diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-10-17 21:46:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-17 21:46:45 (GMT) |
commit | 884d13a55fc328e2e1e3948a82b361b30804b818 (patch) | |
tree | 8b68f04b9261c26d4f2f5ed7a7beaa1d31c236c0 /Lib | |
parent | de86073a761cd3539aaca6f886a1f55effc0d9da (diff) | |
download | cpython-884d13a55fc328e2e1e3948a82b361b30804b818.zip cpython-884d13a55fc328e2e1e3948a82b361b30804b818.tar.gz cpython-884d13a55fc328e2e1e3948a82b361b30804b818.tar.bz2 |
time.clock() now emits a DeprecationWarning (GH-4020)
bpo-31803: time.clock() and time.get_clock_info('clock') now emit a
DeprecationWarning warning.
Replace time.clock() with time.perf_counter() in tests and demos.
Remove also hasattr(time, 'monotonic') in test_time since time.monotonic()
is now always available since Python 3.5.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ctypes/test/test_numbers.py | 2 | ||||
-rw-r--r-- | Lib/ctypes/test/test_strings.py | 2 | ||||
-rwxr-xr-x | Lib/profile.py | 2 | ||||
-rw-r--r-- | Lib/test/test_time.py | 22 | ||||
-rwxr-xr-x | Lib/turtledemo/bytedesign.py | 2 | ||||
-rwxr-xr-x | Lib/turtledemo/forest.py | 2 | ||||
-rwxr-xr-x | Lib/turtledemo/fractalcurves.py | 2 | ||||
-rwxr-xr-x | Lib/turtledemo/penrose.py | 2 | ||||
-rwxr-xr-x | Lib/turtledemo/tree.py | 2 | ||||
-rw-r--r-- | Lib/turtledemo/wikipedia.py | 2 |
10 files changed, 21 insertions, 19 deletions
diff --git a/Lib/ctypes/test/test_numbers.py b/Lib/ctypes/test/test_numbers.py index ba4f563..09eef90 100644 --- a/Lib/ctypes/test/test_numbers.py +++ b/Lib/ctypes/test/test_numbers.py @@ -241,7 +241,7 @@ class c_int_S(_SimpleCData): def run_test(rep, msg, func, arg=None): ## items = [None] * rep items = range(rep) - from time import clock + from time import perf_counter as clock if arg is not None: start = clock() for i in items: diff --git a/Lib/ctypes/test/test_strings.py b/Lib/ctypes/test/test_strings.py index c7bfbda..e28e141 100644 --- a/Lib/ctypes/test/test_strings.py +++ b/Lib/ctypes/test/test_strings.py @@ -194,7 +194,7 @@ class WStringTestCase(unittest.TestCase): def run_test(rep, msg, func, arg): items = range(rep) - from time import clock + from time import perf_counter as clock start = clock() for i in items: func(arg); func(arg); func(arg); func(arg); func(arg) diff --git a/Lib/profile.py b/Lib/profile.py index 5ceeddc..0340a79 100755 --- a/Lib/profile.py +++ b/Lib/profile.py @@ -195,7 +195,7 @@ class Profile: self.t = r[0] + r[1] - t # put back unrecorded delta # Dispatch routine for best timer program (return = scalar, fastest if - # an integer but float works too -- and time.clock() relies on that). + # an integer but float works too -- and time.process_time() relies on that). def trace_dispatch_i(self, frame, event, arg): timer = self.timer diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 61dda09..a08fd18 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -9,6 +9,7 @@ import sysconfig import time import threading import unittest +import warnings try: import _testcapi except ImportError: @@ -64,9 +65,11 @@ class TimeTestCase(unittest.TestCase): self.assertTrue(info.adjustable) def test_clock(self): - time.clock() + with self.assertWarns(DeprecationWarning): + time.clock() - info = time.get_clock_info('clock') + with self.assertWarns(DeprecationWarning): + info = time.get_clock_info('clock') self.assertTrue(info.monotonic) self.assertFalse(info.adjustable) @@ -427,8 +430,6 @@ class TimeTestCase(unittest.TestCase): pass self.assertEqual(time.strftime('%Z', tt), tzname) - @unittest.skipUnless(hasattr(time, 'monotonic'), - 'need time.monotonic') def test_monotonic(self): # monotonic() should not go backward times = [time.monotonic() for n in range(100)] @@ -467,8 +468,6 @@ class TimeTestCase(unittest.TestCase): self.assertTrue(info.monotonic) self.assertFalse(info.adjustable) - @unittest.skipUnless(hasattr(time, 'monotonic'), - 'need time.monotonic') @unittest.skipUnless(hasattr(time, 'clock_settime'), 'need time.clock_settime') def test_monotonic_settime(self): @@ -506,12 +505,15 @@ class TimeTestCase(unittest.TestCase): self.assertRaises(ValueError, time.ctime, float("nan")) def test_get_clock_info(self): - clocks = ['clock', 'perf_counter', 'process_time', 'time'] - if hasattr(time, 'monotonic'): - clocks.append('monotonic') + clocks = ['clock', 'monotonic', 'perf_counter', 'process_time', 'time'] for name in clocks: - info = time.get_clock_info(name) + if name == 'clock': + with self.assertWarns(DeprecationWarning): + info = time.get_clock_info('clock') + else: + info = time.get_clock_info(name) + #self.assertIsInstance(info, dict) self.assertIsInstance(info.implementation, str) self.assertNotEqual(info.implementation, '') diff --git a/Lib/turtledemo/bytedesign.py b/Lib/turtledemo/bytedesign.py index b3b095b..1b7452b 100755 --- a/Lib/turtledemo/bytedesign.py +++ b/Lib/turtledemo/bytedesign.py @@ -23,7 +23,7 @@ mode as fast as possible. """ from turtle import Turtle, mainloop -from time import clock +from time import perf_counter as clock # wrapper for any additional drawing routines # that need to know about each other diff --git a/Lib/turtledemo/forest.py b/Lib/turtledemo/forest.py index 7fe080e..55b7da9 100755 --- a/Lib/turtledemo/forest.py +++ b/Lib/turtledemo/forest.py @@ -13,7 +13,7 @@ http://homepage.univie.ac.at/erich.neuwirth/ """ from turtle import Turtle, colormode, tracer, mainloop from random import randrange -from time import clock +from time import perf_counter as clock def symRandom(n): return randrange(-n,n+1) diff --git a/Lib/turtledemo/fractalcurves.py b/Lib/turtledemo/fractalcurves.py index c49f8b8..54ade96 100755 --- a/Lib/turtledemo/fractalcurves.py +++ b/Lib/turtledemo/fractalcurves.py @@ -12,7 +12,7 @@ methods are taken from the PythonCard example scripts for turtle-graphics. """ from turtle import * -from time import sleep, clock +from time import sleep, perf_counter as clock class CurvesTurtle(Pen): # example derived from diff --git a/Lib/turtledemo/penrose.py b/Lib/turtledemo/penrose.py index f73c864..b2a5813 100755 --- a/Lib/turtledemo/penrose.py +++ b/Lib/turtledemo/penrose.py @@ -17,7 +17,7 @@ For more information see: """ from turtle import * from math import cos, pi -from time import clock, sleep +from time import perf_counter as clock, sleep f = (5**0.5-1)/2.0 # (sqrt(5)-1)/2 -- golden ratio d = 2 * cos(3*pi/10) diff --git a/Lib/turtledemo/tree.py b/Lib/turtledemo/tree.py index 71fff35..9998fa8 100755 --- a/Lib/turtledemo/tree.py +++ b/Lib/turtledemo/tree.py @@ -16,7 +16,7 @@ the current pen is cloned. So in the end there are 1024 turtles. """ from turtle import Turtle, mainloop -from time import clock +from time import perf_counter as clock def tree(plist, l, a, f): """ plist is list of pens diff --git a/Lib/turtledemo/wikipedia.py b/Lib/turtledemo/wikipedia.py index d6bbad8..47d0f00 100644 --- a/Lib/turtledemo/wikipedia.py +++ b/Lib/turtledemo/wikipedia.py @@ -14,7 +14,7 @@ parallel. Followed by a complete undo(). """ from turtle import Screen, Turtle, mainloop -from time import clock, sleep +from time import perf_counter as clock, sleep def mn_eck(p, ne,sz): turtlelist = [p] |