@@ -163,9 +163,7 @@ def test_conversions(self):
163
163
def test_sleep (self ):
164
164
self .assertRaises (ValueError , time .sleep , - 2 )
165
165
self .assertRaises (ValueError , time .sleep , - 1 )
166
- time .sleep (1.2 )
167
- time .sleep (IndexLike (0 ))
168
- time .sleep (FloatLike (0 ))
166
+ time .sleep (0.2 )
169
167
170
168
def test_strftime (self ):
171
169
tt = time .gmtime (self .t )
@@ -468,21 +466,24 @@ def test_monotonic(self):
468
466
self .assertGreaterEqual (t2 , t1 , "times=%s" % times )
469
467
t1 = t2
470
468
471
- # monotonic() includes time elapsed during a sleep
472
- t1 = time .monotonic ()
473
- time .sleep (0.5 )
474
- t2 = time .monotonic ()
475
- dt = t2 - t1
476
- self .assertGreater (t2 , t1 )
477
- # bpo-20101: tolerate a difference of 50 ms because of bad timer
478
- # resolution on Windows
479
- self .assertTrue (0.450 <= dt )
480
-
481
469
# monotonic() is a monotonic but non adjustable clock
482
470
info = time .get_clock_info ('monotonic' )
483
471
self .assertTrue (info .monotonic )
484
472
self .assertFalse (info .adjustable )
485
473
474
+ def test_monotic_sleep (self ):
475
+ # This tests both time.sleep() and time.monotonic(): we test various
476
+ # types of input to time.sleep() and check using time.monotonic() that
477
+ # we sleep sufficiently long.
478
+ for T in (0.5 , decimal .Decimal ('0.5' ), FloatLike (0.5 ), IndexLike (1 )):
479
+ t1 = time .monotonic ()
480
+ time .sleep (T )
481
+ t2 = time .monotonic ()
482
+ dt = t2 - t1
483
+ # bpo-20101: tolerate a difference of 50 ms because of bad timer
484
+ # resolution on Windows
485
+ self .assertGreaterEqual (dt , float (T ) - 0.05 )
486
+
486
487
def test_perf_counter (self ):
487
488
time .perf_counter ()
488
489
0 commit comments