def test_access_denied_during_cleanup(tmp_path, monkeypatch): """Ensure that deleting a numbered dir does not fail because of OSErrors (#4262).""" path = tmp_path / "temp-1" path.mkdir() def renamed_failed(*args): raise OSError("access denied") monkeypatch.setattr(Path, "rename", renamed_failed) lock_path = get_lock_path(path) maybe_delete_a_numbered_dir(path) assert not lock_path.is_file()
def test_access_denied_during_cleanup(tmp_path, monkeypatch): """Ensure that deleting a numbered dir does not fail because of OSErrors (#4262).""" path = tmp_path / "temp-1" path.mkdir() def renamed_failed(*args): raise OSError("access denied") monkeypatch.setattr(Path, "rename", renamed_failed) lock_path = get_lock_path(path) maybe_delete_a_numbered_dir(path) assert not lock_path.is_file()
def test_suppress_error_removing_lock(tmp_path): """ensure_deletable should not raise an exception if the lock file cannot be removed (#5456)""" path = tmp_path / "dir" path.mkdir() lock = get_lock_path(path) lock.touch() mtime = lock.stat().st_mtime with unittest.mock.patch.object(Path, "unlink", side_effect=OSError): assert not ensure_deletable( path, consider_lock_dead_if_created_before=mtime + 30) assert lock.is_file() # check now that we can remove the lock file in normal circumstances assert ensure_deletable(path, consider_lock_dead_if_created_before=mtime + 30) assert not lock.is_file()
def test_suppress_error_removing_lock(tmp_path: Path) -> None: """ensure_deletable should be resilient if lock file cannot be removed (#5456, #7491)""" path = tmp_path / "dir" path.mkdir() lock = get_lock_path(path) lock.touch() mtime = lock.stat().st_mtime with unittest.mock.patch.object(Path, "unlink", side_effect=OSError) as m: assert not ensure_deletable( path, consider_lock_dead_if_created_before=mtime + 30) assert m.call_count == 1 assert lock.is_file() with unittest.mock.patch.object(Path, "is_file", side_effect=OSError) as m: assert not ensure_deletable( path, consider_lock_dead_if_created_before=mtime + 30) assert m.call_count == 1 assert lock.is_file() # check now that we can remove the lock file in normal circumstances assert ensure_deletable(path, consider_lock_dead_if_created_before=mtime + 30) assert not lock.is_file()