MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / mock_cursor

Function mock_cursor

test/engine/test_reconnect.py:55–95  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53
54def mock_connection():
55 def mock_cursor():
56 def execute(*args, **kwargs):
57 if conn.explode == "execute":
58 raise MockDisconnect("Lost the DB connection on execute")
59 elif conn.explode == "interrupt":
60 conn.explode = "explode_no_disconnect"
61 raise MockExitIsh("Keyboard / greenlet / etc interruption")
62 elif conn.explode == "interrupt_dont_break":
63 conn.explode = None
64 raise MockExitIsh("Keyboard / greenlet / etc interruption")
65 elif conn.explode in (
66 "execute_no_disconnect",
67 "explode_no_disconnect",
68 ):
69 raise MockError(
70 "something broke on execute but we didn't lose the "
71 "connection"
72 )
73 elif conn.explode in (
74 "rollback",
75 "rollback_no_disconnect",
76 "explode_no_disconnect",
77 ):
78 raise MockError(
79 "something broke on execute but we didn't lose the "
80 "connection"
81 )
82 elif args and "SELECT" in args[0]:
83 cursor.description = [("foo", None, None, None, None, None)]
84 else:
85 return
86
87 def close():
88 cursor.fetchall = cursor.fetchone = Mock(
89 side_effect=MockError("cursor closed")
90 )
91
92 cursor = Mock(
93 execute=Mock(side_effect=execute), close=Mock(side_effect=close)
94 )
95 return cursor
96
97 def cursor():
98 while True:

Callers 1

cursorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected