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

Function test_simple

tests/test_filelock.py:30–55  ·  view source on GitHub ↗
(
    lock_type: type[BaseFileLock],
    path_type: type[str | Path],
    filename: str,
    tmp_path: Path,
    caplog: pytest.LogCaptureFixture,
)

Source from the content-addressed store, hash-verified

28@pytest.mark.parametrize("path_type", [str, PurePath, Path])
29@pytest.mark.parametrize("filename", ["a", "new/b", "new2/new3/c"])
30def test_simple(
31 lock_type: type[BaseFileLock],
32 path_type: type[str | Path],
33 filename: str,
34 tmp_path: Path,
35 caplog: pytest.LogCaptureFixture,
36) -> None:
37 caplog.set_level(logging.DEBUG)
38
39 # test lock creation by passing a `str`
40 lock_path = tmp_path / filename
41 lock = lock_type(path_type(lock_path))
42 with lock as locked:
43 assert lock.is_locked
44 assert lock is locked
45 assert not lock.is_locked
46
47 assert caplog.messages == [
48 f"Attempting to acquire lock {id(lock)} on {lock_path}",
49 f"Lock {id(lock)} acquired on {lock_path}",
50 f"Attempting to release lock {id(lock)} on {lock_path}",
51 f"Lock {id(lock)} released on {lock_path}",
52 ]
53 assert [r.levelno for r in caplog.records] == [logging.DEBUG, logging.DEBUG, logging.DEBUG, logging.DEBUG]
54 assert [r.name for r in caplog.records] == ["filelock", "filelock", "filelock", "filelock"]
55 assert logging.getLogger("filelock").level == logging.NOTSET
56
57
58@contextmanager

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected