Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe4b602

Browse filesBrowse files
authored
gh-83714: Fix os.statx() tests on tmpfs: st_birthtime can be None (#140407)
1 parent 5c41666 commit fe4b602
Copy full SHA for fe4b602

1 file changed

+11-6Lines changed: 11 additions & 6 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/test/test_os/test_os.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_os/test_os.py
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,10 @@ def check_timestamp_agreement(self, result, names):
648648
# Make sure that the st_?time and st_?time_ns fields roughly agree
649649
# (they should always agree up to around tens-of-microseconds)
650650
for name in names:
651-
floaty = int(getattr(result, name) * 100_000)
652-
nanosecondy = getattr(result, name + "_ns") // 10_000
653-
self.assertAlmostEqual(floaty, nanosecondy, delta=2, msg=name)
651+
with self.subTest(name=name):
652+
floaty = int(getattr(result, name) * 100_000)
653+
nanosecondy = getattr(result, name + "_ns") // 10_000
654+
self.assertAlmostEqual(floaty, nanosecondy, delta=2, msg=name)
654655

655656
def check_stat_attributes(self, fname):
656657
result = os.stat(fname)
@@ -741,14 +742,19 @@ def test_stat_result_pickle(self):
741742
unpickled = pickle.loads(p)
742743
self.assertEqual(result, unpickled)
743744

744-
def check_statx_attributes(self, fname):
745+
def check_statx_attributes(self, filename):
745746
maximal_mask = 0
746747
for name in dir(os):
747748
if name.startswith('STATX_'):
748749
maximal_mask |= getattr(os, name)
749-
result = os.statx(self.fname, maximal_mask)
750+
result = os.statx(filename, maximal_mask)
751+
basic_result = os.stat(filename)
750752

751753
time_attributes = ('st_atime', 'st_mtime', 'st_ctime', 'st_birthtime')
754+
# gh-83714: st_birthtime can be None on tmpfs even if STATX_BTIME mask
755+
# is used
756+
time_attributes = [name for name in time_attributes
757+
if getattr(result, name) is not None]
752758
self.check_timestamp_agreement(result, time_attributes)
753759

754760
# Check that valid attributes match os.stat.
@@ -773,7 +779,6 @@ def check_statx_attributes(self, fname):
773779
('st_rdev', 0),
774780
('st_dev', 0),
775781
)
776-
basic_result = os.stat(self.fname)
777782
for name, bits in requirements:
778783
if result.stx_mask & bits == bits and hasattr(basic_result, name):
779784
x = getattr(result, name)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.