Skip to content

Commit 23cfddc

Browse files
committed
TEST: Separate recopy test, err_msg for debugging
1 parent 3f48cb7 commit 23cfddc

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

nipype/utils/tests/test_filemanip.py

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,6 @@ def test_linkchain():
158158
yield assert_true, os.path.samefile(orig_img, new_img3)
159159
yield assert_true, os.path.samefile(orig_hdr, new_hdr3)
160160

161-
# Test that re-copying leaves files
162-
stat1 = os.stat(new_img1)
163-
stat2 = os.stat(new_img2)
164-
stat3 = os.stat(new_img3)
165-
# Same symlink
166-
copyfile(orig_img, new_img1)
167-
# Hash matches
168-
copyfile(new_img1, new_img2, copy=True)
169-
# Hardlinks
170-
copyfile(new_img1, new_img3, copy=True, use_hardlink=True)
171-
yield assert_equal, stat1, os.stat(new_img1)
172-
yield assert_equal, stat2, os.stat(new_img2)
173-
yield assert_equal, stat3, os.stat(new_img3)
174-
175161
os.unlink(new_img1)
176162
os.unlink(new_hdr1)
177163
os.unlink(new_img2)
@@ -183,6 +169,47 @@ def test_linkchain():
183169
os.unlink(orig_hdr)
184170

185171

172+
def test_recopy():
173+
# Re-copying with the same parameters on an unchanged file should be
174+
# idempotent
175+
#
176+
# Test for copying from regular files and symlinks
177+
orig_img, orig_hdr = _temp_analyze_files()
178+
pth, fname = os.path.split(orig_img)
179+
img_link = os.path.join(pth, 'imglink.img')
180+
hdr_link = os.path.join(pth, 'imglink.hdr')
181+
new_img = os.path.join(pth, 'newfile.img')
182+
new_hdr = os.path.join(pth, 'newfile.hdr')
183+
copyfile(orig_img, img_link)
184+
for copy in (True, False):
185+
for use_hardlink in (True, False):
186+
copyfile(orig_img, new_img, copy=copy, use_hardlink=use_hardlink)
187+
img_stat = os.stat(new_img)
188+
hdr_stat = os.stat(new_hdr)
189+
copyfile(orig_img, new_img, copy=copy, use_hardlink=use_hardlink)
190+
err_msg = "Regular - OS: {}; Copy: {}; Hardlink: {}".format(
191+
os.name, copy, use_hardlink)
192+
yield assert_equal, img_stat, os.stat(new_img), err_msg
193+
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
194+
os.unlink(new_img)
195+
os.unlink(new_hdr)
196+
197+
copyfile(img_link, new_img, copy=copy, use_hardlink=use_hardlink)
198+
img_stat = os.stat(new_img)
199+
hdr_stat = os.stat(new_hdr)
200+
copyfile(img_link, new_img, copy=copy, use_hardlink=use_hardlink)
201+
err_msg = "Symlink - OS: {}; Copy: {}; Hardlink: {}".format(
202+
os.name, copy, use_hardlink)
203+
yield assert_equal, img_stat, os.stat(new_img), err_msg
204+
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
205+
os.unlink(new_img)
206+
os.unlink(new_hdr)
207+
os.unlink(img_link)
208+
os.unlink(hdr_link)
209+
os.unlink(orig_img)
210+
os.unlink(orig_hdr)
211+
212+
186213
def test_copyfallback():
187214
if os.name is not 'posix':
188215
return

0 commit comments

Comments
 (0)