ensure_deletable should be resilient if lock file cannot be removed (#5456, #7491)
(tmp_path: Path)
| 375 | |
| 376 | |
| 377 | def test_suppress_error_removing_lock(tmp_path: Path) -> None: |
| 378 | """ensure_deletable should be resilient if lock file cannot be removed (#5456, #7491)""" |
| 379 | path = tmp_path / "dir" |
| 380 | path.mkdir() |
| 381 | lock = get_lock_path(path) |
| 382 | lock.touch() |
| 383 | mtime = lock.stat().st_mtime |
| 384 | |
| 385 | with unittest.mock.patch.object(Path, "unlink", side_effect=OSError) as m: |
| 386 | assert not ensure_deletable( |
| 387 | path, consider_lock_dead_if_created_before=mtime + 30 |
| 388 | ) |
| 389 | assert m.call_count == 1 |
| 390 | assert lock.is_file() |
| 391 | |
| 392 | with unittest.mock.patch.object(Path, "is_file", side_effect=OSError) as m: |
| 393 | assert not ensure_deletable( |
| 394 | path, consider_lock_dead_if_created_before=mtime + 30 |
| 395 | ) |
| 396 | assert m.call_count == 1 |
| 397 | assert lock.is_file() |
| 398 | |
| 399 | # check now that we can remove the lock file in normal circumstances |
| 400 | assert ensure_deletable(path, consider_lock_dead_if_created_before=mtime + 30) |
| 401 | assert not lock.is_file() |
| 402 | |
| 403 | |
| 404 | def test_bestrelpath() -> None: |
nothing calls this directly
no test coverage detected