Skip to content

Commit 41f29e5

Browse files
authored
gh-127146: Some expected failures in Emscripten time tests (#127843)
Disables two tests in the test_time suite, and adjusts test_os to reflect precision limits in Emscripten.
1 parent c84928e commit 41f29e5

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Lib/test/test_os.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,14 +805,28 @@ def _test_utime(self, set_time, filename=None):
805805
set_time(filename, (atime_ns, mtime_ns))
806806
st = os.stat(filename)
807807

808-
if support_subsecond:
809-
self.assertAlmostEqual(st.st_atime, atime_ns * 1e-9, delta=1e-6)
810-
self.assertAlmostEqual(st.st_mtime, mtime_ns * 1e-9, delta=1e-6)
808+
if support.is_emscripten:
809+
# Emscripten timestamps are roundtripped through a 53 bit integer of
810+
# nanoseconds. If we want to represent ~50 years which is an 11
811+
# digits number of seconds:
812+
# 2*log10(60) + log10(24) + log10(365) + log10(60) + log10(50)
813+
# is about 11. Because 53 * log10(2) is about 16, we only have 5
814+
# digits worth of sub-second precision.
815+
# Some day it would be good to fix this upstream.
816+
delta=1e-5
817+
self.assertAlmostEqual(st.st_atime, atime_ns * 1e-9, delta=1e-5)
818+
self.assertAlmostEqual(st.st_mtime, mtime_ns * 1e-9, delta=1e-5)
819+
self.assertAlmostEqual(st.st_atime_ns, atime_ns, delta=1e9 * 1e-5)
820+
self.assertAlmostEqual(st.st_mtime_ns, mtime_ns, delta=1e9 * 1e-5)
811821
else:
812-
self.assertEqual(st.st_atime, atime_ns * 1e-9)
813-
self.assertEqual(st.st_mtime, mtime_ns * 1e-9)
814-
self.assertEqual(st.st_atime_ns, atime_ns)
815-
self.assertEqual(st.st_mtime_ns, mtime_ns)
822+
if support_subsecond:
823+
self.assertAlmostEqual(st.st_atime, atime_ns * 1e-9, delta=1e-6)
824+
self.assertAlmostEqual(st.st_mtime, mtime_ns * 1e-9, delta=1e-6)
825+
else:
826+
self.assertEqual(st.st_atime, atime_ns * 1e-9)
827+
self.assertEqual(st.st_mtime, mtime_ns * 1e-9)
828+
self.assertEqual(st.st_atime_ns, atime_ns)
829+
self.assertEqual(st.st_mtime_ns, mtime_ns)
816830

817831
def test_utime(self):
818832
def set_time(filename, ns):

Lib/test/test_time.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def test_clock_monotonic(self):
116116
'need time.pthread_getcpuclockid()')
117117
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
118118
'need time.clock_gettime()')
119+
@unittest.skipIf(support.is_emscripten, "Fails to find clock")
119120
def test_pthread_getcpuclockid(self):
120121
clk_id = time.pthread_getcpuclockid(threading.get_ident())
121122
self.assertTrue(type(clk_id) is int)
@@ -539,6 +540,9 @@ def test_perf_counter(self):
539540
@unittest.skipIf(
540541
support.is_wasi, "process_time not available on WASI"
541542
)
543+
@unittest.skipIf(
544+
support.is_emscripten, "process_time present but doesn't exclude sleep"
545+
)
542546
def test_process_time(self):
543547
# process_time() should not include time spend during a sleep
544548
start = time.process_time()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy