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

Function test_simple

tests/test_async_filelock.py:15–40  ·  view source on GitHub ↗
(
    lock_type: type[BaseAsyncFileLock],
    path_type: type[str | Path],
    filename: str,
    tmp_path: Path,
    caplog: pytest.LogCaptureFixture,
)

Source from the content-addressed store, hash-verified

13@pytest.mark.parametrize("filename", ["a", "new/b", "new2/new3/c"])
14@pytest.mark.asyncio
15async def test_simple(
16 lock_type: type[BaseAsyncFileLock],
17 path_type: type[str | Path],
18 filename: str,
19 tmp_path: Path,
20 caplog: pytest.LogCaptureFixture,
21) -> None:
22 caplog.set_level(logging.DEBUG)
23
24 # test lock creation by passing a `str`
25 lock_path = tmp_path / filename
26 lock = lock_type(path_type(lock_path))
27 async with lock as locked:
28 assert lock.is_locked
29 assert lock is locked
30 assert not lock.is_locked
31
32 assert caplog.messages == [
33 f"Attempting to acquire lock {id(lock)} on {lock_path}",
34 f"Lock {id(lock)} acquired on {lock_path}",
35 f"Attempting to release lock {id(lock)} on {lock_path}",
36 f"Lock {id(lock)} released on {lock_path}",
37 ]
38 assert [r.levelno for r in caplog.records] == [logging.DEBUG, logging.DEBUG, logging.DEBUG, logging.DEBUG]
39 assert [r.name for r in caplog.records] == ["filelock", "filelock", "filelock", "filelock"]
40 assert logging.getLogger("filelock").level == logging.NOTSET
41
42
43@pytest.mark.parametrize("lock_type", [AsyncFileLock, AsyncSoftFileLock])

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected