MCPcopy Index your code
hub / github.com/python/cpython / test_func_10

Method test_func_10

Lib/test/test_coroutines.py:684–724  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

682 support.gc_collect()
683
684 def test_func_10(self):
685 N = 0
686
687 @types.coroutine
688 def gen():
689 nonlocal N
690 try:
691 a = yield
692 yield (a ** 2)
693 except ZeroDivisionError:
694 N += 100
695 raise
696 finally:
697 N += 1
698
699 async def foo():
700 await gen()
701
702 coro = foo()
703 aw = coro.__await__()
704 self.assertIs(aw, iter(aw))
705 next(aw)
706 self.assertEqual(aw.send(10), 100)
707
708 self.assertEqual(N, 0)
709 aw.close()
710 self.assertEqual(N, 1)
711
712 coro = foo()
713 aw = coro.__await__()
714 next(aw)
715 with self.assertRaises(ZeroDivisionError):
716 aw.throw(ZeroDivisionError())
717 self.assertEqual(N, 102)
718
719 coro = foo()
720 aw = coro.__await__()
721 next(aw)
722 with self.assertRaises(ZeroDivisionError):
723 with self.assertWarns(DeprecationWarning):
724 aw.throw(ZeroDivisionError, ZeroDivisionError(), None)
725
726 def test_func_11(self):
727 async def func(): pass

Callers

nothing calls this directly

Calls 9

assertWarnsMethod · 0.80
fooFunction · 0.70
__await__Method · 0.45
assertIsMethod · 0.45
assertEqualMethod · 0.45
sendMethod · 0.45
closeMethod · 0.45
assertRaisesMethod · 0.45
throwMethod · 0.45

Tested by

no test coverage detected