def test_push_dialog() -> None: # GIVEN mainloop = mock.Mock(name="MainLoop") mainloop.screen._palette = {} screen = ScreenManagerImpl(mainloop) act1 = ActivityStub("Main Activity") screen.push_activity(act1) # WHEN dialog = screen.push_dialog("Dialog Title", urwid.Text("Dialog content")) dialog.add_button("Nevermind", lambda: False) dialog.add_button("Close", lambda: True) # THEN view = _render(mainloop.widget) assert "Dialog Title" in view assert "Dialog content" in view assert "Close" in view assert "Nevermind" in view # WHEN # Click the default button (Nevermind) _keypress(mainloop.widget, ["enter"]) # THEN # Dialog did not close assert "Dialog Title" in _render(mainloop.widget) # WHEN # Click the "close" button _keypress(mainloop.widget, ["right", "enter"]) # THEN # Dialog closed assert "Dialog Title" not in _render(mainloop.widget)
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"]
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
def test_push_activity() -> None: mainloop = mock.Mock(name="MainLoop") screen = ScreenManagerImpl(mainloop) act = ActivityStub("Stub Activity") # WHEN screen.push_activity(act) # THEN act.activated == 1 view = _render(mainloop.widget) assert "Stub Activity" in view
def test_push_modal() -> None: mainloop = mock.Mock(name="MainLoop") mainloop.screen._palette = {} screen = ScreenManagerImpl(mainloop) act1 = ActivityStub("Activity One") screen.push_activity(act1) # WHEN screen.push_modal( ActivityStub("Modal Activity"), protocol.ModalOptions(align="center", width=20, valign="top", height=3), ) # THEN # Modal activity does not obscure the main view view = _render(mainloop.widget) assert "Modal Activity" in view assert "Activity One" in view
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