Skip to content

Commit 05d6a05

Browse files
committed
TEST: Ignore atime, wait for clock ticks to make test deterministic
1 parent 4ab5554 commit 05d6a05

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

nipype/utils/tests/test_filemanip.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from builtins import open
66

77
import os
8+
import time
89
from tempfile import mkstemp, mkdtemp
910
import warnings
1011

@@ -20,6 +21,17 @@
2021
import numpy as np
2122

2223

24+
def _wait_for_tick(tic=None):
25+
tic = time.time() if tic is None else tic
26+
toc = time.time()
27+
while int(tic) == int(toc):
28+
toc = time.time()
29+
30+
31+
def _ignore_atime(stat):
32+
return stat[:7] + stat[8:]
33+
34+
2335
def test_split_filename():
2436
res = split_filename('foo.nii')
2537
yield assert_equal, res, ('', 'foo', '.nii')
@@ -193,27 +205,37 @@ def test_recopy():
193205
# tick
194206
if copy and not use_hardlink and hashmethod == 'timestamp':
195207
continue
208+
209+
tic = time.time()
196210
copyfile(orig_img, new_img, **kwargs)
197-
img_stat = os.stat(new_img)
198-
hdr_stat = os.stat(new_hdr)
211+
img_stat = _ignore_atime(os.stat(new_img))
212+
hdr_stat = _ignore_atime(os.stat(new_hdr))
213+
_wait_for_tick(tic)
199214
copyfile(orig_img, new_img, **kwargs)
200215
err_msg = "Regular - OS: {}; Copy: {}; Hardlink: {}".format(
201216
os.name, copy, use_hardlink)
202-
yield assert_equal, img_stat, os.stat(new_img), err_msg
203-
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
217+
yield (assert_equal, img_stat, _ignore_atime(os.stat(new_img)),
218+
err_msg)
219+
yield (assert_equal, hdr_stat, _ignore_atime(os.stat(new_hdr)),
220+
err_msg)
204221
os.unlink(new_img)
205222
os.unlink(new_hdr)
206223

224+
tic = time.time()
207225
copyfile(img_link, new_img, **kwargs)
208-
img_stat = os.stat(new_img)
209-
hdr_stat = os.stat(new_hdr)
226+
img_stat = _ignore_atime(os.stat(new_img))
227+
hdr_stat = _ignore_atime(os.stat(new_hdr))
228+
_wait_for_tick(tic)
210229
copyfile(img_link, new_img, **kwargs)
211230
err_msg = "Symlink - OS: {}; Copy: {}; Hardlink: {}".format(
212231
os.name, copy, use_hardlink)
213-
yield assert_equal, img_stat, os.stat(new_img), err_msg
214-
yield assert_equal, hdr_stat, os.stat(new_hdr), err_msg
232+
yield (assert_equal, img_stat, _ignore_atime(os.stat(new_img)),
233+
err_msg)
234+
yield (assert_equal, hdr_stat, _ignore_atime(os.stat(new_hdr)),
235+
err_msg)
215236
os.unlink(new_img)
216237
os.unlink(new_hdr)
238+
217239
os.unlink(img_link)
218240
os.unlink(hdr_link)
219241
os.unlink(orig_img)

0 commit comments

Comments
 (0)