def test_fail_undelete_non_existing_original_directory(tmp_path): directory = tmp_path / "directory" directory.mkdir() original_filename = create_tmpfile(directory, "file") trash_filename = trash_manager.delete(original_filename) directory.rmdir() with pytest.raises(FileNotFoundError, match="Original directory"): trash_manager.undelete(pathlib.Path(trash_filename).name)
def test_undelete_symlink(tmp_path): path = tmp_path / "file" path.touch() path_to_link = tmp_path / "link" path_to_link.symlink_to("file") trash_filename = trash_manager.delete(str(path_to_link)) trash_manager.undelete(trash_filename) assert path_to_link.exists() assert path_to_link.is_symlink() assert path_to_link.resolve() == path
def undelete(basenames: List[str]) -> None: """Restore a file from the trash directory. **syntax:** ``:undelete [basename ...]`` If no basename is given, the last deleted images in this session are restored. positional arguments: * ``basenames``: The basename(s) of the file in the trash directory. """ basenames = basenames if basenames else _last_deleted for basename in basenames: try: trash_manager.undelete(basename) except FileNotFoundError as e: raise api.commands.CommandError(str(e))
def test_fail_undelete_non_existing_file(tmp_path): with pytest.raises(FileNotFoundError, match="File for"): path = tmp_path / "any" / "random" / "file" trash_manager.undelete(str(path))
def test_undelete_file(deleted_file): trash_manager.undelete(deleted_file.trash.name) assert deleted_file.original.exists(), "Original file not restored" assert not deleted_file.trash.exists(), "File not removed from trash" assert not deleted_file.info.exists(), "File info not removed from trash"
def test_delete_and_undelete_file(trash, tmpfile): trash_manager.delete([tmpfile]) basename = os.path.basename(tmpfile) trash_manager.undelete([basename]) assert os.path.exists(tmpfile)