|
9 | 9 | import time |
10 | 10 | import threading |
11 | 11 | import unittest |
| 12 | +import warnings |
12 | 13 | try: |
13 | 14 | import _testcapi |
14 | 15 | except ImportError: |
@@ -64,9 +65,11 @@ def test_time(self): |
64 | 65 | self.assertTrue(info.adjustable) |
65 | 66 |
|
66 | 67 | def test_clock(self): |
67 | | - time.clock() |
| 68 | + with self.assertWarns(DeprecationWarning): |
| 69 | + time.clock() |
68 | 70 |
|
69 | | - info = time.get_clock_info('clock') |
| 71 | + with self.assertWarns(DeprecationWarning): |
| 72 | + info = time.get_clock_info('clock') |
70 | 73 | self.assertTrue(info.monotonic) |
71 | 74 | self.assertFalse(info.adjustable) |
72 | 75 |
|
@@ -427,8 +430,6 @@ def test_mktime_error(self): |
427 | 430 | pass |
428 | 431 | self.assertEqual(time.strftime('%Z', tt), tzname) |
429 | 432 |
|
430 | | - @unittest.skipUnless(hasattr(time, 'monotonic'), |
431 | | - 'need time.monotonic') |
432 | 433 | def test_monotonic(self): |
433 | 434 | # monotonic() should not go backward |
434 | 435 | times = [time.monotonic() for n in range(100)] |
@@ -467,8 +468,6 @@ def test_process_time(self): |
467 | 468 | self.assertTrue(info.monotonic) |
468 | 469 | self.assertFalse(info.adjustable) |
469 | 470 |
|
470 | | - @unittest.skipUnless(hasattr(time, 'monotonic'), |
471 | | - 'need time.monotonic') |
472 | 471 | @unittest.skipUnless(hasattr(time, 'clock_settime'), |
473 | 472 | 'need time.clock_settime') |
474 | 473 | def test_monotonic_settime(self): |
@@ -506,12 +505,15 @@ def test_localtime_failure(self): |
506 | 505 | self.assertRaises(ValueError, time.ctime, float("nan")) |
507 | 506 |
|
508 | 507 | def test_get_clock_info(self): |
509 | | - clocks = ['clock', 'perf_counter', 'process_time', 'time'] |
510 | | - if hasattr(time, 'monotonic'): |
511 | | - clocks.append('monotonic') |
| 508 | + clocks = ['clock', 'monotonic', 'perf_counter', 'process_time', 'time'] |
512 | 509 |
|
513 | 510 | for name in clocks: |
514 | | - info = time.get_clock_info(name) |
| 511 | + if name == 'clock': |
| 512 | + with self.assertWarns(DeprecationWarning): |
| 513 | + info = time.get_clock_info('clock') |
| 514 | + else: |
| 515 | + info = time.get_clock_info(name) |
| 516 | + |
515 | 517 | #self.assertIsInstance(info, dict) |
516 | 518 | self.assertIsInstance(info.implementation, str) |
517 | 519 | self.assertNotEqual(info.implementation, '') |
|
0 commit comments