]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add mypy tests on github.
authorFederico Caselli <cfederico87@gmail.com>
Thu, 22 Jul 2021 20:32:28 +0000 (22:32 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Thu, 22 Jul 2021 21:09:18 +0000 (23:09 +0200)
Support skipping mypy tests based on interpreter version

Change-Id: I98963318dbb2e7e097ad5518e0e4022349ca9779

.github/workflows/run-on-pr.yaml
.github/workflows/run-test.yaml
test/ext/mypy/files/dataclasses_workaround.py
test/ext/mypy/test_mypy_plugin_py3k.py

index ecd3da7a9f3651532e2a2a9c3cc90bcea511901a..5d23818b32259116cb034702a94c95a6dd6acd71 100644 (file)
@@ -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
index 3d641926a9f6dda875a6eb6e7466dfa4f7618cbd..7f6de8a21c3b2225933f6944f409bbbffe0eb9eb 100644 (file)
@@ -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 }}
index f8ee3872bcfdec854c53b2259215eca3b4c238c5..56c61b33338169b85d903fcef01666778e971596 100644 (file)
@@ -1,3 +1,5 @@
+# PYTHON_VERSION>=3.7
+
 from __future__ import annotations
 
 from dataclasses import dataclass
index da86167462e816c11e70925db0e0c9cff36bb2c1..681c9d57bab6f997ef4e0f44af5c9a238525e0e7 100644 (file)
@@ -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)