]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- these tests are really old but trying to make sure everything is closed out
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 5 Jan 2014 23:25:51 +0000 (18:25 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 5 Jan 2014 23:25:51 +0000 (18:25 -0500)
test/engine/test_execute.py

index 7312bb0412c29f6b95863776485b9005ff4ba371..c2479eff7ab65ee6d6d14709d1cebdff305dfc1e 100644 (file)
@@ -218,21 +218,20 @@ class ExecuteTest(fixtures.TestBase):
         e = create_engine('sqlite://')
         e.dialect.is_disconnect = is_disconnect = Mock()
 
-        c = e.connect()
-
-        c.connection.cursor = Mock(
-                return_value=Mock(
-                    execute=Mock(
-                            side_effect=TypeError("I'm not a DBAPI error")
-                    ))
-                )
+        with e.connect() as c:
+            c.connection.cursor = Mock(
+                    return_value=Mock(
+                        execute=Mock(
+                                side_effect=TypeError("I'm not a DBAPI error")
+                        ))
+                    )
 
-        assert_raises_message(
-            TypeError,
-            "I'm not a DBAPI error",
-            c.execute, "select "
-        )
-        eq_(is_disconnect.call_count, 0)
+            assert_raises_message(
+                TypeError,
+                "I'm not a DBAPI error",
+                c.execute, "select "
+            )
+            eq_(is_disconnect.call_count, 0)
 
 
     def test_exception_wrapping_non_dbapi_statement(self):
@@ -260,21 +259,22 @@ class ExecuteTest(fixtures.TestBase):
 
     def test_stmt_exception_non_ascii(self):
         name = util.u('méil')
-        assert_raises_message(
-            tsa.exc.StatementError,
-            util.u(
-                "A value is required for bind parameter 'uname'"
-                r'.*SELECT users.user_name AS .m\\xe9il.') if util.py2k
-            else
+        with testing.db.connect() as conn:
+            assert_raises_message(
+                tsa.exc.StatementError,
                 util.u(
                     "A value is required for bind parameter 'uname'"
-                    '.*SELECT users.user_name AS .méil.')
-                ,
-            testing.db.execute,
-            select([users.c.user_name.label(name)]).where(
-                            users.c.user_name == bindparam("uname")),
-            {'uname_incorrect': 'foo'}
-        )
+                    r'.*SELECT users.user_name AS .m\\xe9il.') if util.py2k
+                else
+                    util.u(
+                        "A value is required for bind parameter 'uname'"
+                        '.*SELECT users.user_name AS .méil.')
+                    ,
+                conn.execute,
+                select([users.c.user_name.label(name)]).where(
+                                users.c.user_name == bindparam("uname")),
+                {'uname_incorrect': 'foo'}
+            )
 
     def test_stmt_exception_pickleable_no_dbapi(self):
         self._test_stmt_exception_pickleable(Exception("hello world"))
@@ -361,17 +361,17 @@ class ExecuteTest(fixtures.TestBase):
     def test_engine_level_options(self):
         eng = engines.testing_engine(options={'execution_options':
                                             {'foo': 'bar'}})
-        conn = eng.contextual_connect()
-        eq_(conn._execution_options['foo'], 'bar')
-        eq_(conn.execution_options(bat='hoho')._execution_options['foo'
-            ], 'bar')
-        eq_(conn.execution_options(bat='hoho')._execution_options['bat'
-            ], 'hoho')
-        eq_(conn.execution_options(foo='hoho')._execution_options['foo'
-            ], 'hoho')
-        eng.update_execution_options(foo='hoho')
-        conn = eng.contextual_connect()
-        eq_(conn._execution_options['foo'], 'hoho')
+        with eng.contextual_connect() as conn:
+            eq_(conn._execution_options['foo'], 'bar')
+            eq_(conn.execution_options(bat='hoho')._execution_options['foo'
+                ], 'bar')
+            eq_(conn.execution_options(bat='hoho')._execution_options['bat'
+                ], 'hoho')
+            eq_(conn.execution_options(foo='hoho')._execution_options['foo'
+                ], 'hoho')
+            eng.update_execution_options(foo='hoho')
+            conn = eng.contextual_connect()
+            eq_(conn._execution_options['foo'], 'hoho')
 
     @testing.requires.ad_hoc_engines
     def test_generative_engine_execution_options(self):
@@ -418,8 +418,8 @@ class ExecuteTest(fixtures.TestBase):
         event.listen(eng, "before_execute", l2)
         event.listen(eng1, "before_execute", l3)
 
-        eng.execute(select([1]))
-        eng1.execute(select([1]))
+        eng.execute(select([1])).close()
+        eng1.execute(select([1])).close()
 
         eq_(canary, ["l1", "l2", "l3", "l1", "l2"])