diff options
author | CaselIT <cfederico87@gmail.com> | 2021-04-18 15:44:50 +0200 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-08-11 15:04:56 -0400 |
commit | 6aad68605f510e8b51f42efa812e02b3831d6e33 (patch) | |
tree | cc0e98b8ad8245add8692d8e4910faf57abf7ae3 /tests | |
parent | 3bf6a326c0a11e4f05c94008709d6b0b8e9e051a (diff) | |
download | alembic-6aad68605f510e8b51f42efa812e02b3831d6e33.tar.gz |
Add pep-484 type annotations
pep-484 type annotations have been added throughout the library. This
should be helpful in providing Mypy and IDE support, however there is not
full support for Alembic's dynamically modified "op" namespace as of yet; a
future release will likely modify the approach used for importing this
namespace to be better compatible with pep-484 capabilities.
Type originally created using MonkeyType
Add types extracted with the MonkeyType https://github.com/instagram/MonkeyType
library by running the unit tests using ``monkeytype run -m pytest tests``, then
``monkeytype apply <module>`` (see below for further details).
USed MonkeyType version 20.5 on Python 3.8, since newer version have issues
After applying the types, the new imports are placed in a ``TYPE_CHECKING`` guard
and all type definition of non base types are deferred by using the string notation.
NOTE: since to apply the types MonkeType need to import the module, also the test
ones, the patch below mocks the setup done by pytest so that the tests could be
correctly imported
diff --git a/alembic/testing/__init__.py b/alembic/testing/__init__.py
index bdd1746..b1090c7 100644
Change-Id: Iff93628f4b43c740848871ce077a118db5e75d41
--- a/alembic/testing/__init__.py
+++ b/alembic/testing/__init__.py
@@ -9,6 +9,12 @@ from sqlalchemy.testing.config import combinations
from sqlalchemy.testing.config import fixture
from sqlalchemy.testing.config import requirements as requires
+from sqlalchemy.testing.plugin.pytestplugin import PytestFixtureFunctions
+from sqlalchemy.testing.plugin.plugin_base import _setup_requirements
+
+config._fixture_functions = PytestFixtureFunctions()
+_setup_requirements("tests.requirements:DefaultRequirements")
+
from alembic import util
from .assertions import assert_raises
from .assertions import assert_raises_message
Currently I'm using this branch of the sqlalchemy stubs:
https://github.com/sqlalchemy/sqlalchemy2-stubs/tree/alembic_updates
Change-Id: I8fd0700aab1913f395302626b8b84fea60334abd
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_revision.py | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/tests/test_revision.py b/tests/test_revision.py index c2c1410..61998bf 100644 --- a/tests/test_revision.py +++ b/tests/test_revision.py @@ -9,14 +9,13 @@ from alembic.script.revision import Revision from alembic.script.revision import RevisionError from alembic.script.revision import RevisionMap from alembic.testing import assert_raises_message -from alembic.testing import config from alembic.testing import eq_ +from alembic.testing import expect_raises_message from alembic.testing.fixtures import TestBase from . import _large_map class APITest(TestBase): - @config.requirements.python3 def test_invalid_datatype(self): map_ = RevisionMap( lambda: [ @@ -25,29 +24,26 @@ class APITest(TestBase): Revision("c", ("b",)), ] ) - assert_raises_message( + with expect_raises_message( RevisionError, "revision identifier b'12345' is not a string; " "ensure database driver settings are correct", - map_.get_revisions, - b"12345", - ) + ): + map_.get_revisions(b"12345") - assert_raises_message( + with expect_raises_message( RevisionError, "revision identifier b'12345' is not a string; " "ensure database driver settings are correct", - map_.get_revision, - b"12345", - ) + ): + map_.get_revision(b"12345") - assert_raises_message( + with expect_raises_message( RevisionError, r"revision identifier \(b'12345',\) is not a string; " "ensure database driver settings are correct", - map_.get_revision, - (b"12345",), - ) + ): + map_.get_revision((b"12345",)) map_.get_revision(("a",)) map_.get_revision("a") @@ -310,12 +306,12 @@ class LabeledBranchTest(DownIterateTest): c1 = map_.get_revision("c1") c2 = map_.get_revision("c2") d = map_.get_revision("d") - eq_(map_.filter_for_lineage([c1, c2, d], "c1branch@head"), [c1, c2, d]) + eq_(map_.filter_for_lineage([c1, c2, d], "c1branch@head"), (c1, c2, d)) def test_filter_for_lineage_heads(self): eq_( self.map.filter_for_lineage([self.map.get_revision("f")], "heads"), - [self.map.get_revision("f")], + (self.map.get_revision("f"),), ) def setUp(self): @@ -333,13 +329,13 @@ class LabeledBranchTest(DownIterateTest): ) def test_get_base_revisions_labeled(self): - eq_(self.map._get_base_revisions("somelongername@base"), ["a"]) + eq_(self.map._get_base_revisions("somelongername@base"), ("a",)) def test_get_current_named_rev(self): eq_(self.map.get_revision("ebranch@head"), self.map.get_revision("f")) def test_get_base_revisions(self): - eq_(self.map._get_base_revisions("base"), ["a", "d"]) + eq_(self.map._get_base_revisions("base"), ("a", "d")) def test_iterate_head_to_named_base(self): self._assert_iteration( |