summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_time.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-02 14:28:27 (GMT)
committerGitHub <noreply@github.com>2017-11-02 14:28:27 (GMT)
commitc29b585fd4b5a91d17fc5dd41d86edff28a30da3 (patch)
treeaadcf238ccc1867d7adefc079081781424e3e62c /Lib/test/test_time.py
parente314853d57450b2b9523157eebd405289a795a0e (diff)
downloadcpython-c29b585fd4b5a91d17fc5dd41d86edff28a30da3.zip
cpython-c29b585fd4b5a91d17fc5dd41d86edff28a30da3.tar.gz
cpython-c29b585fd4b5a91d17fc5dd41d86edff28a30da3.tar.bz2
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
Diffstat (limited to 'Lib/test/test_time.py')
-rw-r--r--Lib/test/test_time.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index a08fd18..b44646d 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -64,6 +64,27 @@ class TimeTestCase(unittest.TestCase):
self.assertFalse(info.monotonic)
self.assertTrue(info.adjustable)
+ def test_time_ns_type(self):
+ def check_ns(sec, ns):
+ self.assertIsInstance(ns, int)
+
+ sec_ns = int(sec * 1e9)
+ # tolerate a difference of 50 ms
+ self.assertLess((sec_ns - ns), 50 ** 6, (sec, ns))
+
+ check_ns(time.time(),
+ time.time_ns())
+ check_ns(time.monotonic(),
+ time.monotonic_ns())
+ check_ns(time.perf_counter(),
+ time.perf_counter_ns())
+ check_ns(time.process_time(),
+ time.process_time_ns())
+
+ if hasattr(time, 'clock_gettime'):
+ check_ns(time.clock_gettime(time.CLOCK_REALTIME),
+ time.clock_gettime_ns(time.CLOCK_REALTIME))
+
def test_clock(self):
with self.assertWarns(DeprecationWarning):
time.clock()
@@ -76,7 +97,8 @@ class TimeTestCase(unittest.TestCase):
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
'need time.clock_gettime()')
def test_clock_realtime(self):
- time.clock_gettime(time.CLOCK_REALTIME)
+ t = time.clock_gettime(time.CLOCK_REALTIME)
+ self.assertIsInstance(t, float)
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
'need time.clock_gettime()')