Skip to content

Commit d1466cc

Browse files
[3.13] gh-154427: Check the access time in UtimeTests only if it is stored (GH-154428) (GH-154439)
HAMMER2 on DragonFly BSD does not store the access time and os.stat() returns the modification time instead. Probe the file system, like it is already done for the timestamp resolution. (cherry picked from commit 6f8f97f) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 9d4e852 commit d1466cc

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Lib/test/test_os.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,18 @@ def support_subsecond(self, filename):
791791
or (st.st_mtime != st[8])
792792
or (st.st_ctime != st[9]))
793793

794+
def support_atime(self, filename):
795+
# Heuristic to check if the filesystem stores the access time.
796+
# Use whole seconds, to not depend on the timestamp resolution.
797+
os.utime(filename, (1, 2))
798+
return os.stat(filename).st_atime == 1
799+
794800
def _test_utime(self, set_time, filename=None):
795801
if not filename:
796802
filename = self.fname
797803

798804
support_subsecond = self.support_subsecond(filename)
805+
support_atime = self.support_atime(filename)
799806
if support_subsecond:
800807
# Timestamp with a resolution of 1 microsecond (10^-6).
801808
#
@@ -814,12 +821,15 @@ def _test_utime(self, set_time, filename=None):
814821
st = os.stat(filename)
815822

816823
if support_subsecond:
817-
self.assertAlmostEqual(st.st_atime, atime_ns * 1e-9, delta=1e-6)
824+
if support_atime:
825+
self.assertAlmostEqual(st.st_atime, atime_ns * 1e-9, delta=1e-6)
818826
self.assertAlmostEqual(st.st_mtime, mtime_ns * 1e-9, delta=1e-6)
819827
else:
820-
self.assertEqual(st.st_atime, atime_ns * 1e-9)
828+
if support_atime:
829+
self.assertEqual(st.st_atime, atime_ns * 1e-9)
821830
self.assertEqual(st.st_mtime, mtime_ns * 1e-9)
822-
self.assertEqual(st.st_atime_ns, atime_ns)
831+
if support_atime:
832+
self.assertEqual(st.st_atime_ns, atime_ns)
823833
self.assertEqual(st.st_mtime_ns, mtime_ns)
824834

825835
def test_utime(self):

0 commit comments

Comments
 (0)