mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-83714: Fix os.statx() tests on tmpfs: st_birthtime can be None (#140407)
This commit is contained in:
parent
5c41666ec4
commit
fe4b60208e
1 changed files with 11 additions and 6 deletions
|
|
@ -648,6 +648,7 @@ def check_timestamp_agreement(self, result, names):
|
||||||
# Make sure that the st_?time and st_?time_ns fields roughly agree
|
# Make sure that the st_?time and st_?time_ns fields roughly agree
|
||||||
# (they should always agree up to around tens-of-microseconds)
|
# (they should always agree up to around tens-of-microseconds)
|
||||||
for name in names:
|
for name in names:
|
||||||
|
with self.subTest(name=name):
|
||||||
floaty = int(getattr(result, name) * 100_000)
|
floaty = int(getattr(result, name) * 100_000)
|
||||||
nanosecondy = getattr(result, name + "_ns") // 10_000
|
nanosecondy = getattr(result, name + "_ns") // 10_000
|
||||||
self.assertAlmostEqual(floaty, nanosecondy, delta=2, msg=name)
|
self.assertAlmostEqual(floaty, nanosecondy, delta=2, msg=name)
|
||||||
|
|
@ -741,14 +742,19 @@ def test_stat_result_pickle(self):
|
||||||
unpickled = pickle.loads(p)
|
unpickled = pickle.loads(p)
|
||||||
self.assertEqual(result, unpickled)
|
self.assertEqual(result, unpickled)
|
||||||
|
|
||||||
def check_statx_attributes(self, fname):
|
def check_statx_attributes(self, filename):
|
||||||
maximal_mask = 0
|
maximal_mask = 0
|
||||||
for name in dir(os):
|
for name in dir(os):
|
||||||
if name.startswith('STATX_'):
|
if name.startswith('STATX_'):
|
||||||
maximal_mask |= getattr(os, name)
|
maximal_mask |= getattr(os, name)
|
||||||
result = os.statx(self.fname, maximal_mask)
|
result = os.statx(filename, maximal_mask)
|
||||||
|
basic_result = os.stat(filename)
|
||||||
|
|
||||||
time_attributes = ('st_atime', 'st_mtime', 'st_ctime', 'st_birthtime')
|
time_attributes = ('st_atime', 'st_mtime', 'st_ctime', 'st_birthtime')
|
||||||
|
# gh-83714: st_birthtime can be None on tmpfs even if STATX_BTIME mask
|
||||||
|
# is used
|
||||||
|
time_attributes = [name for name in time_attributes
|
||||||
|
if getattr(result, name) is not None]
|
||||||
self.check_timestamp_agreement(result, time_attributes)
|
self.check_timestamp_agreement(result, time_attributes)
|
||||||
|
|
||||||
# Check that valid attributes match os.stat.
|
# Check that valid attributes match os.stat.
|
||||||
|
|
@ -773,7 +779,6 @@ def check_statx_attributes(self, fname):
|
||||||
('st_rdev', 0),
|
('st_rdev', 0),
|
||||||
('st_dev', 0),
|
('st_dev', 0),
|
||||||
)
|
)
|
||||||
basic_result = os.stat(self.fname)
|
|
||||||
for name, bits in requirements:
|
for name, bits in requirements:
|
||||||
if result.stx_mask & bits == bits and hasattr(basic_result, name):
|
if result.stx_mask & bits == bits and hasattr(basic_result, name):
|
||||||
x = getattr(result, name)
|
x = getattr(result, name)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue