MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_func_18

Method test_func_18

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

Source from the content-addressed store, hash-verified

847 coro.close()
848
849 def test_func_18(self):
850 # See http://bugs.python.org/issue25887 for details
851
852 async def coroutine():
853 return 'spam'
854
855 coro = coroutine()
856 await_iter = coro.__await__()
857 it = iter(await_iter)
858
859 with self.assertRaisesRegex(StopIteration, 'spam'):
860 it.send(None)
861
862 with self.assertRaisesRegex(RuntimeError,
863 'cannot reuse already awaited coroutine'):
864 it.send(None)
865
866 with self.assertRaisesRegex(RuntimeError,
867 'cannot reuse already awaited coroutine'):
868 # Although the iterator protocol requires iterators to
869 # raise another StopIteration here, we don't want to do
870 # that. In this particular case, the iterator will raise
871 # a RuntimeError, so that 'yield from' and 'await'
872 # expressions will trigger the error, instead of silently
873 # ignoring the call.
874 next(it)
875
876 with self.assertRaisesRegex(RuntimeError,
877 'cannot reuse already awaited coroutine'):
878 it.throw(Exception('wat'))
879
880 with self.assertRaisesRegex(RuntimeError,
881 'cannot reuse already awaited coroutine'):
882 it.throw(Exception('wat'))
883
884 # Closing a coroutine shouldn't raise any exception even if it's
885 # already closed/exhausted (similar to generators)
886 it.close()
887 it.close()
888
889 def test_func_19(self):
890 CHK = 0

Callers

nothing calls this directly

Calls 8

coroutineFunction · 0.85
iterFunction · 0.85
nextFunction · 0.85
assertRaisesRegexMethod · 0.80
__await__Method · 0.45
sendMethod · 0.45
throwMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected