@@ -27,7 +27,7 @@ def test_close(self):
27
27
self .loop .close ()
28
28
29
29
# operation blocked when the loop is closed
30
- f = asyncio .Future (loop = self . loop )
30
+ f = asyncio .Future ()
31
31
self .assertRaises (RuntimeError , self .loop .run_forever )
32
32
self .assertRaises (RuntimeError , self .loop .run_until_complete , f )
33
33
@@ -99,7 +99,7 @@ def cb():
99
99
100
100
meth (cb )
101
101
self .assertIsNone (context )
102
- self .loop .run_until_complete (asyncio .sleep (0.05 , loop = self . loop ))
102
+ self .loop .run_until_complete (asyncio .sleep (0.05 ))
103
103
104
104
self .assertIs (type (context ['exception' ]), ZeroDivisionError )
105
105
self .assertTrue (context ['message' ].startswith (
@@ -167,9 +167,9 @@ def test_call_later_2(self):
167
167
# libuv cached time.
168
168
169
169
async def main ():
170
- await asyncio .sleep (0.001 , loop = self . loop )
170
+ await asyncio .sleep (0.001 )
171
171
time .sleep (0.01 )
172
- await asyncio .sleep (0.01 , loop = self . loop )
172
+ await asyncio .sleep (0.01 )
173
173
174
174
started = time .monotonic ()
175
175
self .loop .run_until_complete (main ())
@@ -331,7 +331,7 @@ def test_run_until_complete_type_error(self):
331
331
TypeError , self .loop .run_until_complete , 'blah' )
332
332
333
333
def test_run_until_complete_loop (self ):
334
- task = asyncio .Future (loop = self . loop )
334
+ task = asyncio .Future ()
335
335
other_loop = self .new_loop ()
336
336
self .addCleanup (other_loop .close )
337
337
self .assertRaises (
@@ -351,7 +351,7 @@ class ShowStopper(BaseException):
351
351
pass
352
352
353
353
async def foo (delay ):
354
- await asyncio .sleep (delay , loop = self . loop )
354
+ await asyncio .sleep (delay )
355
355
356
356
def throw ():
357
357
raise ShowStopper
@@ -373,7 +373,7 @@ def test_debug_slow_callbacks(self):
373
373
self .loop .call_soon (lambda : time .sleep (0.3 ))
374
374
375
375
with mock .patch .object (logger , 'warning' ) as log :
376
- self .loop .run_until_complete (asyncio .sleep (0 , loop = self . loop ))
376
+ self .loop .run_until_complete (asyncio .sleep (0 ))
377
377
378
378
self .assertEqual (log .call_count , 1 )
379
379
# format message
@@ -389,7 +389,7 @@ def test_debug_slow_timer_callbacks(self):
389
389
self .loop .call_later (0.01 , lambda : time .sleep (0.3 ))
390
390
391
391
with mock .patch .object (logger , 'warning' ) as log :
392
- self .loop .run_until_complete (asyncio .sleep (0.02 , loop = self . loop ))
392
+ self .loop .run_until_complete (asyncio .sleep (0.02 ))
393
393
394
394
self .assertEqual (log .call_count , 1 )
395
395
# format message
@@ -429,7 +429,7 @@ def zero_error(fut):
429
429
430
430
# Test call_soon (events.Handle)
431
431
with mock .patch .object (logger , 'error' ) as log :
432
- fut = asyncio .Future (loop = self . loop )
432
+ fut = asyncio .Future ()
433
433
self .loop .call_soon (zero_error , fut )
434
434
fut .add_done_callback (lambda fut : self .loop .stop ())
435
435
self .loop .run_forever ()
@@ -439,7 +439,7 @@ def zero_error(fut):
439
439
440
440
# Test call_later (events.TimerHandle)
441
441
with mock .patch .object (logger , 'error' ) as log :
442
- fut = asyncio .Future (loop = self . loop )
442
+ fut = asyncio .Future ()
443
443
self .loop .call_later (0.01 , zero_error , fut )
444
444
fut .add_done_callback (lambda fut : self .loop .stop ())
445
445
self .loop .run_forever ()
@@ -562,31 +562,34 @@ def test_shutdown_asyncgens_01(self):
562
562
raise unittest .SkipTest ()
563
563
564
564
waiter = self ._compile_agen (
565
- '''async def waiter(timeout, finalized, loop ):
565
+ '''async def waiter(timeout, finalized):
566
566
try:
567
- await asyncio.sleep(timeout, loop=loop )
567
+ await asyncio.sleep(timeout)
568
568
yield 1
569
569
finally:
570
- await asyncio.sleep(0, loop=loop )
570
+ await asyncio.sleep(0)
571
571
finalized.append(1)
572
572
''' )
573
573
574
574
async def wait ():
575
- async for _ in waiter (1 , finalized , self . loop ):
575
+ async for _ in waiter (1 , finalized ):
576
576
pass
577
577
578
578
t1 = self .loop .create_task (wait ())
579
579
t2 = self .loop .create_task (wait ())
580
580
581
- self .loop .run_until_complete (asyncio .sleep (0.1 , loop = self . loop ))
581
+ self .loop .run_until_complete (asyncio .sleep (0.1 ))
582
582
583
+ t1 .cancel ()
584
+ t2 .cancel ()
583
585
self .loop .run_until_complete (self .loop .shutdown_asyncgens ())
584
586
self .assertEqual (finalized , [1 , 1 ])
585
587
586
- # Silence warnings
587
- t1 .cancel ()
588
- t2 .cancel ()
589
- self .loop .run_until_complete (asyncio .sleep (0.1 , loop = self .loop ))
588
+ for t in {t1 , t2 }:
589
+ try :
590
+ self .loop .run_until_complete (t )
591
+ except asyncio .CancelledError :
592
+ pass
590
593
591
594
def test_shutdown_asyncgens_02 (self ):
592
595
if not hasattr (self .loop , 'shutdown_asyncgens' ):
@@ -601,20 +604,20 @@ def logger(loop, context):
601
604
if expected in context ['message' ]:
602
605
logged += 1
603
606
604
- waiter = self ._compile_agen ('''async def waiter(timeout, loop ):
607
+ waiter = self ._compile_agen ('''async def waiter(timeout):
605
608
try:
606
- await asyncio.sleep(timeout, loop=loop )
609
+ await asyncio.sleep(timeout)
607
610
yield 1
608
611
finally:
609
612
1 / 0
610
613
''' )
611
614
612
615
async def wait ():
613
- async for _ in waiter (1 , self . loop ):
616
+ async for _ in waiter (1 ):
614
617
pass
615
618
616
619
t = self .loop .create_task (wait ())
617
- self .loop .run_until_complete (asyncio .sleep (0.1 , loop = self . loop ))
620
+ self .loop .run_until_complete (asyncio .sleep (0.1 ))
618
621
619
622
self .loop .set_exception_handler (logger )
620
623
self .loop .run_until_complete (self .loop .shutdown_asyncgens ())
@@ -623,7 +626,7 @@ async def wait():
623
626
624
627
# Silence warnings
625
628
t .cancel ()
626
- self .loop .run_until_complete (asyncio .sleep (0.1 , loop = self . loop ))
629
+ self .loop .run_until_complete (asyncio .sleep (0.1 ))
627
630
628
631
def test_shutdown_asyncgens_03 (self ):
629
632
if not hasattr (self .loop , 'shutdown_asyncgens' ):
@@ -640,14 +643,14 @@ async def foo():
640
643
await waiter ().asend (None )
641
644
642
645
self .loop .run_until_complete (foo ())
643
- self .loop .run_until_complete (asyncio .sleep (0.01 , loop = self . loop ))
646
+ self .loop .run_until_complete (asyncio .sleep (0.01 ))
644
647
645
648
def test_inf_wait_for (self ):
646
649
async def foo ():
647
- await asyncio .sleep (0.1 , loop = self . loop )
650
+ await asyncio .sleep (0.1 )
648
651
return 123
649
652
res = self .loop .run_until_complete (
650
- asyncio .wait_for (foo (), timeout = float ('inf' ), loop = self . loop ))
653
+ asyncio .wait_for (foo (), timeout = float ('inf' )))
651
654
self .assertEqual (res , 123 )
652
655
653
656
0 commit comments