summaryrefslogtreecommitdiff
path: root/test/engine/test_execute.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/engine/test_execute.py')
-rw-r--r--test/engine/test_execute.py94
1 files changed, 87 insertions, 7 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py
index d8e1c655e..5c3279ba9 100644
--- a/test/engine/test_execute.py
+++ b/test/engine/test_execute.py
@@ -25,6 +25,10 @@ from sqlalchemy.util import nested
users, metadata, users_autoinc = None, None, None
+class SomeException(Exception):
+ pass
+
+
class ExecuteTest(fixtures.TestBase):
__backend__ = True
@@ -280,12 +284,13 @@ class ExecuteTest(fixtures.TestBase):
impl = Integer
def process_bind_param(self, value, dialect):
- raise Exception("nope")
+ raise SomeException("nope")
def _go(conn):
assert_raises_message(
tsa.exc.StatementError,
- r"nope \(original cause: Exception: nope\) u?'SELECT 1 ",
+ r"\(test.engine.test_execute.SomeException\) "
+ "nope \[SQL\: u?'SELECT 1 ",
conn.execute,
select([1]).
where(
@@ -479,6 +484,26 @@ class ExecuteTest(fixtures.TestBase):
eq_(canary, ["l1", "l2", "l3", "l1", "l2"])
@testing.requires.ad_hoc_engines
+ def test_autocommit_option_no_issue_first_connect(self):
+ eng = create_engine(testing.db.url)
+ eng.update_execution_options(autocommit=True)
+ conn = eng.connect()
+ eq_(conn._execution_options, {"autocommit": True})
+ conn.close()
+
+ @testing.requires.ad_hoc_engines
+ def test_dialect_init_uses_options(self):
+ eng = create_engine(testing.db.url)
+
+ def my_init(connection):
+ connection.execution_options(foo='bar').execute(select([1]))
+
+ with patch.object(eng.dialect, "initialize", my_init):
+ conn = eng.connect()
+ eq_(conn._execution_options, {})
+ conn.close()
+
+ @testing.requires.ad_hoc_engines
def test_generative_engine_event_dispatch_hasevents(self):
def l1(*arg, **kw):
pass
@@ -541,7 +566,7 @@ class ConvenienceExecuteTest(fixtures.TablesTest):
if is_transaction:
conn = conn.connection
conn.execute(self.table.insert().values(a=x, b=value))
- raise Exception("breakage")
+ raise SomeException("breakage")
return go
def _assert_no_data(self):
@@ -982,6 +1007,17 @@ class ExecutionOptionsTest(fixtures.TestBase):
eq_(c1._execution_options, {"foo": "bar"})
eq_(c2._execution_options, {"foo": "bar", "bat": "hoho"})
+ def test_branched_connection_execution_options(self):
+ engine = testing_engine("sqlite://")
+
+ conn = engine.connect()
+ c2 = conn.execution_options(foo="bar")
+ c2_branch = c2.connect()
+ eq_(
+ c2_branch._execution_options,
+ {"foo": "bar"}
+ )
+
class AlternateResultProxyTest(fixtures.TestBase):
__requires__ = ('sqlite', )
@@ -1440,6 +1476,48 @@ class EngineEventsTest(fixtures.TestBase):
'begin', 'execute', 'cursor_execute', 'commit',
])
+ def test_transactional_named(self):
+ canary = []
+
+ def tracker(name):
+ def go(*args, **kw):
+ canary.append((name, set(kw)))
+ return go
+
+ engine = engines.testing_engine()
+ event.listen(engine, 'before_execute', tracker('execute'), named=True)
+ event.listen(
+ engine, 'before_cursor_execute',
+ tracker('cursor_execute'), named=True)
+ event.listen(engine, 'begin', tracker('begin'), named=True)
+ event.listen(engine, 'commit', tracker('commit'), named=True)
+ event.listen(engine, 'rollback', tracker('rollback'), named=True)
+
+ conn = engine.connect()
+ trans = conn.begin()
+ conn.execute(select([1]))
+ trans.rollback()
+ trans = conn.begin()
+ conn.execute(select([1]))
+ trans.commit()
+
+ eq_(
+ canary, [
+ ('begin', set(['conn', ])),
+ ('execute', set([
+ 'conn', 'clauseelement', 'multiparams', 'params'])),
+ ('cursor_execute', set([
+ 'conn', 'cursor', 'executemany',
+ 'statement', 'parameters', 'context'])),
+ ('rollback', set(['conn', ])), ('begin', set(['conn', ])),
+ ('execute', set([
+ 'conn', 'clauseelement', 'multiparams', 'params'])),
+ ('cursor_execute', set([
+ 'conn', 'cursor', 'executemany', 'statement',
+ 'parameters', 'context'])),
+ ('commit', set(['conn', ]))]
+ )
+
@testing.requires.savepoints
@testing.requires.two_phase_transactions
def test_transactional_advanced(self):
@@ -1524,7 +1602,7 @@ class HandleErrorTest(fixtures.TestBase):
listener = Mock(return_value=None)
event.listen(engine, 'dbapi_error', listener)
- nope = Exception("nope")
+ nope = SomeException("nope")
class MyType(TypeDecorator):
impl = Integer
@@ -1535,7 +1613,8 @@ class HandleErrorTest(fixtures.TestBase):
with engine.connect() as conn:
assert_raises_message(
tsa.exc.StatementError,
- r"nope \(original cause: Exception: nope\) u?'SELECT 1 ",
+ r"\(test.engine.test_execute.SomeException\) "
+ "nope \[SQL\: u?'SELECT 1 ",
conn.execute,
select([1]).where(
column('foo') == literal('bar', MyType()))
@@ -1715,7 +1794,7 @@ class HandleErrorTest(fixtures.TestBase):
listener = Mock(return_value=None)
event.listen(engine, 'handle_error', listener)
- nope = Exception("nope")
+ nope = SomeException("nope")
class MyType(TypeDecorator):
impl = Integer
@@ -1726,7 +1805,8 @@ class HandleErrorTest(fixtures.TestBase):
with engine.connect() as conn:
assert_raises_message(
tsa.exc.StatementError,
- r"nope \(original cause: Exception: nope\) u?'SELECT 1 ",
+ r"\(test.engine.test_execute.SomeException\) "
+ "nope \[SQL\: u?'SELECT 1 ",
conn.execute,
select([1]).where(
column('foo') == literal('bar', MyType()))