Ejemplo n.º 1
0
def test_loop_run_until_complete_when_set_is_running(loop: GLibEventLoop):
    loop.set_is_running(True)

    future = asyncio.Future(loop=loop)

    with raises(RuntimeError):
        loop.run_until_complete(future)
Ejemplo n.º 2
0
def test_loop_run_forever_after_toggle_set_is_running(loop: GLibEventLoop):
    loop.set_is_running(True)
    loop.set_is_running(False)

    idle_add(loop.context, loop.stop)

    loop.run_forever()
Ejemplo n.º 3
0
def test_loop_set_is_running(loop: GLibEventLoop):
    assert not loop.is_running()

    loop.set_is_running(True)
    assert asyncio.get_running_loop() is loop

    assert loop.is_running()
Ejemplo n.º 4
0
def test_loop_set_is_running_when_not_owner():
    from aioglib._loop import GLibEventLoop

    context = MockMainContext(is_owner=False)
    loop = GLibEventLoop(context)

    with raises(RuntimeError):
        loop.set_is_running(True)
Ejemplo n.º 5
0
def test_loop_set_is_not_running(loop: GLibEventLoop):
    old_loop = Mock()
    asyncio._set_running_loop(old_loop)

    loop.set_is_running(True)
    loop.set_is_running(False)
    assert not loop.is_running()

    assert asyncio.get_running_loop() is old_loop
Ejemplo n.º 6
0
def test_loop_set_is_running_acquires_context():
    from gi.repository.GLib import MainLoop as MockMainLoop
    from aioglib._loop import GLibEventLoop

    mock_context = MockMainContext()
    loop = GLibEventLoop(mock_context)

    MockMainLoop().is_running.return_value = False

    loop.set_is_running(True)

    assert mock_context.acquire_count > 0
Ejemplo n.º 7
0
def test_loop_run_forever_when_set_is_running(loop: GLibEventLoop):
    loop.set_is_running(True)

    with raises(RuntimeError):
        loop.run_forever()