1
+ import os
2
+
1
3
import pytest
2
4
3
5
import fsspec
@@ -17,3 +19,39 @@ def test_move_raises_error_with_tmpdir(tmpdir):
17
19
# Use the actual file paths as string
18
20
with pytest .raises (FileNotFoundError ):
19
21
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