def test_f1_left_returns_none(self): ci = CharArrowKeysInput(get_mock_input(), get_mock_output(), name=ci_name) ci.refresh = lambda *args, **kwargs: None #not needed # Checking at the start of the list def scenario(): ci.keymap["KEY_LEFT"]() assert not ci.in_foreground with patch.object(ci, 'idle_loop', side_effect=scenario) as p: return_value = ci.activate() assert return_value is None # Checking after entering some keys letters_entered = 5 test_keys = "ur"*letters_entered def scenario(): for key in test_keys: execute_shorthand(ci, key) for i in range(letters_entered): execute_shorthand(ci, 'l') assert ci.in_foreground #Not yet at the beginning of the value execute_shorthand(ci, 'l') assert not ci.in_foreground #At the beginning of the value with patch.object(ci, 'idle_loop', side_effect=scenario) as p: return_value = ci.activate() assert return_value is None
def test_entering_value(self): ci = CharArrowKeysInput(get_mock_input(), get_mock_output(), name=ci_name) ci.refresh = lambda *args, **kwargs: None expected_output = "hello" test_key_offsets = (8, 5, 12, 12, 15) test_keys = "r".join(["u"*offset for offset in test_key_offsets]) test_keys += "e" #Press ENTER def scenario(): for key in test_keys: execute_shorthand(ci, key) assert not ci.in_foreground # Should exit on last "e" with patch.object(ci, 'idle_loop', side_effect=scenario) as p: return_value = ci.activate() assert return_value == expected_output
def test_entering_value_with_backspaces(self): ci = CharArrowKeysInput(get_mock_input(), get_mock_output(), name=ci_name) ci.refresh = lambda *args, **kwargs: None expected_output = "hello" test_key_offsets = (8, 5, 12, 12, 15) test_keys = "r".join(["u"*offset for offset in test_key_offsets]) test_keys += "d"*(test_key_offsets[-1]+1) #Going back to the backspace character test_keys += "lr" #should erase the latest character and go to the position it took test_keys += "u"*test_key_offsets[-1] #adding the latest character again test_keys += "e" #Press ENTER def scenario(): for key in test_keys: execute_shorthand(ci, key) assert not ci.in_foreground # Should exit on last "e" with patch.object(ci, 'idle_loop', side_effect=scenario) as p: return_value = ci.activate() assert return_value == expected_output