From: Federico Caselli Date: Thu, 22 Jul 2021 20:32:28 +0000 (+0200) Subject: Add mypy tests on github. X-Git-Tag: rel_1_4_23~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e7d097a633d1b7a95bbd59f9a6d2a5b85249332;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add mypy tests on github. Support skipping mypy tests based on interpreter version Change-Id: I98963318dbb2e7e097ad5518e0e4022349ca9779 --- diff --git a/.github/workflows/run-on-pr.yaml b/.github/workflows/run-on-pr.yaml index ecd3da7a9f..5d23818b32 100644 --- a/.github/workflows/run-on-pr.yaml +++ b/.github/workflows/run-on-pr.yaml @@ -52,6 +52,40 @@ jobs: - name: Run tests run: tox -e github-${{ matrix.build-type }} -- -q --nomemory --notimingintensive ${{ matrix.pytest-args }} + run-mypy: + name: mypy-${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + strategy: + # run this job using this matrix, excluding some combinations below. + matrix: + os: + - "ubuntu-latest" + python-version: + - "3.9" + + fail-fast: false + + # steps to run in each job. Some are github actions, others run shell commands + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Set up python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + architecture: ${{ matrix.architecture }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade tox setuptools + pip list + + - name: Run tests + run: tox -e mypy ${{ matrix.pytest-args }} + + # Arm emulation is quite slow (~20min) so for now just run it when merging to master # run-test-arm64: # name: ${{ matrix.python-version }}-${{ matrix.build-type }}-arm64-ubuntu-latest diff --git a/.github/workflows/run-test.yaml b/.github/workflows/run-test.yaml index 3d641926a9..7f6de8a21c 100644 --- a/.github/workflows/run-test.yaml +++ b/.github/workflows/run-test.yaml @@ -122,3 +122,40 @@ jobs: pip list && tox -e github-${{ matrix.build-type }} -- -q --nomemory --notimingintensive ${{ matrix.pytest-args }} " + + run-mypy: + name: mypy-${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + strategy: + # run this job using this matrix, excluding some combinations below. + matrix: + os: + - "ubuntu-latest" + python-version: + - "3.6" + - "3.7" + - "3.8" + - "3.9" + - "3.10.0-beta - 3.10" + + fail-fast: false + + # steps to run in each job. Some are github actions, others run shell commands + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Set up python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + architecture: ${{ matrix.architecture }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade tox setuptools + pip list + + - name: Run tests + run: tox -e mypy ${{ matrix.pytest-args }} diff --git a/test/ext/mypy/files/dataclasses_workaround.py b/test/ext/mypy/files/dataclasses_workaround.py index f8ee3872bc..56c61b3333 100644 --- a/test/ext/mypy/files/dataclasses_workaround.py +++ b/test/ext/mypy/files/dataclasses_workaround.py @@ -1,3 +1,5 @@ +# PYTHON_VERSION>=3.7 + from __future__ import annotations from dataclasses import dataclass diff --git a/test/ext/mypy/test_mypy_plugin_py3k.py b/test/ext/mypy/test_mypy_plugin_py3k.py index da86167462..681c9d57ba 100644 --- a/test/ext/mypy/test_mypy_plugin_py3k.py +++ b/test/ext/mypy/test_mypy_plugin_py3k.py @@ -1,9 +1,11 @@ import os import re import shutil +import sys import tempfile from sqlalchemy import testing +from sqlalchemy.testing import config from sqlalchemy.testing import eq_ from sqlalchemy.testing import fixtures @@ -152,13 +154,23 @@ class MypyPluginTest(fixtures.TestBase): use_plugin = True expected_errors = [] + expected_re = re.compile(r"\s*# EXPECTED(_MYPY)?: (.+)") + py_ver_re = re.compile(r"^#\s*PYTHON_VERSION\s?>=\s?(\d+\.\d+)") with open(path) as file_: for num, line in enumerate(file_, 1): + m = py_ver_re.match(line) + if m: + major, _, minor = m.group(1).partition(".") + if sys.version_info < (int(major), int(minor)): + config.skip_test( + "Requires python >= %s" % (m.group(1)) + ) + continue if line.startswith("# NOPLUGINS"): use_plugin = False continue - m = re.match(r"\s*# EXPECTED(_MYPY)?: (.+)", line) + m = expected_re.match(line) if m: is_mypy = bool(m.group(1)) expected_msg = m.group(2)