mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Close #10278: Add clock_getres(), clock_gettime() and CLOCK_xxx constants to
the time module. time.clock_gettime(time.CLOCK_MONOTONIC) provides a monotonic clock
This commit is contained in:
parent
92b958420e
commit
e0be423297
9 changed files with 615 additions and 288 deletions
|
@ -20,6 +20,27 @@ class TimeTestCase(unittest.TestCase):
|
|||
def test_clock(self):
|
||||
time.clock()
|
||||
|
||||
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
|
||||
'need time.clock_gettime()')
|
||||
def test_clock_realtime(self):
|
||||
time.clock_gettime(time.CLOCK_REALTIME)
|
||||
|
||||
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
|
||||
'need time.clock_gettime()')
|
||||
@unittest.skipUnless(hasattr(time, 'CLOCK_MONOTONIC'),
|
||||
'need time.CLOCK_MONOTONIC')
|
||||
def test_clock_monotonic(self):
|
||||
a = time.clock_gettime(time.CLOCK_MONOTONIC)
|
||||
b = time.clock_gettime(time.CLOCK_MONOTONIC)
|
||||
self.assertLessEqual(a, b)
|
||||
|
||||
@unittest.skipUnless(hasattr(time, 'clock_getres'),
|
||||
'need time.clock_getres()')
|
||||
def test_clock_getres(self):
|
||||
res = time.clock_getres(time.CLOCK_REALTIME)
|
||||
self.assertGreater(res, 0.0)
|
||||
self.assertLessEqual(res, 1.0)
|
||||
|
||||
def test_conversions(self):
|
||||
self.assertEqual(time.ctime(self.t),
|
||||
time.asctime(time.localtime(self.t)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue