Skip to content

Commit abdb04f

Browse files
authored
Merge pull request RustPython#3671 from fanninpm/test-time-3.10
Update test_time.py to CPython 3.10
2 parents 00e461e + 498121b commit abdb04f

File tree

1 file changed

+59
-21
lines changed

1 file changed

+59
-21
lines changed

Lib/test/test_time.py

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from test import support
2+
from test.support import warnings_helper
23
import decimal
34
import enum
45
import locale
@@ -14,7 +15,7 @@
1415
except ImportError:
1516
_testcapi = None
1617

17-
from test.support import skip_if_buggy_ucrt_strfptime, warnings_helper
18+
from test.support import skip_if_buggy_ucrt_strfptime
1819

1920
# Max year is only limited by the size of C int.
2021
SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4
@@ -114,12 +115,13 @@ def test_pthread_getcpuclockid(self):
114115
clk_id = time.pthread_getcpuclockid(threading.get_ident())
115116
self.assertTrue(type(clk_id) is int)
116117
# when in 32-bit mode AIX only returns the predefined constant
117-
if not platform.system() == "AIX":
118-
self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
119-
elif (sys.maxsize.bit_length() > 32):
120-
self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
121-
else:
118+
if platform.system() == "AIX" and (sys.maxsize.bit_length() <= 32):
119+
self.assertEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
120+
# Solaris returns CLOCK_THREAD_CPUTIME_ID when current thread is given
121+
elif sys.platform.startswith("sunos"):
122122
self.assertEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
123+
else:
124+
self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
123125
t1 = time.clock_gettime(clk_id)
124126
t2 = time.clock_gettime(clk_id)
125127
self.assertLessEqual(t1, t2)
@@ -460,8 +462,8 @@ def test_mktime(self):
460462
@unittest.skipUnless(platform.libc_ver()[0] != 'glibc',
461463
"disabled because of a bug in glibc. Issue #13309")
462464
def test_mktime_error(self):
463-
# It may not be possible to reliably make mktime return error
464-
# on all platfom. This will make sure that no other exception
465+
# It may not be possible to reliably make mktime return an error
466+
# on all platforms. This will make sure that no other exception
465467
# than OverflowError is raised for an extreme value.
466468
tt = time.gmtime(self.t)
467469
tzname = time.strftime('%Z', tt)
@@ -570,20 +572,26 @@ def test_localtime_failure(self):
570572
self.assertRaises(ValueError, time.ctime, float("nan"))
571573

572574
def test_get_clock_info(self):
573-
clocks = ['monotonic', 'perf_counter', 'process_time', 'time']
575+
clocks = [
576+
'monotonic',
577+
'perf_counter',
578+
'process_time',
579+
'time',
580+
'thread_time',
581+
]
574582

575583
for name in clocks:
576-
info = time.get_clock_info(name)
577-
578-
#self.assertIsInstance(info, dict)
579-
self.assertIsInstance(info.implementation, str)
580-
self.assertNotEqual(info.implementation, '')
581-
self.assertIsInstance(info.monotonic, bool)
582-
self.assertIsInstance(info.resolution, float)
583-
# 0.0 < resolution <= 1.0
584-
self.assertGreater(info.resolution, 0.0)
585-
self.assertLessEqual(info.resolution, 1.0)
586-
self.assertIsInstance(info.adjustable, bool)
584+
with self.subTest(name=name):
585+
info = time.get_clock_info(name)
586+
587+
self.assertIsInstance(info.implementation, str)
588+
self.assertNotEqual(info.implementation, '')
589+
self.assertIsInstance(info.monotonic, bool)
590+
self.assertIsInstance(info.resolution, float)
591+
# 0.0 < resolution <= 1.0
592+
self.assertGreater(info.resolution, 0.0)
593+
self.assertLessEqual(info.resolution, 1.0)
594+
self.assertIsInstance(info.adjustable, bool)
587595

588596
self.assertRaises(ValueError, time.get_clock_info, 'xxx')
589597

@@ -863,7 +871,7 @@ def convert_values(ns_timestamps):
863871
try:
864872
result = pytime_converter(value, time_rnd)
865873
expected = expected_func(value)
866-
except Exception as exc:
874+
except Exception:
867875
self.fail("Error on timestamp conversion: %s" % debug_info)
868876
self.assertEqual(result,
869877
expected,
@@ -1078,6 +1086,36 @@ def test_object_to_timespec(self):
10781086
with self.assertRaises(ValueError):
10791087
pytime_object_to_timespec(float('nan'), time_rnd)
10801088

1089+
@unittest.skipUnless(sys.platform == "darwin", "test weak linking on macOS")
1090+
class TestTimeWeaklinking(unittest.TestCase):
1091+
# These test cases verify that weak linking support on macOS works
1092+
# as expected. These cases only test new behaviour introduced by weak linking,
1093+
# regular behaviour is tested by the normal test cases.
1094+
#
1095+
# See the section on Weak Linking in Mac/README.txt for more information.
1096+
def test_clock_functions(self):
1097+
import sysconfig
1098+
import platform
1099+
1100+
config_vars = sysconfig.get_config_vars()
1101+
var_name = "HAVE_CLOCK_GETTIME"
1102+
if var_name not in config_vars or not config_vars[var_name]:
1103+
raise unittest.SkipTest(f"{var_name} is not available")
1104+
1105+
mac_ver = tuple(int(x) for x in platform.mac_ver()[0].split("."))
1106+
1107+
clock_names = [
1108+
"CLOCK_MONOTONIC", "clock_gettime", "clock_gettime_ns", "clock_settime",
1109+
"clock_settime_ns", "clock_getres"]
1110+
1111+
if mac_ver >= (10, 12):
1112+
for name in clock_names:
1113+
self.assertTrue(hasattr(time, name), f"time.{name} is not available")
1114+
1115+
else:
1116+
for name in clock_names:
1117+
self.assertFalse(hasattr(time, name), f"time.{name} is available")
1118+
10811119

10821120
if __name__ == "__main__":
10831121
unittest.main()

0 commit comments

Comments
 (0)