Exemplo n.º 1
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)]
        mu = Menu(contents,
                  get_mock_input(),
                  get_mock_output(),
                  name=mu_name,
                  config={})
        mu.refresh = lambda *args, **kwargs: None

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

        with patch.object(mu, 'idle_loop', side_effect=scenario) as p:
            return_value = mu.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):
                mu.move_down()  # KEY_DOWN x3
            mu.select_entry()  # KEY_ENTER
            assert not mu.in_foreground

        with patch.object(mu, 'idle_loop', side_effect=scenario) as p:
            return_value = mu.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()])
Exemplo n.º 2
0
    def test_left_key_returns_none(self):
        num_elements = 3
        contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)]
        mu = Menu(contents,
                  get_mock_input(),
                  get_mock_output(),
                  name=mu_name,
                  config={})
        mu.refresh = lambda *args, **kwargs: None

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

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

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

        with patch.object(mu, 'idle_loop', side_effect=scenario) as p:
            return_value = mu.activate()
        assert return_value is None
Exemplo n.º 3
0
    def test_left_key_disabled_when_not_exitable(self):
        """Tests whether a menu does not 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)]
        mu = Menu(contents,
                  get_mock_input(),
                  get_mock_output(),
                  name=mu_name,
                  exitable=False,
                  config={})
        mu.refresh = lambda *args, **kwargs: None

        def scenario():
            assert "KEY_LEFT" not in mu.keymap  # KEY_LEFT
            mu.deactivate()
            assert not mu.in_foreground

        with patch.object(mu, 'idle_loop', side_effect=scenario) as p:
            mu.activate()
Exemplo n.º 4
0
    def callback_is_executed_wrapper(self, contents, cb1, cb2):
        mu = Menu(contents,
                  get_mock_input(),
                  get_mock_output(),
                  name=mu_name,
                  config={})
        mu.refresh = lambda *args, **kwargs: None

        # Checking at other elements - shouldn't return
        def scenario():
            mu.select_entry()  # KEY_ENTER
            assert cb1.called
            assert mu.in_foreground
            mu.move_down()  # KEY_DOWN
            mu.select_entry()  # KEY_ENTER
            assert cb2.called
            assert mu.in_foreground
            mu.deactivate(
            )  # because is not deactivated yet and would idle loop otherwise
            assert not mu.in_foreground

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