@@ -151,13 +151,29 @@ def test_move_file_read_only_mem_dest(self):
151151 dst_ro .exists ("target.txt" ), "file should not have been copied over"
152152 )
153153
154- def test_overwrite (self ):
155- with open_fs ("temp://" ) as src , open_fs ("temp://" ) as dst :
156- src .writetext ("file.txt" , "Content" )
157- dst .writetext ("target.txt" , "Content" )
154+ @parameterized .expand ([("temp://" ,), ("mem://" ,)])
155+ def test_move_file_overwrite (self , fs_url ):
156+ # we use TempFS and MemoryFS in order to make sure the optimised code path
157+ # behaves like the regular one
158+ with open_fs (fs_url ) as src , open_fs (fs_url ) as dst :
159+ src .writetext ("file.txt" , "source content" )
160+ dst .writetext ("target.txt" , "target content" )
158161 fs .move .move_file (src , "file.txt" , dst , "target.txt" )
159162 self .assertFalse (src .exists ("file.txt" ))
163+ self .assertFalse (src .exists ("target.txt" ))
164+ self .assertFalse (dst .exists ("file.txt" ))
160165 self .assertTrue (dst .exists ("target.txt" ))
166+ self .assertEquals (dst .readtext ("target.txt" ), "source content" )
167+
168+ @parameterized .expand ([("temp://" ,), ("mem://" ,)])
169+ def test_move_file_overwrite_itself (self , fs_url ):
170+ # we use TempFS and MemoryFS in order to make sure the optimised code path
171+ # behaves like the regular one
172+ with open_fs (fs_url ) as tmp :
173+ tmp .writetext ("file.txt" , "content" )
174+ fs .move .move_file (tmp , "file.txt" , tmp , "file.txt" )
175+ self .assertTrue (tmp .exists ("file.txt" ))
176+ self .assertEquals (tmp .readtext ("file.txt" ), "content" )
161177
162178 @parameterized .expand ([(True ,), (False ,)])
163179 def test_move_file_cleanup_on_error (self , cleanup ):
0 commit comments