From: Mike Bayer Date: Fri, 20 Jul 2007 20:27:27 +0000 (+0000) Subject: - merged bind unittest fix from r2999 X-Git-Tag: rel_0_4_6~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7182af8f13faddf05592283b6b8d0814711a6bf;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - merged bind unittest fix from r2999 REV 3000 !!! WOO HOO ! --- diff --git a/test/engine/bind.py b/test/engine/bind.py index 17b243d256..a639a4a90a 100644 --- a/test/engine/bind.py +++ b/test/engine/bind.py @@ -77,27 +77,32 @@ class BindTest(testbase.PersistTest): table.create() table.drop() assert not table.exists() + if isinstance(bind, engine.Connection): + bind.close() def test_create_drop_constructor_bound(self): for bind in ( testbase.db, testbase.db.connect() ): - for args in ( - ([bind], {}), - ([], {'bind':bind}), - ): - metadata = MetaData(*args[0], **args[1]) - table = Table('test_table', metadata, - Column('foo', Integer)) - - assert metadata.bind is table.bind is bind - metadata.create_all() - assert table.exists() - metadata.drop_all() - table.create() - table.drop() - assert not table.exists() + try: + for args in ( + ([bind], {}), + ([], {'bind':bind}), + ): + metadata = MetaData(*args[0], **args[1]) + table = Table('test_table', metadata, + Column('foo', Integer)) + assert metadata.bind is table.bind is bind + metadata.create_all() + assert table.exists() + metadata.drop_all() + table.create() + table.drop() + assert not table.exists() + finally: + if isinstance(bind, engine.Connection): + bind.close() def test_implicit_execution(self): metadata = MetaData() @@ -138,9 +143,13 @@ class BindTest(testbase.PersistTest): testbase.db, testbase.db.connect() ): - e = elem(bind=bind) - assert e.bind is bind - e.execute() + try: + e = elem(bind=bind) + assert e.bind is bind + e.execute() + finally: + if isinstance(bind, engine.Connection): + bind.close() try: e = elem() @@ -169,13 +178,17 @@ class BindTest(testbase.PersistTest): for bind in (testbase.db, testbase.db.connect() ): - for args in ({'bind':bind},): - sess = create_session(**args) - assert sess.bind is bind - f = Foo() - sess.save(f) - sess.flush() - assert sess.get(Foo, f.foo) is f + try: + for args in ({'bind':bind},): + sess = create_session(**args) + assert sess.bind is bind + f = Foo() + sess.save(f) + sess.flush() + assert sess.get(Foo, f.foo) is f + finally: + if isinstance(bind, engine.Connection): + bind.close() if isinstance(bind, engine.Connection): bind.close()