diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-28 11:09:40 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-31 14:44:14 -0400 |
commit | 803a2373f58e794499e1e0b476db4c23e8dd7f87 (patch) | |
tree | 6106a2f031cbc0fbb4429d295aef4c486afbae7a /test/ext/mypy/test_mypy_plugin_py3k.py | |
parent | 2c2e01a0c6d0847f5648fd0120c8fa0bd5f6268f (diff) | |
download | sqlalchemy-803a2373f58e794499e1e0b476db4c23e8dd7f87.tar.gz |
Add DeclarativeMeta to globals
Fixed issue in mypy plugin where newly added support for
:func:`_orm.as_declarative` needed to more fully add the
``DeclarativeMeta`` class to the mypy interpreter's state so that it does
not result in a name not found error; additionally improves how global
names are setup for the plugin including the ``Mapped`` name.
Introduces directory oriented testing as well, where a full
set of files will be copied, mypy runs, then zero or more patches
are applied and mypy is run again, to fully test incremental
behaviors.
Fixes: sqlalchemy/sqlalchemy2-stubs/#14
Change-Id: Ide785c07e19ba0694e8cf6f91560094ecb182016
Diffstat (limited to 'test/ext/mypy/test_mypy_plugin_py3k.py')
-rw-r--r-- | test/ext/mypy/test_mypy_plugin_py3k.py | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/test/ext/mypy/test_mypy_plugin_py3k.py b/test/ext/mypy/test_mypy_plugin_py3k.py index bf82aaa86..c8d042db0 100644 --- a/test/ext/mypy/test_mypy_plugin_py3k.py +++ b/test/ext/mypy/test_mypy_plugin_py3k.py @@ -1,5 +1,6 @@ import os import re +import shutil import tempfile from sqlalchemy import testing @@ -36,8 +37,15 @@ class MypyPluginTest(fixtures.TestBase): def mypy_runner(self, cachedir): from mypy import api - def run(filename, use_plugin=True): - path = os.path.join(os.path.dirname(__file__), "files", filename) + def run( + filename, use_plugin=True, incremental=False, working_dir=None + ): + if working_dir: + path = os.path.join(working_dir, filename) + else: + path = os.path.join( + os.path.dirname(__file__), "files", filename + ) args = [ "--strict", @@ -59,6 +67,55 @@ class MypyPluginTest(fixtures.TestBase): return run + def _incremental_dirs(): + path = os.path.join(os.path.dirname(__file__), "incremental") + return [ + d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d)) + ] + + @testing.combinations( + *[(dirname,) for dirname in _incremental_dirs()], argnames="dirname" + ) + @testing.requires.patch_library + def test_incremental(self, mypy_runner, cachedir, dirname): + import patch + + path = os.path.join(os.path.dirname(__file__), "incremental", dirname) + dest = os.path.join(cachedir, "mymodel") + os.mkdir(dest) + + patches = set() + + print("incremental test: %s" % dirname) + + for fname in os.listdir(path): + if fname.endswith(".py"): + shutil.copy( + os.path.join(path, fname), os.path.join(dest, fname) + ) + print("copying to: %s" % os.path.join(dest, fname)) + elif fname.endswith(".testpatch"): + patches.add(fname) + + for patchfile in [None] + sorted(patches): + if patchfile is not None: + print("Applying patchfile %s" % patchfile) + patch_obj = patch.fromfile(os.path.join(path, patchfile)) + patch_obj.apply(1, dest) + print("running mypy against %s/mymodel" % cachedir) + result = mypy_runner( + "mymodel", + use_plugin=True, + incremental=True, + working_dir=cachedir, + ) + eq_( + result[2], + 0, + msg="Failure after applying patch %s: %s" + % (patchfile, result[0]), + ) + def _file_combinations(): path = os.path.join(os.path.dirname(__file__), "files") return [f for f in os.listdir(path) if f.endswith(".py")] |