mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-31784: Implement PEP 564: add time.time_ns() (#3989)
Add new time functions: * time.clock_gettime_ns() * time.clock_settime_ns() * time.monotonic_ns() * time.perf_counter_ns() * time.process_time_ns() * time.time_ns() Add new _PyTime functions: * _PyTime_FromTimespec() * _PyTime_FromNanosecondsObject() * _PyTime_FromTimeval() Other changes: * Add also os.times() tests to test_os. * pytime_fromtimeval() and pytime_fromtimeval() now return _PyTime_MAX or _PyTime_MIN on overflow, rather than undefined behaviour * _PyTime_FromNanoseconds() parameter type changes from long long to _PyTime_t
This commit is contained in:
parent
e314853d57
commit
c29b585fd4
9 changed files with 593 additions and 175 deletions
|
@ -3549,6 +3549,23 @@ class TestPEP519(unittest.TestCase):
|
|||
self.assertRaises(ZeroDivisionError, self.fspath,
|
||||
_PathLike(ZeroDivisionError()))
|
||||
|
||||
|
||||
class TimesTests(unittest.TestCase):
|
||||
def test_times(self):
|
||||
times = os.times()
|
||||
self.assertIsInstance(times, os.times_result)
|
||||
|
||||
for field in ('user', 'system', 'children_user', 'children_system',
|
||||
'elapsed'):
|
||||
value = getattr(times, field)
|
||||
self.assertIsInstance(value, float)
|
||||
|
||||
if os.name == 'nt':
|
||||
self.assertEqual(times.children_user, 0)
|
||||
self.assertEqual(times.children_system, 0)
|
||||
self.assertEqual(times.elapsed, 0)
|
||||
|
||||
|
||||
# Only test if the C version is provided, otherwise TestPEP519 already tested
|
||||
# the pure Python implementation.
|
||||
if hasattr(os, "_fspath"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue