7
7
except ImportError :
8
8
import mock
9
9
10
- from parameterized import parameterized_class
10
+ from parameterized import parameterized , parameterized_class
11
11
12
12
13
13
import fs .move
@@ -80,10 +80,10 @@ def test_move_dir(self):
80
80
81
81
fs .move .move_dir (src_fs , "/foo" , dst_fs , "/" , preserve_time = self .preserve_time )
82
82
83
- self .assertTrue (dst_fs .isdir ("bar" ))
84
- self .assertTrue (dst_fs .isfile ("bar/baz.txt" ))
85
83
self .assertFalse (src_fs .exists ("foo" ))
86
84
self .assertTrue (src_fs .isfile ("test.txt" ))
85
+ self .assertTrue (dst_fs .isdir ("bar" ))
86
+ self .assertTrue (dst_fs .isfile ("bar/baz.txt" ))
87
87
88
88
if self .preserve_time :
89
89
dst_file2_info = dst_fs .getinfo ("bar/baz.txt" , namespaces )
@@ -104,16 +104,16 @@ def test_move_file_fs_urls(self):
104
104
# create a temp dir to work on
105
105
with open_fs ("temp://" ) as tmp :
106
106
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" )
109
109
tmp .makedir ("subdir_dst" )
110
110
fs .move .move_file (
111
111
"osfs://" + join (path , "subdir_src" ),
112
112
"file.txt" ,
113
113
"osfs://" + join (path , "subdir_dst" ),
114
114
"target.txt" ,
115
115
)
116
- self .assertFalse (subdir_src .exists ("file.txt" ))
116
+ self .assertFalse (tmp .exists ("subdir_src/ file.txt" ))
117
117
self .assertEqual (tmp .readtext ("subdir_dst/target.txt" ), "Content" )
118
118
119
119
def test_move_file_same_fs_read_only_source (self ):
@@ -124,10 +124,10 @@ def test_move_file_same_fs_read_only_source(self):
124
124
dst = tmp .makedir ("sub" )
125
125
with self .assertRaises (ResourceReadOnly ):
126
126
fs .move .move_file (src , "file.txt" , dst , "target_file.txt" )
127
+ self .assertTrue (src .exists ("file.txt" ))
127
128
self .assertFalse (
128
129
dst .exists ("target_file.txt" ), "file should not have been copied over"
129
130
)
130
- self .assertTrue (src .exists ("file.txt" ))
131
131
132
132
def test_move_file_read_only_mem_source (self ):
133
133
with open_fs ("mem://" ) as src , open_fs ("mem://" ) as dst :
@@ -136,40 +136,35 @@ def test_move_file_read_only_mem_source(self):
136
136
src_ro = read_only (src )
137
137
with self .assertRaises (ResourceReadOnly ):
138
138
fs .move .move_file (src_ro , "file.txt" , dst_sub , "target.txt" )
139
+ self .assertTrue (src .exists ("file.txt" ))
139
140
self .assertFalse (
140
141
dst_sub .exists ("target.txt" ), "file should not have been copied over"
141
142
)
142
- self .assertTrue (src .exists ("file.txt" ))
143
143
144
144
def test_move_file_read_only_mem_dest (self ):
145
145
with open_fs ("mem://" ) as src , open_fs ("mem://" ) as dst :
146
146
src .writetext ("file.txt" , "Content" )
147
147
dst_ro = read_only (dst )
148
148
with self .assertRaises (ResourceReadOnly ):
149
149
fs .move .move_file (src , "file.txt" , dst_ro , "target.txt" )
150
+ self .assertTrue (src .exists ("file.txt" ))
150
151
self .assertFalse (
151
152
dst_ro .exists ("target.txt" ), "file should not have been copied over"
152
153
)
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" ))
164
154
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 ):
166
157
with open_fs ("mem://" ) as src , open_fs ("mem://" ) as dst :
167
158
src .writetext ("file.txt" , "Content" )
168
159
with mock .patch .object (src , "remove" ) as mck :
169
160
mck .side_effect = FSError
170
161
with self .assertRaises (FSError ):
171
162
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 ,
173
168
)
174
169
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