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

Function test_simple

tests/core/test_lock.py:33–56  ·  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

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

Callers

nothing calls this directly

Calls 1

lock_typeFunction · 0.85

Tested by

no test coverage detected