|
8 | 8 | import inspect |
9 | 9 | from functools import partial |
10 | 10 |
|
11 | | -from test.support import captured_stderr, disable_gc, gc_collect, run_yielding_async_fn |
| 11 | +from test.support import captured_stderr, disable_gc, gc_collect, run_yielding_async_fn, catch_unraisable_exception |
12 | 12 |
|
13 | 13 | _async_test = partial(partial, run_yielding_async_fn) |
14 | 14 |
|
@@ -554,38 +554,38 @@ async def g(): |
554 | 554 | "finishing g", |
555 | 555 | ]) |
556 | 556 |
|
557 | | - # @_async_test |
558 | | - # async def test_broken_getattr_handling(self): |
559 | | - # """ |
560 | | - # Test subiterator with a broken getattr implementation |
561 | | - # """ |
562 | | - # class Broken: |
563 | | - # def __aiter__(self): |
564 | | - # return self |
565 | | - # async def __anext__(self): |
566 | | - # return 1 |
567 | | - # async def __getattr__(self, attr): |
568 | | - # 1/0 |
569 | | - |
570 | | - # async def g(): |
571 | | - # async yield from Broken() |
572 | | - |
573 | | - # with self.assertRaises(ZeroDivisionError): |
574 | | - # gi = g() |
575 | | - # self.assertEqual(await anext(gi), 1) |
576 | | - # await gi.asend(1) |
577 | | - |
578 | | - # with self.assertRaises(ZeroDivisionError): |
579 | | - # gi = g() |
580 | | - # self.assertEqual(await anext(gi), 1) |
581 | | - # await gi.athrow(AttributeError) |
582 | | - |
583 | | - # with support.catch_unraisable_exception() as cm: |
584 | | - # gi = g() |
585 | | - # self.assertEqual(await anext(gi), 1) |
586 | | - # await gi.aclose() |
587 | | - |
588 | | - # self.assertEqual(ZeroDivisionError, cm.unraisable.exc_type) |
| 557 | + @_async_test |
| 558 | + async def test_broken_getattr_handling(self): |
| 559 | + """ |
| 560 | + Test subiterator with a broken getattr implementation |
| 561 | + """ |
| 562 | + class Broken: |
| 563 | + def __aiter__(self): |
| 564 | + return self |
| 565 | + async def __anext__(self): |
| 566 | + return 1 |
| 567 | + def __getattr__(self, attr): |
| 568 | + 1/0 |
| 569 | + |
| 570 | + async def g(): |
| 571 | + async yield from Broken() |
| 572 | + |
| 573 | + with self.assertRaises(ZeroDivisionError): |
| 574 | + gi = g() |
| 575 | + self.assertEqual(await anext(gi), 1) |
| 576 | + await gi.asend(1) |
| 577 | + |
| 578 | + with self.assertRaises(ZeroDivisionError): |
| 579 | + gi = g() |
| 580 | + self.assertEqual(await anext(gi), 1) |
| 581 | + await gi.athrow(AttributeError) |
| 582 | + |
| 583 | + with catch_unraisable_exception() as cm: |
| 584 | + gi = g() |
| 585 | + self.assertEqual(await anext(gi), 1) |
| 586 | + await gi.aclose() |
| 587 | + |
| 588 | + self.assertEqual(ZeroDivisionError, cm.unraisable.exc_type) |
589 | 589 |
|
590 | 590 | @_async_test |
591 | 591 | async def test_exception_in_initial_next_call(self): |
|
0 commit comments