diff options
| author | Gord Thompson <gord@gordthompson.com> | 2020-02-13 12:14:42 -0700 |
|---|---|---|
| committer | Gord Thompson <gord@gordthompson.com> | 2020-02-17 10:15:12 -0700 |
| commit | 60f627cbd0d769e65353e720548efac9d8ab95d9 (patch) | |
| tree | 2370558b27263eeeae1f6731d39d80f2483b18e0 /test/dialect | |
| parent | 3c7765b49c0aba253c11f435b2923bb488d15809 (diff) | |
| download | sqlalchemy-60f627cbd0d769e65353e720548efac9d8ab95d9.tar.gz | |
Replace engine.execute w/ context manager (step1)
First (baby) step at replacing engine.execute
calls in test code with the new preferred way
of executing. MSSQL was targeted because it was
the easiest for me to test locally.
Change-Id: Id2e02f0e39007cbfd28ca6a535115f53c6407015
Diffstat (limited to 'test/dialect')
| -rw-r--r-- | test/dialect/mssql/test_query.py | 9 | ||||
| -rw-r--r-- | test/dialect/mssql/test_types.py | 28 |
2 files changed, 23 insertions, 14 deletions
diff --git a/test/dialect/mssql/test_query.py b/test/dialect/mssql/test_query.py index 718b18f5b..aa0850222 100644 --- a/test/dialect/mssql/test_query.py +++ b/test/dialect/mssql/test_query.py @@ -356,7 +356,8 @@ class QueryTest(testing.AssertsExecutionResults, fixtures.TestBase): metadata.create_all(engine) with self.sql_execution_asserter(engine) as asserter: - engine.execute(t1.insert(), {"data": "somedata"}) + with engine.begin() as conn: + conn.execute(t1.insert(), {"data": "somedata"}) # TODO: need a dialect SQL that acts like Cursor SQL asserter.assert_( @@ -381,7 +382,8 @@ class QueryTest(testing.AssertsExecutionResults, fixtures.TestBase): metadata.create_all(engine) with self.sql_execution_asserter(engine) as asserter: - engine.execute(t1.insert()) + with engine.begin() as conn: + conn.execute(t1.insert()) # even with pyodbc, we don't embed the scope identity on a # DEFAULT VALUES insert @@ -409,7 +411,8 @@ class QueryTest(testing.AssertsExecutionResults, fixtures.TestBase): metadata.create_all(engine) with self.sql_execution_asserter(engine) as asserter: - engine.execute(t1.insert(), {"data": "somedata"}) + with engine.begin() as conn: + conn.execute(t1.insert(), {"data": "somedata"}) # pyodbc-specific system asserter.assert_( diff --git a/test/dialect/mssql/test_types.py b/test/dialect/mssql/test_types.py index 92d3d9e32..c95ac6e6d 100644 --- a/test/dialect/mssql/test_types.py +++ b/test/dialect/mssql/test_types.py @@ -1026,18 +1026,24 @@ class TypeRoundTripTest( ] for counter, engine in enumerate(eng): - engine.execute(tbl.insert()) - if "int_y" in tbl.c: - assert engine.scalar(select([tbl.c.int_y])) == counter + 1 - assert ( - list(engine.execute(tbl.select()).first()).count( - counter + 1 + with engine.begin() as conn: + conn.execute(tbl.insert()) + if "int_y" in tbl.c: + eq_( + conn.execute(select([tbl.c.int_y])).scalar(), + counter + 1, ) - == 1 - ) - else: - assert 1 not in list(engine.execute(tbl.select()).first()) - engine.execute(tbl.delete()) + assert ( + list(conn.execute(tbl.select()).first()).count( + counter + 1 + ) + == 1 + ) + else: + assert 1 not in list( + conn.execute(tbl.select()).first() + ) + conn.execute(tbl.delete()) class StringTest(fixtures.TestBase, AssertsCompiledSQL): |
