|
5 | 5 | from builtins import open
|
6 | 6 |
|
7 | 7 | import os
|
| 8 | +import time |
8 | 9 | from tempfile import mkstemp, mkdtemp
|
9 | 10 | import warnings
|
10 | 11 |
|
|
20 | 21 | import numpy as np
|
21 | 22 |
|
22 | 23 |
|
| 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 | + |
23 | 35 | def test_split_filename():
|
24 | 36 | res = split_filename('foo.nii')
|
25 | 37 | yield assert_equal, res, ('', 'foo', '.nii')
|
@@ -193,27 +205,37 @@ def test_recopy():
|
193 | 205 | # tick
|
194 | 206 | if copy and not use_hardlink and hashmethod == 'timestamp':
|
195 | 207 | continue
|
| 208 | + |
| 209 | + tic = time.time() |
196 | 210 | 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) |
199 | 214 | copyfile(orig_img, new_img, **kwargs)
|
200 | 215 | err_msg = "Regular - OS: {}; Copy: {}; Hardlink: {}".format(
|
201 | 216 | 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) |
204 | 221 | os.unlink(new_img)
|
205 | 222 | os.unlink(new_hdr)
|
206 | 223 |
|
| 224 | + tic = time.time() |
207 | 225 | 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) |
210 | 229 | copyfile(img_link, new_img, **kwargs)
|
211 | 230 | err_msg = "Symlink - OS: {}; Copy: {}; Hardlink: {}".format(
|
212 | 231 | 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) |
215 | 236 | os.unlink(new_img)
|
216 | 237 | os.unlink(new_hdr)
|
| 238 | + |
217 | 239 | os.unlink(img_link)
|
218 | 240 | os.unlink(hdr_link)
|
219 | 241 | os.unlink(orig_img)
|
|
0 commit comments