@@ -151,30 +151,45 @@ 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- @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
154+ @parameterized .expand ([("temp" , "temp ://" ), ("mem" , "mem ://" )])
155+ def test_move_file_overwrite (self , _ , fs_url ):
156+ # we use TempFS and MemoryFS in order to make sure the optimized code path
157+ # behaves like the regular one (TempFS tests the optmized code path).
158158 with open_fs (fs_url ) as src , open_fs (fs_url ) as dst :
159159 src .writetext ("file.txt" , "source content" )
160160 dst .writetext ("target.txt" , "target content" )
161+ self .assertTrue (src .exists ("file.txt" ))
162+ self .assertFalse (src .exists ("target.txt" ))
163+ self .assertFalse (dst .exists ("file.txt" ))
164+ self .assertTrue (dst .exists ("target.txt" ))
161165 fs .move .move_file (src , "file.txt" , dst , "target.txt" )
162166 self .assertFalse (src .exists ("file.txt" ))
163167 self .assertFalse (src .exists ("target.txt" ))
164168 self .assertFalse (dst .exists ("file.txt" ))
165169 self .assertTrue (dst .exists ("target.txt" ))
166170 self .assertEquals (dst .readtext ("target.txt" ), "source content" )
167171
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+ @parameterized .expand ([("temp" , "temp ://" ), ("mem" , "mem ://" )])
173+ def test_move_file_overwrite_itself (self , _ , fs_url ):
174+ # we use TempFS and MemoryFS in order to make sure the optimized code path
175+ # behaves like the regular one (TempFS tests the optmized code path).
172176 with open_fs (fs_url ) as tmp :
173177 tmp .writetext ("file.txt" , "content" )
174178 fs .move .move_file (tmp , "file.txt" , tmp , "file.txt" )
175179 self .assertTrue (tmp .exists ("file.txt" ))
176180 self .assertEquals (tmp .readtext ("file.txt" ), "content" )
177181
182+ @parameterized .expand ([("temp" , "temp://" ), ("mem" , "mem://" )])
183+ def test_move_file_overwrite_itself_relpath (self , _ , fs_url ):
184+ # we use TempFS and MemoryFS in order to make sure the optimized code path
185+ # behaves like the regular one (TempFS tests the optmized code path).
186+ with open_fs (fs_url ) as tmp :
187+ new_dir = tmp .makedir ("dir" )
188+ new_dir .writetext ("file.txt" , "content" )
189+ fs .move .move_file (tmp , "dir/../dir/file.txt" , tmp , "dir/file.txt" )
190+ self .assertTrue (tmp .exists ("dir/file.txt" ))
191+ self .assertEquals (tmp .readtext ("dir/file.txt" ), "content" )
192+
178193 @parameterized .expand ([(True ,), (False ,)])
179194 def test_move_file_cleanup_on_error (self , cleanup ):
180195 with open_fs ("mem://" ) as src , open_fs ("mem://" ) as dst :
0 commit comments