From 23cfddc9e9a9789ef15cd551dd6c87abda0f4947 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Thu, 18 Aug 2016 16:47:13 -0400 Subject: [PATCH 1/3] TEST: Separate recopy test, err_msg for debugging --- nipype/utils/tests/test_filemanip.py | 55 +++++++++++++++++++++------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/nipype/utils/tests/test_filemanip.py b/nipype/utils/tests/test_filemanip.py index 98370aac64..8c72e03525 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,47 @@ 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): + copyfile(orig_img, new_img, copy=copy, use_hardlink=use_hardlink) + img_stat = os.stat(new_img) + hdr_stat = os.stat(new_hdr) + copyfile(orig_img, new_img, copy=copy, use_hardlink=use_hardlink) + 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, copy=copy, use_hardlink=use_hardlink) + img_stat = os.stat(new_img) + hdr_stat = os.stat(new_hdr) + copyfile(img_link, new_img, copy=copy, use_hardlink=use_hardlink) + 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 From be84130fc1f2765b2f52ec1a934f1dac9b3a26df Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Fri, 19 Aug 2016 08:49:32 -0400 Subject: [PATCH 2/3] Update changelog --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 196f464a54ea28d6ea4ff44c9370c69c815448c6 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Fri, 19 Aug 2016 13:16:47 -0400 Subject: [PATCH 3/3] TEST: Test hashmethods --- nipype/utils/tests/test_filemanip.py | 50 ++++++++++++++++------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/nipype/utils/tests/test_filemanip.py b/nipype/utils/tests/test_filemanip.py index 8c72e03525..8b81e03d4d 100644 --- a/nipype/utils/tests/test_filemanip.py +++ b/nipype/utils/tests/test_filemanip.py @@ -183,27 +183,35 @@ def test_recopy(): copyfile(orig_img, img_link) for copy in (True, False): for use_hardlink in (True, False): - copyfile(orig_img, new_img, copy=copy, use_hardlink=use_hardlink) - img_stat = os.stat(new_img) - hdr_stat = os.stat(new_hdr) - copyfile(orig_img, new_img, copy=copy, use_hardlink=use_hardlink) - 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, copy=copy, use_hardlink=use_hardlink) - img_stat = os.stat(new_img) - hdr_stat = os.stat(new_hdr) - copyfile(img_link, new_img, copy=copy, use_hardlink=use_hardlink) - 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) + 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)