Example #1
0
def test_get_loop_contexts(context, event_loop):
    with pytest.raises(TaskFactoryError):
        get_loop_contexts(event_loop)
    wrap_task_factory(event_loop)
    assert get_loop_contexts(event_loop) == []
    context.attach(event_loop)
    assert get_loop_contexts(event_loop) == [context]
Example #2
0
def test_unwrap_task_factory_custom(event_loop):
    event_loop.set_task_factory(custom_task_factory)
    wrap_task_factory(event_loop)
    assert _wrapped_task_factory(event_loop)
    unwrap_task_factory(event_loop)
    assert not _wrapped_task_factory(event_loop)
    assert event_loop.get_task_factory() is custom_task_factory
Example #3
0
def test_wrap_task_factory_custom(event_loop):
    event_loop.set_task_factory(custom_task_factory)
    assert not _wrapped_task_factory(event_loop)
    wrap_task_factory(event_loop)
    assert _wrapped_task_factory(event_loop)
    task = event_loop.create_task(asyncio.sleep(1))
    task.cancel()
    assert isinstance(task, CustomTask)
Example #4
0
 def test_detach(self, event_loop):
     wrap_task_factory(event_loop)
     context1 = Context()
     context1.attach(event_loop)
     context2 = Context()
     context2.attach(event_loop)
     assert len(get_loop_contexts(event_loop)) == 2
     context2.detach(event_loop)
     assert len(get_loop_contexts(event_loop)) == 1
     context2.detach(event_loop)
     assert len(get_loop_contexts(event_loop)) == 1
Example #5
0
def test_unwrap_task_factory_many(event_loop):
    wrap_task_factory(event_loop)
    assert _wrapped_task_factory(event_loop)
    for _ in range(3):
        unwrap_task_factory(event_loop)
        assert not _wrapped_task_factory(event_loop)
Example #6
0
def test_unwrap_task_factory(event_loop):
    wrap_task_factory(event_loop)
    assert _wrapped_task_factory(event_loop)
    unwrap_task_factory(event_loop)
    assert not _wrapped_task_factory(event_loop)
Example #7
0
def context_loop(context, event_loop):
    aiocontext.wrap_task_factory(event_loop)
    context.attach(event_loop)
    return event_loop