@@ -230,29 +230,29 @@ async def runner():
230
230
231
231
self .assertEqual (NUM , 15 )
232
232
233
- async def test_cancellation_in_body (self ):
233
+ async def test_taskgroup_08 (self ):
234
234
235
235
async def foo ():
236
- await asyncio .sleep (0.1 )
237
- 1 / 0
236
+ try :
237
+ await asyncio .sleep (10 )
238
+ finally :
239
+ 1 / 0
238
240
239
241
async def runner ():
240
242
async with taskgroups .TaskGroup () as g :
241
243
for _ in range (5 ):
242
244
g .create_task (foo ())
243
245
244
- try :
245
- await asyncio .sleep (10 )
246
- except asyncio .CancelledError :
247
- raise
246
+ await asyncio .sleep (10 )
248
247
249
248
r = asyncio .create_task (runner ())
250
249
await asyncio .sleep (0.1 )
251
250
252
251
self .assertFalse (r .done ())
253
252
r .cancel ()
254
- with self .assertRaises (asyncio . CancelledError ) as cm :
253
+ with self .assertRaises (ExceptionGroup ) as cm :
255
254
await r
255
+ self .assertEqual (get_error_types (cm .exception ), {ZeroDivisionError })
256
256
257
257
async def test_taskgroup_09 (self ):
258
258
@@ -316,33 +316,37 @@ async def runner():
316
316
async def test_taskgroup_11 (self ):
317
317
318
318
async def foo ():
319
- await asyncio .sleep (0.1 )
320
- 1 / 0
319
+ try :
320
+ await asyncio .sleep (10 )
321
+ finally :
322
+ 1 / 0
321
323
322
324
async def runner ():
323
325
async with taskgroups .TaskGroup ():
324
326
async with taskgroups .TaskGroup () as g2 :
325
327
for _ in range (5 ):
326
328
g2 .create_task (foo ())
327
329
328
- try :
329
- await asyncio .sleep (10 )
330
- except asyncio .CancelledError :
331
- raise
330
+ await asyncio .sleep (10 )
332
331
333
332
r = asyncio .create_task (runner ())
334
333
await asyncio .sleep (0.1 )
335
334
336
335
self .assertFalse (r .done ())
337
336
r .cancel ()
338
- with self .assertRaises (asyncio . CancelledError ) :
337
+ with self .assertRaises (ExceptionGroup ) as cm :
339
338
await r
340
339
340
+ self .assertEqual (get_error_types (cm .exception ), {ExceptionGroup })
341
+ self .assertEqual (get_error_types (cm .exception .exceptions [0 ]), {ZeroDivisionError })
342
+
341
343
async def test_taskgroup_12 (self ):
342
344
343
345
async def foo ():
344
- await asyncio .sleep (0.1 )
345
- 1 / 0
346
+ try :
347
+ await asyncio .sleep (10 )
348
+ finally :
349
+ 1 / 0
346
350
347
351
async def runner ():
348
352
async with taskgroups .TaskGroup () as g1 :
@@ -352,19 +356,19 @@ async def runner():
352
356
for _ in range (5 ):
353
357
g2 .create_task (foo ())
354
358
355
- try :
356
- await asyncio .sleep (10 )
357
- except asyncio .CancelledError :
358
- raise
359
+ await asyncio .sleep (10 )
359
360
360
361
r = asyncio .create_task (runner ())
361
362
await asyncio .sleep (0.1 )
362
363
363
364
self .assertFalse (r .done ())
364
365
r .cancel ()
365
- with self .assertRaises (asyncio . CancelledError ) :
366
+ with self .assertRaises (ExceptionGroup ) as cm :
366
367
await r
367
368
369
+ self .assertEqual (get_error_types (cm .exception ), {ExceptionGroup })
370
+ self .assertEqual (get_error_types (cm .exception .exceptions [0 ]), {ZeroDivisionError })
371
+
368
372
async def test_taskgroup_13 (self ):
369
373
370
374
async def crash_after (t ):
@@ -424,8 +428,9 @@ async def runner():
424
428
425
429
self .assertFalse (r .done ())
426
430
r .cancel ()
427
- with self .assertRaises (asyncio . CancelledError ) :
431
+ with self .assertRaises (ExceptionGroup ) as cm :
428
432
await r
433
+ self .assertEqual (get_error_types (cm .exception ), {ZeroDivisionError })
429
434
430
435
async def test_taskgroup_16 (self ):
431
436
@@ -451,8 +456,9 @@ async def runner():
451
456
452
457
self .assertFalse (r .done ())
453
458
r .cancel ()
454
- with self .assertRaises (asyncio . CancelledError ) :
459
+ with self .assertRaises (ExceptionGroup ) as cm :
455
460
await r
461
+ self .assertEqual (get_error_types (cm .exception ), {ZeroDivisionError })
456
462
457
463
async def test_taskgroup_17 (self ):
458
464
NUM = 0
0 commit comments