diff options
| author | Victor Stinner <victor.stinner@haypocalc.com> | 2012-02-07 22:29:46 (GMT) |
|---|---|---|
| committer | Victor Stinner <victor.stinner@haypocalc.com> | 2012-02-07 22:29:46 (GMT) |
| commit | 8b30201f7d3028628aba1b4bec203a7b507de73b (patch) | |
| tree | d28e1a3a7c771de2bc700e012272b9dfbe2f1417 /Lib/test/test_time.py | |
| parent | d1cd99b533a32e063fc4602c439da334d5a10331 (diff) | |
| download | cpython-8b30201f7d3028628aba1b4bec203a7b507de73b.zip cpython-8b30201f7d3028628aba1b4bec203a7b507de73b.tar.gz cpython-8b30201f7d3028628aba1b4bec203a7b507de73b.tar.bz2 | |
Issue #13846: Add time.monotonic(), monotonic clock.
Diffstat (limited to 'Lib/test/test_time.py')
| -rw-r--r-- | Lib/test/test_time.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index f299266..a89c511 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -331,16 +331,32 @@ class TimeTestCase(unittest.TestCase): pass self.assertEqual(time.strftime('%Z', tt), tzname) + @unittest.skipUnless(hasattr(time, 'monotonic'), + 'need time.monotonic()') + def test_monotonic(self): + t1 = time.monotonic() + t2 = time.monotonic() + self.assertGreaterEqual(t2, t1) + + t1 = time.monotonic() + time.sleep(0.1) + t2 = time.monotonic() + dt = t2 - t1 + self.assertGreater(t2, t1) + self.assertAlmostEqual(dt, 0.1, delta=0.2) + def test_wallclock(self): t1 = time.wallclock() t2 = time.wallclock() + # may fail if the system clock was changed self.assertGreaterEqual(t2, t1) t1 = time.wallclock() time.sleep(0.1) t2 = time.wallclock() - self.assertGreater(t2, t1) dt = t2 - t1 + # may fail if the system clock was changed + self.assertGreater(t2, t1) self.assertAlmostEqual(dt, 0.1, delta=0.2) def test_localtime_failure(self): |
