diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2020-06-20 18:48:34 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2020-06-20 18:48:34 +0000 |
| commit | 56e817bb0ef4eaca189b42b930a6e99ee4ed0671 (patch) | |
| tree | a3ae21889965bc62d756d97cd8738c74e65894dc /test | |
| parent | b66e47b353459fe118575785708b681d893ce4a5 (diff) | |
| parent | 5d7d96b53ef6b046fcd4d19a42e31f99898d1c81 (diff) | |
| download | sqlalchemy-56e817bb0ef4eaca189b42b930a6e99ee4ed0671.tar.gz | |
Merge "Apply dialect_options copy fix"
Diffstat (limited to 'test')
| -rw-r--r-- | test/sql/test_metadata.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 2145e72d0..4351e562e 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -5213,3 +5213,82 @@ class NamingConventionTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( CreateIndex(ix), "CREATE INDEX ix_t_q ON t (q + 5)" ) + + +class CopyDialectOptionsTest(fixtures.TestBase): + @contextmanager + def _fixture(self): + from sqlalchemy.engine.default import DefaultDialect + + class CopyDialectOptionsTestDialect(DefaultDialect): + construct_arguments = [ + (Table, {"some_table_arg": None}), + (Column, {"some_column_arg": None}), + (Index, {"some_index_arg": None}), + (PrimaryKeyConstraint, {"some_pk_arg": None}), + (UniqueConstraint, {"some_uq_arg": None}), + ] + + def load(dialect_name): + if dialect_name == "copydialectoptionstest": + return CopyDialectOptionsTestDialect + else: + raise exc.NoSuchModuleError("no dialect %r" % dialect_name) + + with mock.patch("sqlalchemy.dialects.registry.load", load): + yield + + @classmethod + def check_dialect_options_(cls, t): + eq_( + t.dialect_kwargs["copydialectoptionstest_some_table_arg"], "a1", + ) + eq_( + t.c.foo.dialect_kwargs["copydialectoptionstest_some_column_arg"], + "a2", + ) + eq_( + t.primary_key.dialect_kwargs["copydialectoptionstest_some_pk_arg"], + "a3", + ) + eq_( + list(t.indexes)[0].dialect_kwargs[ + "copydialectoptionstest_some_index_arg" + ], + "a4", + ) + eq_( + list(c for c in t.constraints if isinstance(c, UniqueConstraint))[ + 0 + ].dialect_kwargs["copydialectoptionstest_some_uq_arg"], + "a5", + ) + + def test_dialect_options_are_copied(self): + with self._fixture(): + t1 = Table( + "t", + MetaData(), + Column( + "foo", + Integer, + copydialectoptionstest_some_column_arg="a2", + ), + Column("bar", Integer), + PrimaryKeyConstraint( + "foo", copydialectoptionstest_some_pk_arg="a3" + ), + UniqueConstraint( + "bar", copydialectoptionstest_some_uq_arg="a5" + ), + copydialectoptionstest_some_table_arg="a1", + ) + Index( + "idx", t1.c.foo, copydialectoptionstest_some_index_arg="a4", + ) + + self.check_dialect_options_(t1) + + m2 = MetaData() + t2 = t1.tometadata(m2) # make a copy + self.check_dialect_options_(t2) |
