def test_monotonic(self):
# monotonic() should not go backward
times = [time.monotonic() for n in range(100)]
t1 = times[0]
for t2 in times[1:]:
self.assertGreaterEqual(t2, t1, "times=%s" % times)
t1 = t2
# monotonic() includes time elapsed during a sleep
t1 = time.monotonic()
time.sleep(0.5)
t2 = time.monotonic()
dt = t2 - t1
self.assertGreater(t2, t1)
# Issue #20101: On some Windows machines, dt may be slightly low
self.assertTrue(0.45 <= dt <= 1.0, dt)
# monotonic() is a monotonic but non adjustable clock
info = time.get_clock_info('monotonic')
self.assertTrue(info.monotonic)
self.assertFalse(info.adjustable)
评论列表
文章目录