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

Function connect

tests/test_async_read_write_cancellation.py:478–508  ·  view source on GitHub ↗
(
        database: str,
        *,
        factory: type[sqlite3.Connection],
        timeout: float,
    )

Source from the content-addressed store, hash-verified

476 connection_count = 0
477
478 def connect(
479 database: str,
480 *,
481 factory: type[sqlite3.Connection],
482 timeout: float,
483 ) -> sqlite3.Connection:
484 nonlocal connection_count
485 real_connection = real_connect(
486 database,
487 check_same_thread=False,
488 factory=factory,
489 cached_statements=0,
490 timeout=timeout,
491 )
492 connection_count += 1
493 if connection_count != 2:
494 return real_connection
495 configuration: dict[str, Callable[[str], sqlite3.Cursor] | Callable[[], None]] = {}
496 if executescript is not None:
497 configuration["executescript.side_effect"] = functools.partial(executescript, real_connection)
498 if rollback is not None:
499 configuration["rollback.side_effect"] = functools.partial(rollback, real_connection)
500 connection = mocker.MagicMock(spec_set=type(real_connection), wraps=real_connection, **configuration)
501 mocker.patch.object(
502 type(connection),
503 "in_transaction",
504 new_callable=mocker.PropertyMock,
505 create=True,
506 side_effect=lambda: real_connection.in_transaction,
507 )
508 return cast("sqlite3.Connection", connection)
509
510 mocker.patch("filelock._read_write._connect", side_effect=connect)
511

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected