diff --git a/CHANGES b/CHANGES index 1868b5de9b..05a05873a3 100644 --- a/CHANGES +++ b/CHANGES @@ -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) diff --git a/nipype/utils/tests/test_filemanip.py b/nipype/utils/tests/test_filemanip.py index 98370aac64..8b81e03d4d 100644 --- a/nipype/utils/tests/test_filemanip.py +++ b/nipype/utils/tests/test_filemanip.py @@ -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) @@ -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