Skip to content

Commit d2a6ac7

Browse files
committed
Further improve unit test
1 parent f0bdd55 commit d2a6ac7

File tree

1 file changed

+38
-0
lines changed
  • fsspec/tests/abstract

1 file changed

+38
-0
lines changed

fsspec/tests/abstract/mv.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24

35
import fsspec
@@ -17,3 +19,39 @@ def test_move_raises_error_with_tmpdir(tmpdir):
1719
# Use the actual file paths as string
1820
with pytest.raises(FileNotFoundError):
1921
fs.mv(str(source), str(destination))
22+
23+
24+
@pytest.mark.parametrize("recursive", (True, False))
25+
def test_move_raises_error_with_tmpdir_permission(recursive, tmpdir):
26+
# Create a file in the temporary directory
27+
source = tmpdir.join("source_file.txt")
28+
source.write("content")
29+
30+
# Create a protected directory (non-writable)
31+
protected_dir = tmpdir.mkdir("protected_directory")
32+
protected_path = str(protected_dir)
33+
34+
# Set the directory to read-only
35+
if os.name == "nt":
36+
os.system(f'icacls "{protected_path}" /deny Everyone:(W)')
37+
else:
38+
os.chmod(protected_path, 0o555) # Sets the directory to read-only
39+
40+
# Define a destination inside the protected directory
41+
destination = protected_dir.join("destination_file.txt")
42+
43+
# Instantiate the filesystem (assuming the local file system interface)
44+
fs = fsspec.filesystem("file")
45+
46+
# Try to move the file to the read-only directory, expecting a permission error
47+
with pytest.raises(PermissionError):
48+
fs.mv(str(source), str(destination), recursive=recursive)
49+
50+
# Assert the file was not created in the destination
51+
assert not os.path.exists(destination)
52+
53+
# Cleanup: Restore permissions so the directory can be cleaned up
54+
if os.name == "nt":
55+
os.system(f'icacls "{protected_path}" /remove:d Everyone')
56+
else:
57+
os.chmod(protected_path, 0o755) # Restore write permission for cleanup

0 commit comments

Comments
 (0)