| 386 | |
| 387 | @pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) |
| 388 | def test_default_timeout(lock_type: type[BaseFileLock], tmp_path: Path) -> None: |
| 389 | # test if the default timeout parameter works |
| 390 | lock_path = tmp_path / "a" |
| 391 | lock_1, lock_2 = lock_type(str(lock_path)), lock_type(str(lock_path), timeout=0.1) |
| 392 | assert lock_2.timeout == 0.1 |
| 393 | |
| 394 | # acquire lock 1 |
| 395 | lock_1.acquire() |
| 396 | assert lock_1.is_locked |
| 397 | assert not lock_2.is_locked |
| 398 | |
| 399 | # try to acquire lock 2 |
| 400 | with pytest.raises(Timeout, match="The file lock '.*' could not be acquired."): |
| 401 | lock_2.acquire() |
| 402 | assert not lock_2.is_locked |
| 403 | assert lock_1.is_locked |
| 404 | |
| 405 | lock_2.timeout = 0 |
| 406 | assert lock_2.timeout == 0 |
| 407 | |
| 408 | with pytest.raises(Timeout, match="The file lock '.*' could not be acquired."): |
| 409 | lock_2.acquire() |
| 410 | assert not lock_2.is_locked |
| 411 | assert lock_1.is_locked |
| 412 | |
| 413 | # release lock 1 |
| 414 | lock_1.release() |
| 415 | assert not lock_1.is_locked |
| 416 | assert not lock_2.is_locked |
| 417 | |
| 418 | |
| 419 | @pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) |