Пример #1
0
    def test_content_update_maintains_pointers(self):
        """Tests whether the BaseListUIElement outputs data on screen when it's ran"""
        i = get_mock_input()
        o = get_mock_output()

        contents = [["A" + str(x), "a" + str(x)] for x in range(10)]
        el = BaseListUIElement(contents, i, o, name=el_name, config={})

        def scenario():
            for x in range(5):
                el.move_down()

            # Now, we should be on element "A3"
            assert o.display_data.called
            assert o.display_data.call_count == 6 # 1 in to_foreground, 5 in move_down
            assert o.display_data.call_args[0] == ('A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7')

            # Setting shorter contents and scrolling some more
            el.set_contents([["A" + str(x), "a" + str(x)] for x in range(3)])
            el.move_up()
            for x in range(3):
                el.move_down()
            assert o.display_data.call_count == 6 + 2 # 1 in move_up, 3 in move_down but 2 didn't work
            assert o.display_data.call_args[0] == ('A0', 'A1', 'A2', 'Back')

            el.deactivate()
            assert not el.is_active

        with patch.object(el, 'idle_loop', side_effect=scenario) as p:
            el.activate()
Пример #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)]
        el = BaseListUIElement(contents, get_mock_input(), get_mock_output(), name=el_name, config={})
        el.refresh = lambda *args, **kwargs: None

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

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

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

        with patch.object(el, 'idle_loop', side_effect=scenario) as p:
            return_value = el.activate()
        assert return_value is None
Пример #3
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)]
        el = BaseListUIElement(contents, get_mock_input(), get_mock_output(), name=el_name, config={})
        el.refresh = lambda *args, **kwargs: None

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

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

        with patch.object(el, 'idle_loop', side_effect=scenario) as p:
            return_value = el.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()])
Пример #4
0
 def test_properties(self):
     """tests in_background property"""
     element = BaseListUIElement([["Option", "option"]], get_mock_input(), get_mock_output(), name=el_name, config={})
     assert(element.in_background == False)
     assert(not element._in_background.isSet())
     element.in_background = True
     assert(element.in_background == True)
     assert(element._in_background.isSet())
Пример #5
0
 def test_exit_label_leakage(self):
     """tests whether the exit label of one BaseListUIElement leaks into another"""
     i = get_mock_input()
     o = get_mock_output()
     c1 = BaseListUIElement([["a", "1"]], i, o, name=el_name + "1", final_button_name="Name1", config={})
     c2 = BaseListUIElement([["b", "2"]], i, o, name=el_name + "2", final_button_name="Name2", config={})
     c3 = BaseListUIElement([["c", "3"]], i, o, name=el_name + "3", config={})
     assert (c1.exit_entry != c2.exit_entry)
     assert (c2.exit_entry != c3.exit_entry)
     assert (c1.exit_entry != c3.exit_entry)
Пример #6
0
    def graphical_display_redraw_runner(self, contents):
        o = get_mock_graphical_output()
        el = BaseListUIElement(contents, get_mock_input(), o, name=el_name, config={})
        Canvas.fonts_dir = fonts_dir
        # Exiting immediately, but we should get at least one redraw
        def scenario():
            el.deactivate()  # KEY_LEFT
            assert not el.is_active

        with patch.object(el, 'idle_loop', side_effect=scenario) as p:
            el.activate()
        assert o.display_image.called
        assert o.display_image.call_count == 1 #One in to_foreground
Пример #7
0
 def test_constructor(self):
     """tests constructor"""
     element = BaseListUIElement([["Option", "option"]],
                                 get_mock_input(),
                                 get_mock_output(),
                                 name=el_name,
                                 config={})
     self.assertIsNotNone(element)
Пример #8
0
    def test_append_exit_works(self):
        """
        Tests whether the BaseListUIElement stops appending "Exit" when append_exit
        is set to false.
        """
        contents = [["A" + str(i), "a" + str(i)] for i in range(3)]
        i = get_mock_input()
        o = get_mock_output()
        el = BaseListUIElement(contents, i, o, name=el_name, append_exit=False, config={})

        def scenario():
            el.deactivate()
            assert not el.is_active

        with patch.object(el, 'idle_loop', side_effect=scenario) as p:
            el.activate()

        assert o.display_data.call_args[0] == ('A0', 'A1', 'A2')
Пример #9
0
    def shows_data_on_screen_runner(self, contents):
        i = get_mock_input()
        o = get_mock_output()
        el = BaseListUIElement(contents, i, o, name=el_name, config={})

        def scenario():
            el.deactivate()
            assert not el.is_active

        with patch.object(el, 'idle_loop', side_effect=scenario) as p:
            el.activate()
            #The scenario should only be called once
            assert el.idle_loop.called
            assert el.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', 'Back')
Пример #10
0
    def test_pagedown_pageup_refresh_once(self):
        """Tests whether the BaseListUIElement page_down and page_up only refresh the screen once."""
        num_elements = 20
        contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)]
        i = get_mock_input()
        o = get_mock_output()
        el = BaseListUIElement(contents, i, o, name=el_name, config={})

        def scenario():
            assert o.display_data.call_count == 1 #One in to_foreground
            el.page_down()
            assert o.display_data.call_count == 2 #One more
            el.page_up()
            assert o.display_data.call_count == 3 #And one more
            el.deactivate()
            assert not el.is_active

        with patch.object(el, 'idle_loop', side_effect=scenario) as p:
            el.activate()
Пример #11
0
 def test_keymap(self):
     """tests keymap"""
     element = BaseListUIElement([["Option", "option"]],
                                 get_mock_input(),
                                 get_mock_output(),
                                 name=el_name,
                                 config={})
     self.assertIsNotNone(element.keymap)
     for key_name, callback in element.keymap.iteritems():
         self.assertIsNotNone(callback)
Пример #12
0
    def test_shows_data_on_screen(self):
        """Tests whether the BaseListUIElement 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()
        el = BaseListUIElement(contents, i, o, name=el_name, config={})

        def scenario():
            el.deactivate()

        with patch.object(el, 'idle_loop', side_effect=scenario) as p:
            el.activate()
            #The scenario should only be called once
            assert el.idle_loop.called
            assert el.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', 'Back')
Пример #13
0
    def test_graphical_display_redraw(self):
        num_elements = 3
        o = get_mock_graphical_output()
        contents = [["A" + str(i), "a" + str(i)] for i in range(num_elements)]
        el = BaseListUIElement(contents,
                               get_mock_input(),
                               o,
                               name=el_name,
                               config={})
        Canvas.fonts_dir = fonts_dir

        # Exiting immediately, but we should get at least one redraw
        def scenario():
            el.deactivate()  # KEY_LEFT
            assert not el.in_foreground

        with patch.object(el, 'idle_loop', side_effect=scenario) as p:
            return_value = el.activate()
        assert o.display_image.called
        assert o.display_image.call_count == 1  #One in to_foreground