diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/engine/test_execute.py | 140 | ||||
-rw-r--r-- | test/engine/test_pool.py | 7 | ||||
-rw-r--r-- | test/engine/test_transaction.py | 22 | ||||
-rw-r--r-- | test/profiles.txt | 78 |
4 files changed, 164 insertions, 83 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 9795e4c10..1d2aebf97 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -1014,6 +1014,53 @@ class ResultProxyTest(fixtures.TestBase): finally: r.close() +class ExecutionOptionsTest(fixtures.TestBase): + def test_dialect_conn_options(self): + engine = testing_engine("sqlite://") + engine.dialect = Mock() + conn = engine.connect() + c2 = conn.execution_options(foo="bar") + eq_( + engine.dialect.set_connection_execution_options.mock_calls, + [call(c2, {"foo": "bar"})] + ) + + def test_dialect_engine_options(self): + engine = testing_engine("sqlite://") + engine.dialect = Mock() + e2 = engine.execution_options(foo="bar") + eq_( + engine.dialect.set_engine_execution_options.mock_calls, + [call(e2, {"foo": "bar"})] + ) + + def test_dialect_engine_construction_options(self): + dialect = Mock() + engine = Engine(Mock(), dialect, Mock(), + execution_options={"foo": "bar"}) + eq_( + dialect.set_engine_execution_options.mock_calls, + [call(engine, {"foo": "bar"})] + ) + + def test_propagate_engine_to_connection(self): + engine = testing_engine("sqlite://", + options=dict(execution_options={"foo": "bar"})) + conn = engine.connect() + eq_(conn._execution_options, {"foo": "bar"}) + + def test_propagate_option_engine_to_connection(self): + e1 = testing_engine("sqlite://", + options=dict(execution_options={"foo": "bar"})) + e2 = e1.execution_options(bat="hoho") + c1 = e1.connect() + c2 = e2.connect() + eq_(c1._execution_options, {"foo": "bar"}) + eq_(c2._execution_options, {"foo": "bar", "bat": "hoho"}) + + + + class AlternateResultProxyTest(fixtures.TestBase): __requires__ = ('sqlite', ) @@ -1101,63 +1148,58 @@ class EngineEventsTest(fixtures.TestBase): e1 = testing_engine(config.db_url) e2 = testing_engine(config.db_url) - canary = [] - def before_exec(conn, stmt, *arg): - canary.append(stmt) - event.listen(e1, "before_execute", before_exec) + canary = Mock() + event.listen(e1, "before_execute", canary) s1 = select([1]) s2 = select([2]) e1.execute(s1) e2.execute(s2) - eq_(canary, [s1]) - event.listen(e2, "before_execute", before_exec) + eq_( + [arg[1][1] for arg in canary.mock_calls], [s1] + ) + event.listen(e2, "before_execute", canary) e1.execute(s1) e2.execute(s2) - eq_(canary, [s1, s1, s2]) + eq_([arg[1][1] for arg in canary.mock_calls], [s1, s1, s2]) def test_per_engine_plus_global(self): - canary = [] - def be1(conn, stmt, *arg): - canary.append('be1') - def be2(conn, stmt, *arg): - canary.append('be2') - def be3(conn, stmt, *arg): - canary.append('be3') - - event.listen(Engine, "before_execute", be1) + canary = Mock() + event.listen(Engine, "before_execute", canary.be1) e1 = testing_engine(config.db_url) e2 = testing_engine(config.db_url) - event.listen(e1, "before_execute", be2) + event.listen(e1, "before_execute", canary.be2) - event.listen(Engine, "before_execute", be3) + event.listen(Engine, "before_execute", canary.be3) e1.connect() e2.connect() - canary[:] = [] + e1.execute(select([1])) + canary.be1.assert_call_count(1) + canary.be2.assert_call_count(1) + e2.execute(select([1])) - eq_(canary, ['be1', 'be3', 'be2', 'be1', 'be3']) + canary.be1.assert_call_count(2) + canary.be2.assert_call_count(1) + canary.be3.assert_call_count(2) def test_per_connection_plus_engine(self): - canary = [] - def be1(conn, stmt, *arg): - canary.append('be1') - def be2(conn, stmt, *arg): - canary.append('be2') + canary = Mock() e1 = testing_engine(config.db_url) - event.listen(e1, "before_execute", be1) + event.listen(e1, "before_execute", canary.be1) conn = e1.connect() - event.listen(conn, "before_execute", be2) - canary[:] = [] + event.listen(conn, "before_execute", canary.be2) conn.execute(select([1])) - eq_(canary, ['be2', 'be1']) + canary.be1.assert_call_count(1) + canary.be2.assert_call_count(1) conn._branch().execute(select([1])) - eq_(canary, ['be2', 'be1', 'be2', 'be1']) + canary.be1.assert_call_count(2) + canary.be2.assert_call_count(2) def test_argument_format_execute(self): def before_execute(conn, clauseelement, multiparams, params): @@ -1320,6 +1362,44 @@ class EngineEventsTest(fixtures.TestBase): canary, ['execute', 'cursor_execute'] ) + def test_engine_connect(self): + engine = engines.testing_engine() + + tracker = Mock() + event.listen(engine, "engine_connect", tracker) + + c1 = engine.connect() + c2 = c1._branch() + c1.close() + eq_( + tracker.mock_calls, + [call(c1, False), call(c2, True)] + ) + + def test_execution_options(self): + engine = engines.testing_engine() + + engine_tracker = Mock() + conn_tracker = Mock() + + event.listen(engine, "set_engine_execution_options", engine_tracker) + event.listen(engine, "set_connection_execution_options", conn_tracker) + + e2 = engine.execution_options(e1='opt_e1') + c1 = engine.connect() + c2 = c1.execution_options(c1='opt_c1') + c3 = e2.connect() + c4 = c3.execution_options(c3='opt_c3') + eq_( + engine_tracker.mock_calls, + [call(e2, {'e1': 'opt_e1'})] + ) + eq_( + conn_tracker.mock_calls, + [call(c2, {"c1": "opt_c1"}), call(c4, {"c3": "opt_c3"})] + ) + + @testing.requires.sequences @testing.provide_metadata def test_cursor_execute(self): diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index 5b64a9f31..8c4bcd8b5 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -879,9 +879,10 @@ class QueuePoolTest(PoolTestBase): pool_size=2, timeout=timeout, max_overflow=max_overflow) def waiter(p): + success_key = (timeout, max_overflow) conn = p.connect() time.sleep(.5) - success.append(True) + success.append(success_key) conn.close() time.sleep(.2) @@ -896,8 +897,8 @@ class QueuePoolTest(PoolTestBase): c1.invalidate() c2.invalidate() p2 = p._replace() - time.sleep(2) - eq_(len(success), 12) + time.sleep(1) + eq_(len(success), 12, "successes: %s" % success) @testing.requires.threading_with_mock @testing.requires.python26 diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index 789c15444..ffc12b5b9 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -1279,15 +1279,15 @@ class IsolationLevelTest(fixtures.TestBase): ) - def test_per_engine_bzzt(self): - assert_raises_message( - exc.ArgumentError, - r"'isolation_level' execution option may " - r"only be specified on Connection.execution_options\(\). " - r"To set engine-wide isolation level, " - r"use the isolation_level argument to create_engine\(\).", - create_engine, - testing.db.url, - execution_options={'isolation_level': - self._non_default_isolation_level} + def test_per_engine(self): + # new in 0.9 + eng = create_engine(testing.db.url, + execution_options={ + 'isolation_level': + self._non_default_isolation_level()} + ) + conn = eng.connect() + eq_( + eng.dialect.get_isolation_level(conn.connection), + self._non_default_isolation_level() ) diff --git a/test/profiles.txt b/test/profiles.txt index 4d8964639..915cfadb4 100644 --- a/test/profiles.txt +++ b/test/profiles.txt @@ -168,19 +168,19 @@ test.aaa_profiling.test_orm.MergeTest.test_merge_no_load 3.3_sqlite_pysqlite_noc # TEST: test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.6_sqlite_pysqlite_nocextensions 82 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_mysql_mysqldb_cextensions 82 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_mysql_mysqldb_nocextensions 82 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_oracle_cx_oracle_nocextensions 82 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_postgresql_psycopg2_cextensions 82 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_postgresql_psycopg2_nocextensions 82 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_sqlite_pysqlite_cextensions 82 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_sqlite_pysqlite_nocextensions 82 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.2_postgresql_psycopg2_nocextensions 70 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.2_sqlite_pysqlite_nocextensions 70 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.3_oracle_cx_oracle_nocextensions 69 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.3_postgresql_psycopg2_nocextensions 69 -test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.3_sqlite_pysqlite_nocextensions 69 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.6_sqlite_pysqlite_nocextensions 87 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_mysql_mysqldb_cextensions 87 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_mysql_mysqldb_nocextensions 87 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_oracle_cx_oracle_nocextensions 87 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_postgresql_psycopg2_cextensions 87 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_postgresql_psycopg2_nocextensions 87 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_sqlite_pysqlite_cextensions 87 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 2.7_sqlite_pysqlite_nocextensions 87 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.2_postgresql_psycopg2_nocextensions 75 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.2_sqlite_pysqlite_nocextensions 75 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.3_oracle_cx_oracle_nocextensions 74 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.3_postgresql_psycopg2_nocextensions 74 +test.aaa_profiling.test_pool.QueuePoolTest.test_first_connect 3.3_sqlite_pysqlite_nocextensions 74 # TEST: test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect @@ -200,19 +200,19 @@ test.aaa_profiling.test_pool.QueuePoolTest.test_second_connect 3.3_sqlite_pysqli # TEST: test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.6_sqlite_pysqlite_nocextensions 6 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_mysql_mysqldb_cextensions 6 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_mysql_mysqldb_nocextensions 6 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_oracle_cx_oracle_nocextensions 6 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_postgresql_psycopg2_cextensions 6 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_postgresql_psycopg2_nocextensions 6 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_sqlite_pysqlite_cextensions 6 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_sqlite_pysqlite_nocextensions 6 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.2_postgresql_psycopg2_nocextensions 7 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.2_sqlite_pysqlite_nocextensions 7 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.3_oracle_cx_oracle_nocextensions 7 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.3_postgresql_psycopg2_nocextensions 7 -test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.3_sqlite_pysqlite_nocextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.6_sqlite_pysqlite_nocextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_mysql_mysqldb_cextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_mysql_mysqldb_nocextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_oracle_cx_oracle_nocextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_postgresql_psycopg2_cextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_postgresql_psycopg2_nocextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_sqlite_pysqlite_cextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 2.7_sqlite_pysqlite_nocextensions 7 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.2_postgresql_psycopg2_nocextensions 8 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.2_sqlite_pysqlite_nocextensions 8 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.3_oracle_cx_oracle_nocextensions 8 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.3_postgresql_psycopg2_nocextensions 8 +test.aaa_profiling.test_pool.QueuePoolTest.test_second_samethread_connect 3.3_sqlite_pysqlite_nocextensions 8 # TEST: test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute @@ -232,19 +232,19 @@ test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_connection_execute # TEST: test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.6_sqlite_pysqlite_nocextensions 68 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_mysql_mysqldb_cextensions 66 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_mysql_mysqldb_nocextensions 68 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_oracle_cx_oracle_nocextensions 68 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_postgresql_psycopg2_cextensions 66 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_postgresql_psycopg2_nocextensions 68 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_sqlite_pysqlite_cextensions 66 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_sqlite_pysqlite_nocextensions 68 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.2_postgresql_psycopg2_nocextensions 66 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.2_sqlite_pysqlite_nocextensions 66 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.3_oracle_cx_oracle_nocextensions 66 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.3_postgresql_psycopg2_nocextensions 66 -test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.3_sqlite_pysqlite_nocextensions 66 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.6_sqlite_pysqlite_nocextensions 73 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_mysql_mysqldb_cextensions 71 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_mysql_mysqldb_nocextensions 73 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_oracle_cx_oracle_nocextensions 73 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_postgresql_psycopg2_cextensions 71 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_postgresql_psycopg2_nocextensions 73 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_sqlite_pysqlite_cextensions 71 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 2.7_sqlite_pysqlite_nocextensions 73 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.2_postgresql_psycopg2_nocextensions 71 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.2_sqlite_pysqlite_nocextensions 71 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.3_oracle_cx_oracle_nocextensions 71 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.3_postgresql_psycopg2_nocextensions 71 +test.aaa_profiling.test_resultset.ExecutionTest.test_minimal_engine_execute 3.3_sqlite_pysqlite_nocextensions 71 # TEST: test.aaa_profiling.test_resultset.ResultSetTest.test_contains_doesnt_compile |