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

Function test_simple

tests/async_lock/test_lock.py:26–51  ·  view source on GitHub ↗
(
    lock_type: type[BaseAsyncFileLock],
    path_type: type[str | Path],
    filename: str,
    tmp_path: Path,
    caplog: pytest.LogCaptureFixture,
    *,
    enter: Enter,
)

Source from the content-addressed store, hash-verified

24@pytest.mark.parametrize("enter", ENTER)
25@pytest.mark.asyncio
26async def test_simple(
27 lock_type: type[BaseAsyncFileLock],
28 path_type: type[str | Path],
29 filename: str,
30 tmp_path: Path,
31 caplog: pytest.LogCaptureFixture,
32 *,
33 enter: Enter,
34) -> None:
35 caplog.set_level(logging.DEBUG)
36
37 lock_path = tmp_path / filename
38 lock = lock_type(path_type(lock_path))
39 async with enter(lock) as locked:
40 assert lock.is_locked
41 assert lock is locked
42 assert not lock.is_locked
43
44 # A runtime with a lazy collector may finalize, mid-test, a lock an earlier test dropped.
45 assert [(r.name, r.levelno, r.getMessage()) for r in caplog.records if str(lock_path) in r.getMessage()] == [
46 ("filelock", logging.DEBUG, f"Attempting to acquire lock {id(lock)} on {lock_path}"),
47 ("filelock", logging.DEBUG, f"Lock {id(lock)} acquired on {lock_path}"),
48 ("filelock", logging.DEBUG, f"Attempting to release lock {id(lock)} on {lock_path}"),
49 ("filelock", logging.DEBUG, f"Lock {id(lock)} released on {lock_path}"),
50 ]
51 assert logging.getLogger("filelock").level == logging.NOTSET
52
53
54@pytest.mark.parametrize("lock_type", [AsyncFileLock, AsyncSoftFileLock])

Callers

nothing calls this directly

Calls 2

lock_typeFunction · 0.85
enterFunction · 0.85

Tested by

no test coverage detected