diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-10-29 17:38:56 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-10-29 17:38:56 -0400 |
| commit | e6a5ea8fa7d10078c8d3f1bf6cabc4399cac3e70 (patch) | |
| tree | 316f3c5287a1389d214437dadb9c2dca0560410f /test | |
| parent | 5d6376fbd5ca4103a26118a6fffd1e95be0d5161 (diff) | |
| download | sqlalchemy-e6a5ea8fa7d10078c8d3f1bf6cabc4399cac3e70.tar.gz | |
- [bug] Postgresql dialect memoizes that an ENUM of a
particular name was processed
during a create/drop sequence. This allows
a create/drop sequence to work without any
calls to "checkfirst", and also means with
"checkfirst" turned on it only needs to
check for the ENUM once. [ticket:2311]
Diffstat (limited to 'test')
| -rw-r--r-- | test/dialect/test_postgresql.py | 24 | ||||
| -rw-r--r-- | test/lib/engines.py | 8 | ||||
| -rw-r--r-- | test/sql/test_types.py | 14 |
3 files changed, 45 insertions, 1 deletions
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 487139102..b4b7e818c 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -450,6 +450,30 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): finally: metadata.drop_all(testing.db) + @testing.provide_metadata + def test_generate_multiple(self): + """Test that the same enum twice only generates once + for the create_all() call, without using checkfirst. + + A 'memo' collection held by the DDL runner + now handles this. + + """ + metadata = self.metadata + + e1 = Enum('one', 'two', 'three', + name="myenum") + t1 = Table('e1', metadata, + Column('c1', e1) + ) + + t2 = Table('e2', metadata, + Column('c1', e1) + ) + + metadata.create_all(checkfirst=False) + metadata.drop_all(checkfirst=False) + def test_non_native_dialect(self): engine = engines.testing_engine() engine.connect() diff --git a/test/lib/engines.py b/test/lib/engines.py index 649c3e31a..c8a44dc44 100644 --- a/test/lib/engines.py +++ b/test/lib/engines.py @@ -247,12 +247,18 @@ def mock_engine(dialect_name=None): def assert_sql(stmts): recv = [re.sub(r'[\n\t]', '', str(s)) for s in buffer] assert recv == stmts, recv - + def print_sql(): + d = engine.dialect + return "\n".join( + str(s.compile(dialect=d)) + for s in engine.mock + ) engine = create_engine(dialect_name + '://', strategy='mock', executor=executor) assert not hasattr(engine, 'mock') engine.mock = buffer engine.assert_sql = assert_sql + engine.print_sql = print_sql return engine class DBAPIProxyCursor(object): diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 50cb0ba06..987e97f9b 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -956,6 +956,20 @@ class EnumTest(fixtures.TestBase): {'id':4, 'someenum':'four'} ) + def test_mock_engine_no_prob(self): + """ensure no 'checkfirst' queries are run when enums + are created with checkfirst=False""" + + e = engines.mock_engine() + t = Table('t1', MetaData(), + Column('x', Enum("x", "y", name="pge")) + ) + t.create(e, checkfirst=False) + # basically looking for the start of + # the constraint, or the ENUM def itself, + # depending on backend. + assert "('x'," in e.print_sql() + class BinaryTest(fixtures.TestBase, AssertsExecutionResults): __excluded_on__ = ( ('mysql', '<', (4, 1, 1)), # screwy varbinary types |
