Skip to content

Commit 9792641

Browse files
committed
Merge remote-tracking branch 'effigies/fix_linkchain_test' into fix/Py3UseBuiltinOpen
2 parents e682455 + 196f464 commit 9792641

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

nipype/utils/tests/test_filemanip.py

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -170,47 +170,53 @@ def test_linkchain():
170170
os.unlink(orig_img)
171171
os.unlink(orig_hdr)
172172

173-
174-
# def test_recopy():
175-
# # Re-copying with the same parameters on an unchanged file should be
176-
# # idempotent
177-
# #
178-
# # Test for copying from regular files and symlinks
179-
# orig_img, orig_hdr = _temp_analyze_files()
180-
# pth, fname = os.path.split(orig_img)
181-
# img_link = os.path.join(pth, 'imglink.img')
182-
# hdr_link = os.path.join(pth, 'imglink.hdr')
183-
# new_img = os.path.join(pth, 'newfile.img')
184-
# new_hdr = os.path.join(pth, 'newfile.hdr')
185-
# copyfile(orig_img, img_link)
186-
# for copy in (True, False):
187-
# for use_hardlink in (True, False):
188-
# copyfile(orig_img, new_img, copy=copy, use_hardlink=use_hardlink)
189-
# img_stat = os.stat(new_img)
190-
# hdr_stat = os.stat(new_hdr)
191-
# copyfile(orig_img, new_img, copy=copy, use_hardlink=use_hardlink)
192-
# err_msg = "Regular - OS: {}; Copy: {}; Hardlink: {}".format(
193-
# os.name, copy, use_hardlink)
194-
# yield assert_equal, img_stat, os.stat(new_img), err_msg
195-
# yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
196-
# os.unlink(new_img)
197-
# os.unlink(new_hdr)
198-
#
199-
# copyfile(img_link, new_img, copy=copy, use_hardlink=use_hardlink)
200-
# img_stat = os.stat(new_img)
201-
# hdr_stat = os.stat(new_hdr)
202-
# copyfile(img_link, new_img, copy=copy, use_hardlink=use_hardlink)
203-
# err_msg = "Symlink - OS: {}; Copy: {}; Hardlink: {}".format(
204-
# os.name, copy, use_hardlink)
205-
# yield assert_equal, img_stat, os.stat(new_img), err_msg
206-
# yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
207-
# os.unlink(new_img)
208-
# os.unlink(new_hdr)
209-
# os.unlink(img_link)
210-
# os.unlink(hdr_link)
211-
# os.unlink(orig_img)
212-
# os.unlink(orig_hdr)
213-
173+
def test_recopy():
174+
# Re-copying with the same parameters on an unchanged file should be
175+
# idempotent
176+
#
177+
# Test for copying from regular files and symlinks
178+
orig_img, orig_hdr = _temp_analyze_files()
179+
pth, fname = os.path.split(orig_img)
180+
img_link = os.path.join(pth, 'imglink.img')
181+
hdr_link = os.path.join(pth, 'imglink.hdr')
182+
new_img = os.path.join(pth, 'newfile.img')
183+
new_hdr = os.path.join(pth, 'newfile.hdr')
184+
copyfile(orig_img, img_link)
185+
for copy in (True, False):
186+
for use_hardlink in (True, False):
187+
for hashmethod in ('timestamp', 'content'):
188+
kwargs = {'copy': copy, 'use_hardlink': use_hardlink,
189+
'hashmethod': hashmethod}
190+
# Copying does not preserve the original file's timestamp, so
191+
# we may delete and re-copy, if the test is slower than a clock
192+
# tick
193+
if copy and not use_hardlink and hashmethod == 'timestamp':
194+
continue
195+
copyfile(orig_img, new_img, **kwargs)
196+
img_stat = os.stat(new_img)
197+
hdr_stat = os.stat(new_hdr)
198+
copyfile(orig_img, new_img, **kwargs)
199+
err_msg = "Regular - OS: {}; Copy: {}; Hardlink: {}".format(
200+
os.name, copy, use_hardlink)
201+
yield assert_equal, img_stat, os.stat(new_img), err_msg
202+
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
203+
os.unlink(new_img)
204+
os.unlink(new_hdr)
205+
206+
copyfile(img_link, new_img, **kwargs)
207+
img_stat = os.stat(new_img)
208+
hdr_stat = os.stat(new_hdr)
209+
copyfile(img_link, new_img, **kwargs)
210+
err_msg = "Symlink - OS: {}; Copy: {}; Hardlink: {}".format(
211+
os.name, copy, use_hardlink)
212+
yield assert_equal, img_stat, os.stat(new_img), err_msg
213+
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
214+
os.unlink(new_img)
215+
os.unlink(new_hdr)
216+
os.unlink(img_link)
217+
os.unlink(hdr_link)
218+
os.unlink(orig_img)
219+
os.unlink(orig_hdr)
214220

215221
def test_copyfallback():
216222
if os.name is not 'posix':

0 commit comments

Comments
 (0)