| 72 | |
| 73 | @pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) |
| 74 | def test_default_timeout(lock_type: type[BaseFileLock], tmp_path: Path) -> None: |
| 75 | lock_path = tmp_path / "a" |
| 76 | lock_1, lock_2 = lock_type(str(lock_path)), lock_type(str(lock_path), timeout=0.1) |
| 77 | assert lock_2.timeout == pytest.approx(0.1) |
| 78 | |
| 79 | lock_1.acquire() |
| 80 | assert lock_1.is_locked |
| 81 | assert not lock_2.is_locked |
| 82 | |
| 83 | with pytest.raises(Timeout, match=r"The file lock '.*' could not be acquired."): |
| 84 | lock_2.acquire() |
| 85 | assert not lock_2.is_locked |
| 86 | assert lock_1.is_locked |
| 87 | |
| 88 | lock_2.timeout = 0 |
| 89 | assert lock_2.timeout == 0 |
| 90 | |
| 91 | with pytest.raises(Timeout, match=r"The file lock '.*' could not be acquired."): |
| 92 | lock_2.acquire() |
| 93 | assert not lock_2.is_locked |
| 94 | assert lock_1.is_locked |
| 95 | |
| 96 | lock_1.release() |
| 97 | assert not lock_1.is_locked |
| 98 | assert not lock_2.is_locked |
| 99 | |
| 100 | |
| 101 | @pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) |