@@ -113,7 +113,11 @@ async def coro():
113
113
self .assertTrue (hasattr (t , '_cancel_message' ))
114
114
self .assertEqual (t ._cancel_message , None )
115
115
116
- t .cancel ('my message' )
116
+ with self .assertWarnsRegex (
117
+ DeprecationWarning ,
118
+ "Passing 'msg' argument"
119
+ ):
120
+ t .cancel ('my message' )
117
121
self .assertEqual (t ._cancel_message , 'my message' )
118
122
119
123
with self .assertRaises (asyncio .CancelledError ) as cm :
@@ -125,7 +129,11 @@ def test_task_cancel_message_setter(self):
125
129
async def coro ():
126
130
pass
127
131
t = self .new_task (self .loop , coro ())
128
- t .cancel ('my message' )
132
+ with self .assertWarnsRegex (
133
+ DeprecationWarning ,
134
+ "Passing 'msg' argument"
135
+ ):
136
+ t .cancel ('my message' )
129
137
t ._cancel_message = 'my new message'
130
138
self .assertEqual (t ._cancel_message , 'my new message' )
131
139
@@ -582,7 +590,14 @@ async def sleep():
582
590
async def coro ():
583
591
task = self .new_task (loop , sleep ())
584
592
await asyncio .sleep (0 )
585
- task .cancel (* cancel_args )
593
+ if cancel_args not in ((), (None ,)):
594
+ with self .assertWarnsRegex (
595
+ DeprecationWarning ,
596
+ "Passing 'msg' argument"
597
+ ):
598
+ task .cancel (* cancel_args )
599
+ else :
600
+ task .cancel (* cancel_args )
586
601
done , pending = await asyncio .wait ([task ])
587
602
task .result ()
588
603
@@ -616,7 +631,14 @@ async def sleep():
616
631
async def coro ():
617
632
task = self .new_task (loop , sleep ())
618
633
await asyncio .sleep (0 )
619
- task .cancel (* cancel_args )
634
+ if cancel_args not in ((), (None ,)):
635
+ with self .assertWarnsRegex (
636
+ DeprecationWarning ,
637
+ "Passing 'msg' argument"
638
+ ):
639
+ task .cancel (* cancel_args )
640
+ else :
641
+ task .cancel (* cancel_args )
620
642
done , pending = await asyncio .wait ([task ])
621
643
task .exception ()
622
644
@@ -639,10 +661,17 @@ async def sleep():
639
661
fut .set_result (None )
640
662
await asyncio .sleep (10 )
641
663
664
+ def cancel (task , msg ):
665
+ with self .assertWarnsRegex (
666
+ DeprecationWarning ,
667
+ "Passing 'msg' argument"
668
+ ):
669
+ task .cancel (msg )
670
+
642
671
async def coro ():
643
672
inner_task = self .new_task (loop , sleep ())
644
673
await fut
645
- loop .call_soon (inner_task . cancel , 'msg' )
674
+ loop .call_soon (cancel , inner_task , 'msg' )
646
675
try :
647
676
await inner_task
648
677
except asyncio .CancelledError as ex :
@@ -668,7 +697,11 @@ async def sleep():
668
697
async def coro ():
669
698
task = self .new_task (loop , sleep ())
670
699
# We deliberately leave out the sleep here.
671
- task .cancel ('my message' )
700
+ with self .assertWarnsRegex (
701
+ DeprecationWarning ,
702
+ "Passing 'msg' argument"
703
+ ):
704
+ task .cancel ('my message' )
672
705
done , pending = await asyncio .wait ([task ])
673
706
task .exception ()
674
707
@@ -2029,7 +2062,14 @@ async def test():
2029
2062
async def main ():
2030
2063
qwe = self .new_task (loop , test ())
2031
2064
await asyncio .sleep (0.2 )
2032
- qwe .cancel (* cancel_args )
2065
+ if cancel_args not in ((), (None ,)):
2066
+ with self .assertWarnsRegex (
2067
+ DeprecationWarning ,
2068
+ "Passing 'msg' argument"
2069
+ ):
2070
+ qwe .cancel (* cancel_args )
2071
+ else :
2072
+ qwe .cancel (* cancel_args )
2033
2073
await qwe
2034
2074
2035
2075
try :
0 commit comments