MCPcopy Create free account
hub / github.com/tox-dev/filelock / connect

Function connect

tests/sqlite/async_helpers.py:68–103  ·  view source on GitHub ↗
(
        database: str,
        *,
        factory: type[sqlite3.Connection],
        timeout: float,
    )

Source from the content-addressed store, hash-verified

66 connection_count = 0
67
68 def connect(
69 database: str,
70 *,
71 factory: type[sqlite3.Connection],
72 timeout: float,
73 ) -> sqlite3.Connection:
74 nonlocal connection_count
75 real_connection = real_connect(
76 database,
77 check_same_thread=False,
78 factory=factory,
79 cached_statements=0,
80 timeout=timeout,
81 )
82 connection_count += 1
83 if connection_count < 2:
84 return real_connection
85 configuration: dict[str, Callable[[str], sqlite3.Cursor] | Callable[[], None]] = {}
86 if execute is not None:
87 configuration["execute.side_effect"] = functools.partial(execute, real_connection)
88 if rollback is not None:
89 configuration["rollback.side_effect"] = functools.partial(rollback, real_connection)
90 connection = mocker.MagicMock(
91 spec_set=type(real_connection),
92 wraps=real_connection,
93 database_identity=None,
94 **configuration,
95 )
96 mocker.patch.object(
97 type(connection),
98 "in_transaction",
99 new_callable=mocker.PropertyMock,
100 create=True,
101 side_effect=lambda: real_connection.in_transaction,
102 )
103 return cast("sqlite3.Connection", connection)
104
105 mocker.patch("filelock._sqlite._transactions.connect", side_effect=connect, autospec=True)
106

Callers 5

relink_then_connectFunction · 0.70
replace_then_connectFunction · 0.70
connect_while_pinnedFunction · 0.70
remove_then_connectFunction · 0.70
swap_then_connectFunction · 0.70

Calls

no outgoing calls

Tested by 5

relink_then_connectFunction · 0.56
replace_then_connectFunction · 0.56
connect_while_pinnedFunction · 0.56
remove_then_connectFunction · 0.56
swap_then_connectFunction · 0.56