|
import os |
|
|
|
import pytest |
|
|
|
import fsspec |
|
|
|
|
|
def test_move_raises_error_with_tmpdir(tmpdir): |
|
|
|
source = tmpdir.join("source_file.txt") |
|
source.write("content") |
|
|
|
|
|
destination = tmpdir.join("non_existent_directory/destination_file.txt") |
|
|
|
|
|
fs = fsspec.filesystem("file") |
|
|
|
|
|
with pytest.raises(FileNotFoundError): |
|
fs.mv(str(source), str(destination)) |
|
|
|
|
|
@pytest.mark.parametrize("recursive", (True, False)) |
|
def test_move_raises_error_with_tmpdir_permission(recursive, tmpdir): |
|
|
|
source = tmpdir.join("source_file.txt") |
|
source.write("content") |
|
|
|
|
|
protected_dir = tmpdir.mkdir("protected_directory") |
|
protected_path = str(protected_dir) |
|
|
|
|
|
if os.name == "nt": |
|
os.system(f'icacls "{protected_path}" /deny Everyone:(W)') |
|
else: |
|
os.chmod(protected_path, 0o555) |
|
|
|
|
|
destination = protected_dir.join("destination_file.txt") |
|
|
|
|
|
fs = fsspec.filesystem("file") |
|
|
|
|
|
with pytest.raises(PermissionError): |
|
fs.mv(str(source), str(destination), recursive=recursive) |
|
|
|
|
|
assert not os.path.exists(destination) |
|
|
|
|
|
if os.name == "nt": |
|
os.system(f'icacls "{protected_path}" /remove:d Everyone') |
|
else: |
|
os.chmod(protected_path, 0o755) |
|
|