示例#1
0
async def test_spawn_task() -> None:
    # GIVEN
    mainloop = mock.Mock(name="MainLoop")
    mainloop.screen._palette = {}
    screen = ScreenManagerImpl(mainloop)
    act1 = ActivityStub("Main Activity")
    screen.push_activity(act1)

    log: List[str] = []

    async def infinite_loop() -> None:
        log.append("started")
        while True:
            try:
                await asyncio.sleep(0.1)
            except asyncio.CancelledError:
                log.append("cancelled")
                raise

    # WHEN
    screen.spawn_task(act1, infinite_loop())
    await asyncio.sleep(0)

    # THEN
    assert log == ["started"]

    # WHEN
    screen.pop_activity()
    await asyncio.sleep(0)

    # THEN
    assert log == ["started", "cancelled"]
示例#2
0
def test_pop_activity() -> None:
    # GIVEN
    # Create a basic palette and an urwid main loop - we are messing with the internal
    # implementation of palette handling.
    urwid_mock = UrwidMock()
    palette = [
        ("text", "white", "black", ""),
    ]
    asyncioloop = asyncio.get_event_loop()
    evl = urwid.AsyncioEventLoop(loop=asyncioloop)
    mainloop = urwid.MainLoop(None, palette=palette, event_loop=evl)

    screen = ScreenManagerImpl(mainloop)
    act1 = ActivityStub("Activity One")
    act2 = ActivityStub("Activity Two")
    screen.push_activity(act1)
    screen.push_activity(act2)

    assert "Activity Two" in urwid_mock.render(mainloop.widget)

    # WHEN
    screen.pop_activity()

    # THEN
    assert "Activity One" in urwid_mock.render(mainloop.widget)
    assert act2.activated == 1
    assert act2.destroyed == 1
    assert act2.shown == 1
    assert act2.hidden == 1

    assert act1.activated == 1
    assert act1.shown == 2
    assert act1.hidden == 1
示例#3
0
def test_pop_activity() -> None:
    mainloop = mock.Mock(name="MainLoop")
    mainloop.screen._palette = {}
    screen = ScreenManagerImpl(mainloop)
    act1 = ActivityStub("Activity One")
    act2 = ActivityStub("Activity Two")
    screen.push_activity(act1)
    screen.push_activity(act2)

    assert "Activity Two" in _render(mainloop.widget)

    # WHEN
    screen.pop_activity()

    # THEN
    assert "Activity One" in _render(mainloop.widget)
    assert act2.activated == 1
    assert act2.destroyed == 1
    assert act2.shown == 1
    assert act2.hidden == 1

    assert act1.activated == 1
    assert act1.shown == 2
    assert act1.hidden == 1