Skip to content

TEST: Do not test copy idempotence for unlinked files #1586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Upcoming release 0.13

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


Release 0.12.1 (August 3, 2016)
Expand Down
63 changes: 49 additions & 14 deletions nipype/utils/tests/test_filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,6 @@ def test_linkchain():
yield assert_true, os.path.samefile(orig_img, new_img3)
yield assert_true, os.path.samefile(orig_hdr, new_hdr3)

# Test that re-copying leaves files
stat1 = os.stat(new_img1)
stat2 = os.stat(new_img2)
stat3 = os.stat(new_img3)
# Same symlink
copyfile(orig_img, new_img1)
# Hash matches
copyfile(new_img1, new_img2, copy=True)
# Hardlinks
copyfile(new_img1, new_img3, copy=True, use_hardlink=True)
yield assert_equal, stat1, os.stat(new_img1)
yield assert_equal, stat2, os.stat(new_img2)
yield assert_equal, stat3, os.stat(new_img3)

os.unlink(new_img1)
os.unlink(new_hdr1)
os.unlink(new_img2)
Expand All @@ -183,6 +169,55 @@ def test_linkchain():
os.unlink(orig_hdr)


def test_recopy():
# Re-copying with the same parameters on an unchanged file should be
# idempotent
#
# Test for copying from regular files and symlinks
orig_img, orig_hdr = _temp_analyze_files()
pth, fname = os.path.split(orig_img)
img_link = os.path.join(pth, 'imglink.img')
hdr_link = os.path.join(pth, 'imglink.hdr')
new_img = os.path.join(pth, 'newfile.img')
new_hdr = os.path.join(pth, 'newfile.hdr')
copyfile(orig_img, img_link)
for copy in (True, False):
for use_hardlink in (True, False):
for hashmethod in ('timestamp', 'content'):
kwargs = {'copy': copy, 'use_hardlink': use_hardlink,
'hashmethod': hashmethod}
# Copying does not preserve the original file's timestamp, so
# we may delete and re-copy, if the test is slower than a clock
# tick
if copy and not use_hardlink and hashmethod == 'timestamp':
continue
copyfile(orig_img, new_img, **kwargs)
img_stat = os.stat(new_img)
hdr_stat = os.stat(new_hdr)
copyfile(orig_img, new_img, **kwargs)
err_msg = "Regular - OS: {}; Copy: {}; Hardlink: {}".format(
os.name, copy, use_hardlink)
yield assert_equal, img_stat, os.stat(new_img), err_msg
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
os.unlink(new_img)
os.unlink(new_hdr)

copyfile(img_link, new_img, **kwargs)
img_stat = os.stat(new_img)
hdr_stat = os.stat(new_hdr)
copyfile(img_link, new_img, **kwargs)
err_msg = "Symlink - OS: {}; Copy: {}; Hardlink: {}".format(
os.name, copy, use_hardlink)
yield assert_equal, img_stat, os.stat(new_img), err_msg
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
os.unlink(new_img)
os.unlink(new_hdr)
os.unlink(img_link)
os.unlink(hdr_link)
os.unlink(orig_img)
os.unlink(orig_hdr)


def test_copyfallback():
if os.name is not 'posix':
return
Expand Down