]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- merged bind unittest fix from r2999
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Jul 2007 20:27:27 +0000 (20:27 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Jul 2007 20:27:27 +0000 (20:27 +0000)
REV 3000 !!!  WOO HOO !

test/engine/bind.py

index 17b243d256d99e340e164f92cf1124a4bf1731db..a639a4a90ae4f343d349be47d6e7767a5f853a3b 100644 (file)
@@ -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()