Skip to content

Commit 304ffa4

Browse files
authored
Merge pull request #1586 from effigies/fix_linkchain_test
TEST: Do not test copy idempotence for unlinked files
2 parents 3f48cb7 + 196f464 commit 304ffa4

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Upcoming release 0.13
33

44
* TST: reduce the size of docker images & use tags for images (https://github.com/nipy/nipype/pull/1564)
55
* ENH: Implement missing inputs/outputs in FSL AvScale (https://github.com/nipy/nipype/pull/1563)
6-
* FIX: Fix symlink test in copyfile (https://github.com/nipy/nipype/pull/1570)
6+
* FIX: Fix symlink test in copyfile (https://github.com/nipy/nipype/pull/1570, https://github.com/nipy/nipype/pull/1586)
77

88

99
Release 0.12.1 (August 3, 2016)

nipype/utils/tests/test_filemanip.py

Lines changed: 49 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,55 @@ 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+
for hashmethod in ('timestamp', 'content'):
187+
kwargs = {'copy': copy, 'use_hardlink': use_hardlink,
188+
'hashmethod': hashmethod}
189+
# Copying does not preserve the original file's timestamp, so
190+
# we may delete and re-copy, if the test is slower than a clock
191+
# tick
192+
if copy and not use_hardlink and hashmethod == 'timestamp':
193+
continue
194+
copyfile(orig_img, new_img, **kwargs)
195+
img_stat = os.stat(new_img)
196+
hdr_stat = os.stat(new_hdr)
197+
copyfile(orig_img, new_img, **kwargs)
198+
err_msg = "Regular - OS: {}; Copy: {}; Hardlink: {}".format(
199+
os.name, copy, use_hardlink)
200+
yield assert_equal, img_stat, os.stat(new_img), err_msg
201+
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
202+
os.unlink(new_img)
203+
os.unlink(new_hdr)
204+
205+
copyfile(img_link, new_img, **kwargs)
206+
img_stat = os.stat(new_img)
207+
hdr_stat = os.stat(new_hdr)
208+
copyfile(img_link, new_img, **kwargs)
209+
err_msg = "Symlink - OS: {}; Copy: {}; Hardlink: {}".format(
210+
os.name, copy, use_hardlink)
211+
yield assert_equal, img_stat, os.stat(new_img), err_msg
212+
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
213+
os.unlink(new_img)
214+
os.unlink(new_hdr)
215+
os.unlink(img_link)
216+
os.unlink(hdr_link)
217+
os.unlink(orig_img)
218+
os.unlink(orig_hdr)
219+
220+
186221
def test_copyfallback():
187222
if os.name is not 'posix':
188223
return

0 commit comments

Comments
 (0)