def test_forgetting_async_with_on_scope_raises_exception(): """ We raise an exeption if sync with is used on scopes """ with pytest.raises(TypeError): with ayo.scope(): pass with pytest.raises(TypeError): ayo.scope().__exit__(None, None, None)
async def main1(run): async with ayo.scope(max_concurrency=2) as runalso: runalso.all(foo(), foo(), foo(), foo(), foo(), foo()) a, b, c, d, e, f = runalso.results assert diff_in_seconds(a, b) == 0.0 assert diff_in_seconds(c, d) == 0.0 assert diff_in_seconds(e, f) == 0.0 assert diff_in_seconds(c, b) == 0.1 assert diff_in_seconds(d, e) == 0.1
async def main(run): run << foo(run) # TODO: check what happens if I cancel from the parent scope # TODO: test stuff with the parent scope async with ayo.scope() as runalso: runalso.all(foo(runalso), foo(runalso), foo(runalso)) assert not runalso.cancelled runalso.cancel() assert False, "We should never reach this point" assert not run.cancelled assert runalso.cancelled assert not count.value, "No coroutine has finished"
async def main3(run): async with ayo.scope(max_concurrency=2) as runalso: runalso.from_callable(foo) runalso.from_callable(foo) runalso.from_callable(foo) runalso.from_callable(foo) runalso.from_callable(foo) runalso.from_callable(foo) a, b, c, d, e, f = runalso.results assert diff_in_seconds(a, b) == 0.0 assert diff_in_seconds(c, d) == 0.0 assert diff_in_seconds(e, f) == 0.0 assert diff_in_seconds(c, b) == 0.1 assert diff_in_seconds(d, e) == 0.1
async def main(s): async with ayo.scope() as run: run.all(foo(1), foo(2), foo(3)) assert sorted(run.results) == [1, 2, 3]
async def main4(run): async with ayo.scope() as runalso: runalso.all(foo(0.5), foo(2), foo(3))
async def main3(run): async with ayo.scope() as runalso: runalso.all(foo(0.05), foo(0.2), foo(0.3))
async def main2(run): async with ayo.scope(timeout=1) as runalso: runalso.all(foo(0.05), foo(0.2), foo(0.3))
async def main_wrapper(): # pylint: disable=C0111 async with ayo.scope(timeout=timeout, max_concurrency=max_concurrency) as scope: scope.all(*(coro(scope) for coro in coroutines))