(self, explode_on_exec, initialize)
| 918 | # a generic "recovery". maybe this test suite should have been |
| 919 | # named "test_error_recovery". |
| 920 | def _fixture(self, explode_on_exec, initialize): |
| 921 | class DBAPIError(Exception): |
| 922 | pass |
| 923 | |
| 924 | def MockDBAPI(): |
| 925 | def cursor(): |
| 926 | while True: |
| 927 | if explode_on_exec: |
| 928 | yield Mock( |
| 929 | description=[], |
| 930 | close=Mock(side_effect=DBAPIError("explode")), |
| 931 | execute=Mock(side_effect=DBAPIError("explode")), |
| 932 | ) |
| 933 | else: |
| 934 | yield Mock( |
| 935 | description=[], |
| 936 | close=Mock(side_effect=Exception("explode")), |
| 937 | ) |
| 938 | |
| 939 | def connect(): |
| 940 | while True: |
| 941 | yield Mock( |
| 942 | spec=["cursor", "commit", "rollback", "close"], |
| 943 | cursor=Mock(side_effect=cursor()), |
| 944 | ) |
| 945 | |
| 946 | return Mock( |
| 947 | Error=DBAPIError, |
| 948 | paramstyle="qmark", |
| 949 | connect=Mock(side_effect=connect()), |
| 950 | ) |
| 951 | |
| 952 | dbapi = MockDBAPI() |
| 953 | |
| 954 | from sqlalchemy.engine import default |
| 955 | |
| 956 | url = Mock( |
| 957 | get_dialect=lambda: default.DefaultDialect, |
| 958 | _get_entrypoint=lambda: default.DefaultDialect, |
| 959 | _instantiate_plugins=lambda kwargs: (url, [], kwargs), |
| 960 | translate_connect_args=lambda: {}, |
| 961 | query={}, |
| 962 | ) |
| 963 | eng = testing_engine( |
| 964 | url, options=dict(module=dbapi, _initialize=initialize) |
| 965 | ) |
| 966 | eng.pool.logger = Mock() |
| 967 | |
| 968 | def get_default_schema_name(connection): |
| 969 | try: |
| 970 | cursor = connection.connection.cursor() |
| 971 | connection._cursor_execute(cursor, "statement", {}) |
| 972 | cursor.close() |
| 973 | except exc.DBAPIError: |
| 974 | util.warn("Exception attempting to detect") |
| 975 | |
| 976 | eng.dialect._get_default_schema_name = get_default_schema_name |
| 977 | return eng |
no test coverage detected