(
lock_type: type[BaseFileLock],
path_type: type[str | Path],
filename: str,
tmp_path: Path,
caplog: pytest.LogCaptureFixture,
)
| 31 | @pytest.mark.parametrize("path_type", [str, PurePath, Path]) |
| 32 | @pytest.mark.parametrize("filename", ["a", "new/b", "new2/new3/c"]) |
| 33 | def 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( |
nothing calls this directly
no test coverage detected