示例#1
0
    def test_entering_value(self):
        ni = NumpadCharInput(get_mock_input(), get_mock_output(), name=ni_name)
        ni.refresh = lambda *args, **kwargs: None

        #Defining a key sequence to be tested
        key_sequence = [
            4, 4, 3, 3, 5, 5, 5, "RIGHT", 5, 5, 5, 6, 6, 6, "ENTER"
        ]
        expected_output = "hello"

        def scenario():
            for key in key_sequence:
                ni.process_streaming_keycode("KEY_{}".format(key))
            assert not ni.in_foreground  # Should not be active

        with patch.object(ni, 'idle_loop', side_effect=scenario) as p:
            return_value = ni.activate()
        assert return_value == expected_output
示例#2
0
    def test_f1_left_returns_none(self):
        ni = NumpadCharInput(get_mock_input(), get_mock_output(), name=ni_name)
        ni.refresh = lambda *args, **kwargs: None  #not needed

        # Checking at the start of the list
        def scenario():
            ni.process_streaming_keycode("KEY_LEFT")
            assert not ni.in_foreground

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

        # Checking at the end of the list
        def scenario():
            for i in range(3):
                ni.process_streaming_keycode("KEY_1")
            ni.process_streaming_keycode("KEY_F1")
            assert not ni.in_foreground

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