def test_iaio_number_input(self): overlay = IntegerAdjustInputOverlay() i = get_mock_input() ia = IntegerAdjustInput(0, i, get_mock_output(), name=ui_name) overlay.apply_to(ia) def scenario(): keymap = i.set_keymap.call_args[0][0] keymap["KEY_1"]() assert (ia.number == 1) keymap["KEY_2"]() assert (ia.number == 12) ia.deactivate() assert not ia.in_foreground with patch.object(ia, 'idle_loop', side_effect=scenario) as p: ia.activate()
def test_shows_data_on_screen(self): """Tests whether the IntegerAdjustInput outputs data on screen when it's ran""" i = get_mock_input() o = get_mock_output() ii = IntegerAdjustInput(1, i, o, message="Test:", name=ii_name) def scenario(): assert o.display_data.called assert o.display_data.call_args[0][0].strip() == 'Test:' assert o.display_data.call_args[0][1].strip() == str(1) for i in range(5): execute_shorthand(ii, "u") assert o.display_data.call_args[0][1].strip() == str(i+2) execute_shorthand(ii, "e") assert not ii.in_foreground # Should exit on last "e" with patch.object(ii, 'idle_loop', side_effect=scenario) as p: ii.activate() #The scenario should only be called once assert ii.idle_loop.called assert ii.idle_loop.call_count == 1 assert o.display_data.call_count == 6
def test_left_returns_none(self): ii = IntegerAdjustInput(1, get_mock_input(), get_mock_output(), name=ii_name) ii.refresh = lambda *args, **kwargs: None #not needed # Checking without changing value def scenario(): ii.keymap["KEY_LEFT"]() assert not ii.in_foreground with patch.object(ii, 'idle_loop', side_effect=scenario) as p: return_value = ii.activate() assert return_value is None # Checking after entering some keys test_keys = "u"*5 def scenario(): for key in test_keys: execute_shorthand(ii, key) execute_shorthand(ii, 'l') assert not ii.in_foreground with patch.object(ii, 'idle_loop', side_effect=scenario) as p: return_value = ii.activate() assert return_value is None
def test_entering_value(self): ii = IntegerAdjustInput(1, get_mock_input(), get_mock_output(), name=ii_name) ii.refresh = lambda *args, **kwargs: None plus = 5 minus = 4 expected = 2 def scenario(): for i in range(plus): execute_shorthand(ii, "u") for i in range(minus): execute_shorthand(ii, "d") execute_shorthand(ii, 'e') assert not ii.is_active with patch.object(ii, 'idle_loop', side_effect=scenario) as p: return_value = ii.activate() assert return_value == expected