Mercurial > hg-stable
comparison tests/test-atomictempfile.py @ 36789: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 | a007db19dc4d |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
36788:f3c314020beb | 36789:ffa3026d4196 |
---|---|
1 from __future__ import absolute_import | 1 from __future__ import absolute_import |
2 | 2 |
3 import glob | 3 import glob |
4 import os | 4 import os |
5 import shutil | 5 import shutil |
6 import stat | |
6 import tempfile | 7 import tempfile |
7 import unittest | 8 import unittest |
8 | 9 |
9 from mercurial import ( | 10 from mercurial import ( |
10 pycompat, | 11 pycompat, |
64 # try some times, because reproduction of ambiguity depends on | 65 # try some times, because reproduction of ambiguity depends on |
65 # "filesystem time" | 66 # "filesystem time" |
66 for i in xrange(5): | 67 for i in xrange(5): |
67 atomicwrite(False) | 68 atomicwrite(False) |
68 oldstat = os.stat(self._filename) | 69 oldstat = os.stat(self._filename) |
69 if oldstat.st_ctime != oldstat.st_mtime: | 70 if oldstat[stat.ST_CTIME] != oldstat[stat.ST_MTIME]: |
70 # subsequent changing never causes ambiguity | 71 # subsequent changing never causes ambiguity |
71 continue | 72 continue |
72 | 73 |
73 repetition = 3 | 74 repetition = 3 |
74 | 75 |
75 # repeat atomic write with checkambig=True, to examine | 76 # repeat atomic write with checkambig=True, to examine |
76 # whether st_mtime is advanced multiple times as expected | 77 # whether st_mtime is advanced multiple times as expected |
77 for j in xrange(repetition): | 78 for j in xrange(repetition): |
78 atomicwrite(True) | 79 atomicwrite(True) |
79 newstat = os.stat(self._filename) | 80 newstat = os.stat(self._filename) |
80 if oldstat.st_ctime != newstat.st_ctime: | 81 if oldstat[stat.ST_CTIME] != newstat[stat.ST_CTIME]: |
81 # timestamp ambiguity was naturally avoided while repetition | 82 # timestamp ambiguity was naturally avoided while repetition |
82 continue | 83 continue |
83 | 84 |
84 # st_mtime should be advanced "repetition" times, because | 85 # st_mtime should be advanced "repetition" times, because |
85 # all atomicwrite() occurred at same time (in sec) | 86 # all atomicwrite() occurred at same time (in sec) |
86 self.assertTrue(newstat.st_mtime == | 87 oldtime = (oldstat[stat.ST_MTIME] + repetition) & 0x7fffffff |
87 ((oldstat.st_mtime + repetition) & 0x7fffffff)) | 88 self.assertTrue(newstat[stat.ST_MTIME] == oldtime) |
88 # no more examination is needed, if assumption above is true | 89 # no more examination is needed, if assumption above is true |
89 break | 90 break |
90 else: | 91 else: |
91 # This platform seems too slow to examine anti-ambiguity | 92 # This platform seems too slow to examine anti-ambiguity |
92 # of file timestamp (or test happened to be executed at | 93 # of file timestamp (or test happened to be executed at |