def test_left_key_returns_none(self): """ A Listbox shouldn't return anything when LEFT is pressed""" num_elements = 3 contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)] lb = Listbox(contents, get_mock_input(), get_mock_output(), name=lb_name, config={}) lb.refresh = lambda *args, **kwargs: None # Checking at the start of the list def scenario(): lb.deactivate() # KEY_LEFT assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value is None # Checking at the end of the list def scenario(): for i in range(num_elements): lb.move_down() # KEY_DOWN x3 lb.deactivate() # KEY_LEFT assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value is None
def returns_on_enter_runner(self, contents, num_elements, exp_return1, exp_return2): lb = Listbox(contents, get_mock_input(), get_mock_output(), name=lb_name, config={}) lb.refresh = lambda *args, **kwargs: None # Checking at the start of the list def scenario(): lb.select_entry() # KEY_ENTER assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value == exp_return1 # Checking at the end of the list def scenario(): for i in range(num_elements - 1): lb.move_down() # KEY_DOWN x2 lb.select_entry() # KEY_ENTER assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value == exp_return2
def selected_single_el_entry_runner(self, contents, selected): lb = Listbox(contents, get_mock_input(), get_mock_output(), selected=selected, name=lb_name, config={}) lb.refresh = lambda *args, **kwargs: None # Checking at the start of the list def scenario(): lb.select_entry() # KEY_ENTER assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: return_value = lb.activate() assert return_value == selected
def test_left_key_works_when_not_exitable(self): """Listbox should still exit on KEY_LEFT when exitable is set to False""" num_elements = 3 contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)] lb = Listbox(contents, get_mock_input(), get_mock_output(), name=lb_name, config={}) lb.refresh = lambda *args, **kwargs: None def scenario(): assert "KEY_LEFT" in lb.keymap lb.deactivate() assert not lb.in_foreground with patch.object(lb, 'idle_loop', side_effect=scenario) as p: lb.activate()