77except ImportError :
88 import mock
99
10- from parameterized import parameterized_class
10+ from parameterized import parameterized , parameterized_class
1111
1212
1313import fs .move
@@ -80,10 +80,10 @@ def test_move_dir(self):
8080
8181 fs .move .move_dir (src_fs , "/foo" , dst_fs , "/" , preserve_time = self .preserve_time )
8282
83- self .assertTrue (dst_fs .isdir ("bar" ))
84- self .assertTrue (dst_fs .isfile ("bar/baz.txt" ))
8583 self .assertFalse (src_fs .exists ("foo" ))
8684 self .assertTrue (src_fs .isfile ("test.txt" ))
85+ self .assertTrue (dst_fs .isdir ("bar" ))
86+ self .assertTrue (dst_fs .isfile ("bar/baz.txt" ))
8787
8888 if self .preserve_time :
8989 dst_file2_info = dst_fs .getinfo ("bar/baz.txt" , namespaces )
@@ -104,16 +104,16 @@ def test_move_file_fs_urls(self):
104104 # create a temp dir to work on
105105 with open_fs ("temp://" ) as tmp :
106106 path = tmp .getsyspath ("/" )
107- subdir_src = tmp .makedir ("subdir_src" )
108- subdir_src .writetext ("file.txt" , "Content" )
107+ tmp .makedir ("subdir_src" )
108+ tmp .writetext ("subdir_src/ file.txt" , "Content" )
109109 tmp .makedir ("subdir_dst" )
110110 fs .move .move_file (
111111 "osfs://" + join (path , "subdir_src" ),
112112 "file.txt" ,
113113 "osfs://" + join (path , "subdir_dst" ),
114114 "target.txt" ,
115115 )
116- self .assertFalse (subdir_src .exists ("file.txt" ))
116+ self .assertFalse (tmp .exists ("subdir_src/ file.txt" ))
117117 self .assertEqual (tmp .readtext ("subdir_dst/target.txt" ), "Content" )
118118
119119 def test_move_file_same_fs_read_only_source (self ):
@@ -124,10 +124,10 @@ def test_move_file_same_fs_read_only_source(self):
124124 dst = tmp .makedir ("sub" )
125125 with self .assertRaises (ResourceReadOnly ):
126126 fs .move .move_file (src , "file.txt" , dst , "target_file.txt" )
127+ self .assertTrue (src .exists ("file.txt" ))
127128 self .assertFalse (
128129 dst .exists ("target_file.txt" ), "file should not have been copied over"
129130 )
130- self .assertTrue (src .exists ("file.txt" ))
131131
132132 def test_move_file_read_only_mem_source (self ):
133133 with open_fs ("mem://" ) as src , open_fs ("mem://" ) as dst :
@@ -136,40 +136,35 @@ def test_move_file_read_only_mem_source(self):
136136 src_ro = read_only (src )
137137 with self .assertRaises (ResourceReadOnly ):
138138 fs .move .move_file (src_ro , "file.txt" , dst_sub , "target.txt" )
139+ self .assertTrue (src .exists ("file.txt" ))
139140 self .assertFalse (
140141 dst_sub .exists ("target.txt" ), "file should not have been copied over"
141142 )
142- self .assertTrue (src .exists ("file.txt" ))
143143
144144 def test_move_file_read_only_mem_dest (self ):
145145 with open_fs ("mem://" ) as src , open_fs ("mem://" ) as dst :
146146 src .writetext ("file.txt" , "Content" )
147147 dst_ro = read_only (dst )
148148 with self .assertRaises (ResourceReadOnly ):
149149 fs .move .move_file (src , "file.txt" , dst_ro , "target.txt" )
150+ self .assertTrue (src .exists ("file.txt" ))
150151 self .assertFalse (
151152 dst_ro .exists ("target.txt" ), "file should not have been copied over"
152153 )
153- self .assertTrue (src .exists ("file.txt" ))
154-
155- def test_move_file_cleanup_on_error (self ):
156- with open_fs ("mem://" ) as src , open_fs ("mem://" ) as dst :
157- src .writetext ("file.txt" , "Content" )
158- with mock .patch .object (src , "remove" ) as mck :
159- mck .side_effect = FSError
160- with self .assertRaises (FSError ):
161- fs .move .move_file (src , "file.txt" , dst , "target.txt" )
162- self .assertTrue (src .exists ("file.txt" ))
163- self .assertFalse (dst .exists ("target.txt" ))
164154
165- def test_move_file_no_cleanup_on_error (self ):
155+ @parameterized .expand ([(True ,), (False ,)])
156+ def test_move_file_cleanup_on_error (self , cleanup ):
166157 with open_fs ("mem://" ) as src , open_fs ("mem://" ) as dst :
167158 src .writetext ("file.txt" , "Content" )
168159 with mock .patch .object (src , "remove" ) as mck :
169160 mck .side_effect = FSError
170161 with self .assertRaises (FSError ):
171162 fs .move .move_file (
172- src , "file.txt" , dst , "target.txt" , cleanup_dst_on_error = False
163+ src ,
164+ "file.txt" ,
165+ dst ,
166+ "target.txt" ,
167+ cleanup_dst_on_error = cleanup ,
173168 )
174169 self .assertTrue (src .exists ("file.txt" ))
175- self .assertTrue ( dst .exists ("target.txt" ))
170+ self .assertEqual ( not dst .exists ("target.txt" ), cleanup )
0 commit comments