Skip to content

Commit 98cda5b

Browse files
authored
Add Alembic test suite support (#158)
* Add Alembic test suite support Currently using a pre-release version of Alembic. pip install from GitHub instead of PyPI until Alembic 1.7 is released. * Add one non-default requirement for Alembic
1 parent 0561af9 commit 98cda5b

File tree

6 files changed

+125
-5
lines changed

6 files changed

+125
-5
lines changed

README.testing.SQLAlchemy.md renamed to README.testing.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Testing this dialect with SQLAlchemy
1+
## Testing this dialect with SQLAlchemy and Alembic
22

33
"setup.cfg" contains a default SQLAlchemy connection URI that should
44
work if you have a local instance of CockroachDB installed:
@@ -14,19 +14,32 @@ folder as "setup.cfg", copy the ``[db]`` section into it, and adjust the
1414
The minimum requirements for testing are:
1515

1616
- SQLAlchemy,
17+
- Alembic,
1718
- pytest, and
1819
- the psycopg2 DBAPI module.
1920

2021
Install them with
2122

2223
pip install sqlalchemy pytest psycopg2-binary
2324

25+
# A pre-release version of Alembic is required until version 1.7 is released.
26+
# (Bear this in mind if you rebuild test-requirements.txt via make.)
27+
pip install git+https://github.com/sqlalchemy/alembic
28+
2429
Then, to run a complete test simply invoke
2530

2631
pytest
2732

2833
at a command prompt in your virtual environment.
2934

35+
To run just the SQLAlchemy test suite, use
36+
37+
pytest test/test_suite_sqlalchemy.py
38+
39+
and to run just the Alembic test suite, use
40+
41+
pytest test/test_suite_alembic.py
42+
3043
For more detailed information see the corresponding SQLAlchemy document
3144

32-
https://github.com/sqlalchemy/sqlalchemy/blob/master/README.unittests.rst
45+
https://github.com/sqlalchemy/sqlalchemy/blob/master/README.unittests.rst

sqlalchemy_cockroachdb/requirements.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from sqlalchemy.testing.requirements import SuiteRequirements
1+
from sqlalchemy.testing.requirements import SuiteRequirements as SuiteRequirementsSQLA
2+
from alembic.testing.requirements import SuiteRequirements as SuiteRequirementsAlembic
23

34
from sqlalchemy.testing import exclusions
45

56

6-
class Requirements(SuiteRequirements):
7+
class Requirements(SuiteRequirementsSQLA, SuiteRequirementsAlembic):
78
# This class configures the sqlalchemy test suite. Oddly, it must
89
# be importable in the main codebase and not alongside the tests.
910
#
@@ -156,3 +157,9 @@ class Requirements(SuiteRequirements):
156157

157158
def get_isolation_levels(self, config):
158159
return {"default": "SERIALIZABLE", "supported": ["SERIALIZABLE"]}
160+
161+
# non-default requirements for Alembic test suite
162+
163+
@property
164+
def autoincrement_on_composite_pk(self):
165+
return exclusions.open()

test-requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# generated test-requirements.txt) and run make update-requirements
66

77
SQLAlchemy==1.4.17
8+
# temporary tweak required until Alembic 1.7 is released:
9+
git+https://github.com/sqlalchemy/alembic
810
more-itertools==8.8.0
911
mock==4.0.3
1012
pytest==6.2.4
@@ -22,3 +24,7 @@ pyparsing==2.4.7
2224
toml==0.10.2
2325
typing-extensions==3.10.0.0
2426
zipp==3.4.1
27+
Mako
28+
python-editor>=0.3
29+
python-dateutil
30+
six

test-requirements.txt.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# generated test-requirements.txt) and run make update-requirements
66

77
SQLAlchemy
8+
# a temporary tweak in test-requirements.txt is required until Alembic 1.7 is released:
9+
# git+https://github.com/sqlalchemy/alembic
10+
alembic
811
more-itertools
912
mock
1013
pytest

test/test_suite_alembic.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from alembic.testing.suite import * # noqa
2+
from sqlalchemy.testing import skip
3+
from alembic.testing.suite import AutogenerateFKOptionsTest as _AutogenerateFKOptionsTest
4+
from alembic.testing.suite import AutogenerateForeignKeysTest as _AutogenerateForeignKeysTest
5+
from alembic.testing.suite import BackendAlterColumnTest as _BackendAlterColumnTest
6+
from alembic.testing.suite import IncludeHooksTest as _IncludeHooksTest
7+
8+
9+
class AutogenerateFKOptionsTest(_AutogenerateFKOptionsTest):
10+
def test_change_ondelete_from_restrict(self):
11+
if config.db.dialect._is_v202plus: # noqa
12+
super().test_change_ondelete_from_restrict()
13+
14+
def test_change_onupdate_from_restrict(self):
15+
if config.db.dialect._is_v202plus: # noqa
16+
super().test_change_onupdate_from_restrict()
17+
18+
def test_nochange_ondelete(self):
19+
if config.db.dialect._is_v202plus: # noqa
20+
super().test_nochange_ondelete()
21+
22+
def test_nochange_ondelete_noaction(self):
23+
if config.db.dialect._is_v202plus: # noqa
24+
super().test_nochange_ondelete_noaction()
25+
26+
def test_nochange_ondelete_restrict(self):
27+
if config.db.dialect._is_v202plus: # noqa
28+
super().test_nochange_ondelete_restrict()
29+
30+
def test_nochange_onupdate(self):
31+
if config.db.dialect._is_v202plus: # noqa
32+
super().test_nochange_onupdate()
33+
34+
def test_nochange_onupdate_noaction(self):
35+
if config.db.dialect._is_v202plus: # noqa
36+
super().test_nochange_onupdate_noaction()
37+
38+
def test_nochange_onupdate_restrict(self):
39+
if config.db.dialect._is_v202plus: # noqa
40+
super().test_nochange_onupdate_restrict()
41+
42+
43+
class AutogenerateForeignKeysTest(_AutogenerateForeignKeysTest):
44+
def test_casing_convention_changed_so_put_drops_first(self):
45+
if config.db.dialect._is_v202plus: # noqa
46+
super().test_casing_convention_changed_so_put_drops_first()
47+
48+
def test_no_change(self):
49+
if config.db.dialect._is_v202plus: # noqa
50+
super().test_no_change()
51+
52+
def test_no_change_colkeys(self):
53+
if config.db.dialect._is_v202plus: # noqa
54+
super().test_no_change_colkeys()
55+
56+
def test_no_change_composite_fk(self):
57+
if config.db.dialect._is_v202plus: # noqa
58+
super().test_no_change_composite_fk()
59+
60+
def test_remove_composite_fk(self):
61+
if config.db.dialect._is_v202plus: # noqa
62+
super().test_remove_composite_fk()
63+
64+
def test_remove_fk(self):
65+
if config.db.dialect._is_v202plus: # noqa
66+
super().test_remove_fk()
67+
68+
69+
class BackendAlterColumnTest(_BackendAlterColumnTest):
70+
def test_modify_nullable_to_non(self):
71+
# we seem to need autocommit for this operation
72+
with self.op.get_context().autocommit_block():
73+
super().test_modify_nullable_to_non()
74+
75+
@skip("cockroachdb") # noqa
76+
def test_modify_type_int_str(self):
77+
# TODO: enable this test when warning removed for ALTER COLUMN int → string
78+
pass
79+
80+
81+
class IncludeHooksTest(_IncludeHooksTest):
82+
@combinations(("object",), ("name",)) # noqa
83+
def test_change_fk(self, hook_type):
84+
if config.db.dialect._is_v202plus: # noqa
85+
super().test_change_fk(hook_type)
86+
87+
@combinations(("object",), ("name",)) # noqa
88+
def test_remove_connection_fk(self, hook_type):
89+
if config.db.dialect._is_v202plus: # noqa
90+
super().test_remove_connection_fk(hook_type)

test/test_suite.py renamed to test/test_suite_sqlalchemy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from sqlalchemy import __version__ as sa_version
2+
from sqlalchemy.testing import skip
23
from sqlalchemy.testing.suite import * # noqa
34
from sqlalchemy.testing.suite import ComponentReflectionTest as _ComponentReflectionTest
45
from sqlalchemy.testing.suite import ExpandingBoundInTest as _ExpandingBoundInTest
@@ -11,7 +12,7 @@ def test_get_indexes(self, connection):
1112

1213

1314
class ExpandingBoundInTest(_ExpandingBoundInTest):
14-
@testing.skip("cockroachdb") # noqa
15+
@skip("cockroachdb") # noqa
1516
def test_null_in_empty_set_is_false(self, connection):
1617
# Fixed in https://github.com/cockroachdb/cockroach/pull/49814
1718
# Unskip when backported.

0 commit comments

Comments
 (0)