Beispiel #1
0
def test_misuse():
    assert not greenback.has_portal()  # shouldn't raise an error

    with pytest.raises(RuntimeError,
                       match="only supported.*running under Trio"):
        anyio.run(greenback.with_portal_run_tree,
                  anyio.sleep,
                  1,
                  backend="asyncio")

    with pytest.raises(sniffio.AsyncLibraryNotFoundError):
        greenback.await_(42)

    @trio.run
    async def wrong_library():
        sniffio.current_async_library_cvar.set("tokio")
        with pytest.raises(RuntimeError,
                           match="greenback does not support tokio"):
            greenback.await_(trio.sleep(1))

    @trio.run
    async def not_awaitable():
        await greenback.ensure_portal()
        with pytest.raises(TypeError,
                           match="int can't be used in 'await' expression"):
            greenback.await_(42)
Beispiel #2
0
def test_misuse():
    with pytest.raises(sniffio.AsyncLibraryNotFoundError):
        greenback.await_(42)

    @trio.run
    async def wrong_library():
        sniffio.current_async_library_cvar.set("tokio")
        with pytest.raises(RuntimeError, match="greenback does not support tokio"):
            greenback.await_(trio.sleep(1))

    @trio.run
    async def not_awaitable():
        await greenback.ensure_portal()
        with pytest.raises(TypeError, match="int can't be used in 'await' expression"):
            greenback.await_(42)
Beispiel #3
0
 async def not_awaitable():
     await greenback.ensure_portal()
     with pytest.raises(TypeError,
                        match="int can't be used in 'await' expression"):
         greenback.await_(42)
Beispiel #4
0
 async def wrong_library():
     sniffio.current_async_library_cvar.set("tokio")
     with pytest.raises(RuntimeError,
                        match="greenback does not support tokio"):
         greenback.await_(trio.sleep(1))
Beispiel #5
0
async def main():
    # Baseline: checkpoint with no greenback involved.
    await timeit("checkpoints", busy)

    # Greenback portal installed, but calling checkpoint normally.
    await timeit("checkpoints in one portal", greenback.with_portal_run, busy)

    # Greenback portal installed, calling checkpoint through await_ each time.
    await timeit("await_(checkpoint)s in one portal", greenback.with_portal_run, adapt_sync, sync_busy)

    # Greenback portal installed, calling checkpoint many times in a single await_.
    await timeit("checkpoints in one (portal + await_)", greenback.with_portal_run, adapt_sync, lambda: await_(busy()))

    # Simpler portal from with_portal_run_sync(), calling checkpoint through await_.
    await timeit("await_(checkpoint)s in one sync portal", greenback.with_portal_run_sync, sync_busy)

    # Create one with_portal_run() portal per checkpoint, and await_ the checkpoint.
    await timeit("[async portal + await_ + checkpoint]s", each_busy)

    # Create one with_portal_run_sync() portal per checkpoint, and await_ the checkpoint.
    await timeit("[sync portal + await_ + checkpoint]s", each_sync_busy)

    # Create one with_portal_run() portal per checkpoint, and await_ the checkpoint.
    await timeit("async portal creations", each_pass)

    # Create one with_portal_run_sync() portal per checkpoint, and await_ the checkpoint.
    await timeit("sync portal creations", each_sync_pass)
Beispiel #6
0
 def step():
     await_(checkpoint())
Beispiel #7
0
def sync_busy():
    for _ in range(ITERS):
        await_(checkpoint())