def test_rmtree_errorhandler_nonexistent_directory(tmpdir): """ Test rmtree_errorhandler ignores the given non-existing directory. """ nonexistent_path = str(tmpdir / 'foo') mock_func = Mock() rmtree_errorhandler(mock_func, nonexistent_path, None) mock_func.assert_not_called()
def test_rmtree_errorhandler_nonexistent_directory(tmpdir: Path) -> None: """ Test rmtree_errorhandler ignores the given non-existing directory. """ nonexistent_path = str(tmpdir / "foo") mock_func = Mock() # Argument 3 to "rmtree_errorhandler" has incompatible type "None"; expected # "Tuple[Type[BaseException], BaseException, TracebackType]" rmtree_errorhandler(mock_func, nonexistent_path, None) # type: ignore[arg-type] mock_func.assert_not_called()
def test_rmtree_errorhandler_readonly_directory(tmpdir): """ Test rmtree_errorhandler makes the given read-only directory writable. """ # Create read only directory path = str((tmpdir / 'subdir').mkdir()) os.chmod(path, stat.S_IREAD) # Make sure mock_func is called with the given path mock_func = Mock() rmtree_errorhandler(mock_func, path, None) mock_func.assert_called_with(path) # Make sure the path is now writable assert os.stat(path).st_mode & stat.S_IWRITE
def test_rmtree_errorhandler_reraises_error(tmpdir): """ Test rmtree_errorhandler reraises an exception by the given unreadable directory. """ # Create directory without read permission path = str((tmpdir / 'subdir').mkdir()) os.chmod(path, stat.S_IWRITE) mock_func = Mock() try: raise RuntimeError('test message') except RuntimeError: # Make sure the handler reraises an exception with pytest.raises(RuntimeError, match='test message'): rmtree_errorhandler(mock_func, path, None) mock_func.assert_not_called()
def test_rmtree_errorhandler_readonly_directory(tmpdir: Path) -> None: """ Test rmtree_errorhandler makes the given read-only directory writable. """ # Create read only directory subdir_path = tmpdir / "subdir" subdir_path.mkdir() path = str(subdir_path) os.chmod(path, stat.S_IREAD) # Make sure mock_func is called with the given path mock_func = Mock() # Argument 3 to "rmtree_errorhandler" has incompatible type "None"; expected # "Tuple[Type[BaseException], BaseException, TracebackType]" rmtree_errorhandler(mock_func, path, None) # type: ignore[arg-type] mock_func.assert_called_with(path) # Make sure the path is now writable assert os.stat(path).st_mode & stat.S_IWRITE
def test_rmtree_errorhandler_reraises_error(tmpdir: Path) -> None: """ Test rmtree_errorhandler reraises an exception by the given unreadable directory. """ # Create directory without read permission subdir_path = tmpdir / "subdir" subdir_path.mkdir() path = str(subdir_path) os.chmod(path, stat.S_IWRITE) mock_func = Mock() try: raise RuntimeError("test message") except RuntimeError: # Make sure the handler reraises an exception with pytest.raises(RuntimeError, match="test message"): # Argument 3 to "rmtree_errorhandler" has incompatible type "None"; expected # "Tuple[Type[BaseException], BaseException, TracebackType]" rmtree_errorhandler(mock_func, path, None) # type: ignore[arg-type] mock_func.assert_not_called()