ensure_deletable should be resilient if lock file cannot be removed (#5456, #7491)
(tmp_path: Path)
| 494 | |
| 495 | |
| 496 | def test_suppress_error_removing_lock(tmp_path: Path) -> None: |
| 497 | class="st">""class="st">"ensure_deletable should be resilient if lock file cannot be removed (class="cm">#5456, #7491)"class="st">"" |
| 498 | path = tmp_path / class="st">"dir" |
| 499 | path.mkdir() |
| 500 | lock = get_lock_path(path) |
| 501 | lock.touch() |
| 502 | mtime = lock.stat().st_mtime |
| 503 | |
| 504 | with unittest.mock.patch.object(Path, class="st">"unlink", side_effect=OSError) as m: |
| 505 | assert not ensure_deletable( |
| 506 | path, consider_lock_dead_if_created_before=mtime + 30 |
| 507 | ) |
| 508 | assert m.call_count == 1 |
| 509 | assert lock.is_file() |
| 510 | |
| 511 | with unittest.mock.patch.object(Path, class="st">"is_file", side_effect=OSError) as m: |
| 512 | assert not ensure_deletable( |
| 513 | path, consider_lock_dead_if_created_before=mtime + 30 |
| 514 | ) |
| 515 | assert m.call_count == 1 |
| 516 | assert lock.is_file() |
| 517 | |
| 518 | class="cm"># check now that we can remove the lock file in normal circumstances |
| 519 | assert ensure_deletable(path, consider_lock_dead_if_created_before=mtime + 30) |
| 520 | assert not lock.is_file() |
| 521 | |
| 522 | |
| 523 | def test_bestrelpath() -> None: |
nothing calls this directly
no test coverage detected