Skip to content

Commit 40b2cb8

Browse files
committed
TST: Check that we don't hardlink to symlinks
1 parent beec4be commit 40b2cb8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

nipype/utils/tests/test_filemanip.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,41 @@ def test_copyfiles():
132132
os.unlink(new_hdr2)
133133

134134

135+
def test_linkchain():
136+
if os.name is not 'posix':
137+
return
138+
orig_img, orig_hdr = _temp_analyze_files()
139+
pth, fname = os.path.split(orig_img)
140+
new_img1 = os.path.join(pth, 'newfile1.img')
141+
new_hdr1 = os.path.join(pth, 'newfile1.hdr')
142+
new_img2 = os.path.join(pth, 'newfile2.img')
143+
new_hdr2 = os.path.join(pth, 'newfile2.hdr')
144+
new_img3 = os.path.join(pth, 'newfile3.img')
145+
new_hdr3 = os.path.join(pth, 'newfile3.hdr')
146+
copyfile(orig_img, new_img1)
147+
yield assert_true, os.path.islink(new_img1)
148+
yield assert_true, os.path.islink(new_hdr1)
149+
copyfile(new_img1, new_img2, copy=True)
150+
yield assert_false, os.path.islink(new_img2)
151+
yield assert_false, os.path.islink(new_hdr2)
152+
yield assert_false, os.path.samefile(orig_img, new_img2)
153+
yield assert_false, os.path.samefile(orig_hdr, new_hdr2)
154+
copyfile(new_img1, new_img3, copy=True, use_hardlink=True)
155+
yield assert_false, os.path.islink(new_img3)
156+
yield assert_false, os.path.islink(new_hdr3)
157+
yield assert_true, os.path.samefile(orig_img, new_img3)
158+
yield assert_true, os.path.samefile(orig_hdr, new_hdr3)
159+
os.unlink(new_img1)
160+
os.unlink(new_hdr1)
161+
os.unlink(new_img2)
162+
os.unlink(new_hdr2)
163+
os.unlink(new_img3)
164+
os.unlink(new_hdr3)
165+
# final cleanup
166+
os.unlink(orig_img)
167+
os.unlink(orig_hdr)
168+
169+
135170
def test_filename_to_list():
136171
x = filename_to_list('foo.nii')
137172
yield assert_equal, x, ['foo.nii']

0 commit comments

Comments
 (0)