diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-12-05 16:34:43 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-12-05 16:34:43 -0500 |
commit | 0639c199a547343d62134d2f233225fd2862ec45 (patch) | |
tree | 8280164279baa094c60beeb1b833483bba1b8bbd /test/engine/test_parseconnect.py | |
parent | 0ce045bd853ec078943c14fc93b87897d2169882 (diff) | |
download | sqlalchemy-0639c199a547343d62134d2f233225fd2862ec45.tar.gz |
- move inner calls to _revalidate_connection() outside of existing
_handle_dbapi_error(); these are now handled already and the reentrant
call is not needed / breaks things. Adjustment to 41e7253dee168b8c26c49 /
Diffstat (limited to 'test/engine/test_parseconnect.py')
-rw-r--r-- | test/engine/test_parseconnect.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index 72a089aca..b6d08ceba 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -7,6 +7,7 @@ from sqlalchemy.testing import fixtures from sqlalchemy import testing from sqlalchemy.testing.mock import Mock, MagicMock from sqlalchemy import event +from sqlalchemy import select dialect = None @@ -279,7 +280,7 @@ class CreateEngineTest(fixtures.TestBase): ) @testing.requires.sqlite - def test_handle_error_event_reconnect(self): + def test_handle_error_event_revalidate(self): e = create_engine('sqlite://') dbapi = MockDBAPI() sqlite3 = e.dialect.dbapi @@ -295,6 +296,7 @@ class CreateEngineTest(fixtures.TestBase): def handle_error(ctx): assert ctx.engine is eng assert ctx.connection is conn + assert isinstance(ctx.sqlalchemy_exception, exc.ProgrammingError) raise MySpecialException("failed operation") conn = eng.connect() @@ -309,6 +311,37 @@ class CreateEngineTest(fixtures.TestBase): ) @testing.requires.sqlite + def test_handle_error_event_implicit_revalidate(self): + e = create_engine('sqlite://') + dbapi = MockDBAPI() + sqlite3 = e.dialect.dbapi + dbapi.Error = sqlite3.Error, + dbapi.ProgrammingError = sqlite3.ProgrammingError + + class MySpecialException(Exception): + pass + + eng = create_engine('sqlite://', module=dbapi, _initialize=False) + + @event.listens_for(eng, "handle_error") + def handle_error(ctx): + assert ctx.engine is eng + assert ctx.connection is conn + assert isinstance(ctx.sqlalchemy_exception, exc.ProgrammingError) + raise MySpecialException("failed operation") + + conn = eng.connect() + conn.invalidate() + + dbapi.connect = Mock( + side_effect=sqlite3.ProgrammingError("random error")) + + assert_raises( + MySpecialException, + conn.execute, select([1]) + ) + + @testing.requires.sqlite def test_handle_error_custom_connect(self): e = create_engine('sqlite://') |