| 24 | @pytest.mark.parametrize("enter", ENTER) |
| 25 | @pytest.mark.asyncio |
| 26 | async 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]) |