Mercurial > hg
comparison tests/test-filecache.py @ 36781:ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
The latter is floating point by default, and we've been doing
os.stat_float_times(False). Unfortunately, os.stat_float_times was
removed between Python 3.7.0a1 and 3.7.0b2, so we have to stop using
it.
Differential Revision: https://phab.mercurial-scm.org/D2696
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 05 Mar 2018 12:30:20 -0500 |
parents | daa5f47558cf |
children | b3ffa2faae04 |
comparison
equal
deleted
inserted
replaced
36780:f3c314020beb | 36781:ffa3026d4196 |
---|---|
1 from __future__ import absolute_import, print_function | 1 from __future__ import absolute_import, print_function |
2 import os | 2 import os |
3 import stat | |
3 import subprocess | 4 import subprocess |
4 import sys | 5 import sys |
5 | 6 |
6 if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], | 7 if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], |
7 'cacheable']): | 8 'cacheable']): |
198 fp = open(filename, 'w') | 199 fp = open(filename, 'w') |
199 fp.write('FOO') | 200 fp.write('FOO') |
200 fp.close() | 201 fp.close() |
201 | 202 |
202 oldstat = os.stat(filename) | 203 oldstat = os.stat(filename) |
203 if oldstat.st_ctime != oldstat.st_mtime: | 204 if oldstat[stat.ST_CTIME] != oldstat[stat.ST_MTIME]: |
204 # subsequent changing never causes ambiguity | 205 # subsequent changing never causes ambiguity |
205 continue | 206 continue |
206 | 207 |
207 repetition = 3 | 208 repetition = 3 |
208 | 209 |
217 # implicit closing by "with" statement | 218 # implicit closing by "with" statement |
218 with vfsmod.checkambigatclosing(open(filename, 'a')) as fp: | 219 with vfsmod.checkambigatclosing(open(filename, 'a')) as fp: |
219 fp.write('BAR') | 220 fp.write('BAR') |
220 | 221 |
221 newstat = os.stat(filename) | 222 newstat = os.stat(filename) |
222 if oldstat.st_ctime != newstat.st_ctime: | 223 if oldstat[stat.ST_CTIME] != newstat[stat.ST_CTIME]: |
223 # timestamp ambiguity was naturally avoided while repetition | 224 # timestamp ambiguity was naturally avoided while repetition |
224 continue | 225 continue |
225 | 226 |
226 # st_mtime should be advanced "repetition * 2" times, because | 227 # st_mtime should be advanced "repetition * 2" times, because |
227 # all changes occurred at same time (in sec) | 228 # all changes occurred at same time (in sec) |
228 expected = (oldstat.st_mtime + repetition * 2) & 0x7fffffff | 229 expected = (oldstat[stat.ST_MTIME] + repetition * 2) & 0x7fffffff |
229 if newstat.st_mtime != expected: | 230 if newstat[stat.ST_MTIME] != expected: |
230 print("'newstat.st_mtime %s is not %s (as %s + %s * 2)" % | 231 print("'newstat[stat.ST_MTIME] %s is not %s (as %s + %s * 2)" % |
231 (newstat.st_mtime, expected, oldstat.st_mtime, repetition)) | 232 (newstat[stat.ST_MTIME], expected, |
233 oldstat[stat.ST_MTIME], repetition)) | |
232 | 234 |
233 # no more examination is needed regardless of result | 235 # no more examination is needed regardless of result |
234 break | 236 break |
235 else: | 237 else: |
236 # This platform seems too slow to examine anti-ambiguity | 238 # This platform seems too slow to examine anti-ambiguity |