def test__return_value():
    import asyncgui as ag

    task = ag.Task(ag.sleep_forever())
    gen_based_coro = ag.sleep_forever()
    coro = async_fn()

    assert ag.start(task) is task
    for v in (gen_based_coro, coro):
        assert isinstance(ag.start(v), ag.Task)
def test__already_started():
    import asyncgui as ag
    task1 = ag.start(ag.sleep_forever())
    task2 = ag.start(async_fn())
    for task in (task1, task2):
        with pytest.raises(ValueError):
            ag.start(task)
def test_cancel_without_start():
    from inspect import getcoroutinestate, CORO_CLOSED
    import asyncgui as ag
    task = ag.Task(ag.sleep_forever())
    task.cancel()
    assert task.cancelled
    assert task._exception is None
    assert getcoroutinestate(task.root_coro) == CORO_CLOSED
Exemple #4
0
def test_cancel_all_children():
    import asyncgui as ag
    from asyncgui.structured_concurrency import or_
    TS = ag.TaskState

    async def main():
        tasks = await or_(child1, child2)
        for task in tasks:
            assert task.cancelled

    child1 = ag.Task(ag.sleep_forever())
    child2 = ag.Task(ag.sleep_forever())
    main_task = ag.start(main())
    assert main_task.state is TS.STARTED
    child1.cancel()
    assert main_task.state is TS.STARTED
    child2.cancel()
    assert main_task.state is TS.DONE
def test_weakref():
    import weakref
    import asyncgui as ag
    task = ag.Task(ag.sleep_forever())
    weakref.ref(task)
    task.cancel()
Exemple #6
0
 async def main():
     await or_(ag.sleep_forever(), ag.sleep_forever())
     pytest.fail()