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:
Victor Stinner 2011-10-25 13:06:09 +02:00
parent 92b958420e
commit e0be423297
9 changed files with 615 additions and 288 deletions

View file

@ -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)))