diff options
| author | Gord Thompson <gord@gordthompson.com> | 2020-08-12 14:46:59 -0600 |
|---|---|---|
| committer | Gord Thompson <gord@gordthompson.com> | 2020-09-01 08:05:51 -0600 |
| commit | 516131c40da9c8cd304061850e2d98e309966dd5 (patch) | |
| tree | 148c91095e3021de6881fc0d328980538d3fcea0 /lib/sqlalchemy/testing | |
| parent | 301c3f3579ace1ef1c28067904b57dd789620eae (diff) | |
| download | sqlalchemy-516131c40da9c8cd304061850e2d98e309966dd5.tar.gz | |
Improve reflection for mssql temporary tables
Fixes: #5506
Change-Id: I718474d76e3c630a1b71e07eaa20cefb104d11de
Diffstat (limited to 'lib/sqlalchemy/testing')
| -rw-r--r-- | lib/sqlalchemy/testing/provision.py | 15 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_reflection.py | 14 |
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py index 0edaae490..8bdad357c 100644 --- a/lib/sqlalchemy/testing/provision.py +++ b/lib/sqlalchemy/testing/provision.py @@ -296,3 +296,18 @@ def temp_table_keyword_args(cfg, eng): raise NotImplementedError( "no temp table keyword args routine for cfg: %s" % eng.url ) + + +@register.init +def get_temp_table_name(cfg, eng, base_name): + """Specify table name for creating a temporary Table. + + Dialect-specific implementations of this method will return the + name to use when creating a temporary table for testing, + e.g., in the define_temp_tables method of the + ComponentReflectionTest class in suite/test_reflection.py + + Default to just the base name since that's what most dialects will + use. The mssql dialect's implementation will need a "#" prepended. + """ + return base_name diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 151be757a..94ec22c1e 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -8,6 +8,7 @@ from .. import eq_ from .. import expect_warnings from .. import fixtures from .. import is_ +from ..provision import get_temp_table_name from ..provision import temp_table_keyword_args from ..schema import Column from ..schema import Table @@ -442,8 +443,9 @@ class ComponentReflectionTest(fixtures.TablesTest): @classmethod def define_temp_tables(cls, metadata): kw = temp_table_keyword_args(config, config.db) + table_name = get_temp_table_name(config, config.db, "user_tmp") user_tmp = Table( - "user_tmp", + table_name, metadata, Column("id", sa.INT, primary_key=True), Column("name", sa.VARCHAR(50)), @@ -736,10 +738,11 @@ class ComponentReflectionTest(fixtures.TablesTest): @testing.requires.temp_table_reflection def test_get_temp_table_columns(self): + table_name = get_temp_table_name(config, config.db, "user_tmp") meta = MetaData(self.bind) - user_tmp = self.tables.user_tmp + user_tmp = self.tables[table_name] insp = inspect(meta.bind) - cols = insp.get_columns("user_tmp") + cols = insp.get_columns(table_name) self.assert_(len(cols) > 0, len(cols)) for i, col in enumerate(user_tmp.columns): @@ -1051,10 +1054,11 @@ class ComponentReflectionTest(fixtures.TablesTest): refl.pop("duplicates_index", None) eq_(reflected, [{"column_names": ["name"], "name": "user_tmp_uq"}]) - @testing.requires.temp_table_reflection + @testing.requires.temp_table_reflect_indexes def test_get_temp_table_indexes(self): insp = inspect(self.bind) - indexes = insp.get_indexes("user_tmp") + table_name = get_temp_table_name(config, config.db, "user_tmp") + indexes = insp.get_indexes(table_name) for ind in indexes: ind.pop("dialect_options", None) eq_( |
