def test_eval_code_async_loop(): async def slow_identity(i): await asyncio.sleep(0.1) return i c = eval_code_async( """ tot = 0 for i in range(10): tot += await slow_identity(i) tot """, globals=globals(), locals=locals(), ) fut = asyncio.ensure_future(c) asyncio.get_event_loop().run_until_complete(fut) assert fut.result() == 45
def test_eval_code_async_simple(): c = eval_code_async("1+92") with pytest.raises(StopIteration, match="93"): c.send(None)