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

Method test_anext_bad_await

Lib/test/test_asyncgen.py:785–804  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

783 self.loop.run_until_complete(call_with_kwarg())
784
785 def test_anext_bad_await(self):
786 async def bad_awaitable():
787 class BadAwaitable:
788 def __await__(self):
789 return 42
790 class MyAsyncIter:
791 def __aiter__(self):
792 return self
793 def __anext__(self):
794 return BadAwaitable()
795 regex = r"__await__.*iterator"
796 awaitable = anext(MyAsyncIter(), "default")
797 with self.assertRaisesRegex(TypeError, regex):
798 await awaitable
799 awaitable = anext(MyAsyncIter())
800 with self.assertRaisesRegex(TypeError, regex):
801 await awaitable
802 return "completed"
803 result = self.loop.run_until_complete(bad_awaitable())
804 self.assertEqual(result, "completed")
805
806 async def check_anext_returning_iterator(self, aiter_class):
807 awaitable = anext(aiter_class(), "default")

Callers

nothing calls this directly

Calls 2

run_until_completeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected