Exemplo n.º 1
0
    def test_left_key_returns_none(self):
        num_elements = 3
        contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)]
        cb = Checkbox(contents,
                      get_mock_input(),
                      get_mock_output(),
                      name=cb_name,
                      config={})
        cb.refresh = lambda *args, **kwargs: None

        # Checking at the start of the list
        def scenario():
            cb.deactivate()  # KEY_LEFT
            assert not cb.in_foreground

        with patch.object(cb, 'idle_loop', side_effect=scenario) as p:
            return_value = cb.activate()
        assert return_value is None

        # Checking at the end of the list
        def scenario():
            for i in range(num_elements):
                cb.move_down()  # KEY_DOWN x3
            cb.deactivate()  # KEY_LEFT
            assert not cb.in_foreground

        with patch.object(cb, 'idle_loop', side_effect=scenario) as p:
            return_value = cb.activate()
        assert return_value is None
Exemplo n.º 2
0
    def test_enter_on_last_returns_right(self):
        num_elements = 3
        contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)]
        cb = Checkbox(contents,
                      get_mock_input(),
                      get_mock_output(),
                      name=cb_name,
                      config={})
        cb.refresh = lambda *args, **kwargs: None

        # Checking at other elements - shouldn't return
        def scenario():
            cb.select_entry()  # KEY_ENTER
            assert cb.in_foreground  # Should still be active
            cb.deactivate(
            )  # because is not deactivated yet and would idle loop otherwise

        with patch.object(cb, 'idle_loop', side_effect=scenario) as p:
            return_value = cb.activate()
        assert return_value is None

        # Scrolling to the end of the list and pressing Enter - should return a correct dict
        def scenario():
            for i in range(num_elements):
                cb.move_down()  # KEY_DOWN x3
            cb.select_entry()  # KEY_ENTER
            assert not cb.in_foreground

        with patch.object(cb, 'idle_loop', side_effect=scenario) as p:
            return_value = cb.activate()
        assert isinstance(return_value, dict)
        assert all(
            [isinstance(key, basestring) for key in return_value.keys()])
        assert all(
            [isinstance(value, bool) for value in return_value.values()])