예제 #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
예제 #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()])
예제 #3
0
    def shows_data_on_screen_runner(self, contents):
        i = get_mock_input()
        o = get_mock_output()
        cb = Checkbox(contents, i, o, name=cb_name, config={})

        def scenario():
            cb.deactivate()

        with patch.object(cb, 'idle_loop', side_effect=scenario) as p:
            cb.activate()
            #The scenario should only be called once
            assert cb.idle_loop.called
            assert cb.idle_loop.call_count == 1

        assert o.display_data.called
        assert o.display_data.call_count == 1  #One in to_foreground
        assert o.display_data.call_args[0] == (' A0', ' A1', ' A2', ' Accept')
예제 #4
0
    def test_shows_data_on_screen(self):
        """Tests whether the Checkbox outputs data on screen when it's ran"""
        num_elements = 3
        contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)]
        i = get_mock_input()
        o = get_mock_output()
        cb = Checkbox(contents, i, o, name=cb_name, config={})

        def scenario():
            cb.deactivate()

        with patch.object(cb, 'idle_loop', side_effect=scenario) as p:
            cb.activate()
            #The scenario should only be called once
            assert cb.idle_loop.called
            assert cb.idle_loop.call_count == 1

        assert o.display_data.called
        assert o.display_data.call_count == 1  #One in to_foreground
        assert o.display_data.call_args[0] == (' A0', ' A1', ' A2', ' Accept')
예제 #5
0
    def graphical_display_redraw_runner(self, contents):
        o = get_mock_graphical_output()
        cb = Checkbox(contents, get_mock_input(), o, name=cb_name, config={})
        Canvas.fonts_dir = fonts_dir

        # Exiting immediately, but we should get at least one redraw
        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 o.display_image.called
        assert o.display_image.call_count == 1  #One in to_foreground