def test_create_key_event_object(self):
     """It should create an evdev object."""
     pipe = mock.MagicMock()
     listener = inputs.BaseListener(pipe)
     eventlist = listener.create_event_object("Key", 30, 1, (100, 0))
     event_info = next(inputs.iter_unpack(eventlist))
     self.assertEqual(event_info, (100, 0, 1, 30, 1))
 def test_create_mouse_event_object(self):
     """It also should create an evdev object."""
     pipe = mock.MagicMock()
     listener = inputs.BaseListener(pipe)
     eventlist = listener.create_event_object("Absolute", 0, 285, (100, 1))
     event_info = next(inputs.iter_unpack(eventlist))
     self.assertEqual(event_info, (100, 1, 3, 0, 285))
 def test_get_timeval(self):
     """Gives seconds and microseconds."""
     pipe = mock.MagicMock()
     listener = inputs.BaseListener(pipe)
     seconds, microseconds = listener.get_timeval()
     self.assertTrue(seconds > 0)
     self.assertTrue(microseconds > 0)
 def test_create_ev_wo_timeval(self):
     """It should create an evdev object."""
     pipe = mock.MagicMock()
     listener = inputs.BaseListener(pipe)
     eventlist = listener.create_event_object("Key", 30, 1)
     event_info = next(inputs.iter_unpack(eventlist))
     self.assertTrue(event_info[0] > 0)
     self.assertTrue(event_info[1] > 0)
     self.assertEqual(event_info[2:], (1, 30, 1))
 def test_write_to_pipe(self):
     """Subprocess sends data back to the class in the mainprocess."""
     pipe = mock.MagicMock()
     listener = inputs.BaseListener(pipe)
     listener.write_to_pipe([b'Green Eggs', b' and ', b'Ham'])
     send_bytes_call = pipe.method_calls[0]
     method_name = send_bytes_call[0]
     args = send_bytes_call[1]
     self.assertEqual(method_name, 'send_bytes')
     self.assertEqual(args[0], b'Green Eggs and Ham')
    def test_emulate_abs(self):
        """Returns absolute mouse event."""
        pipe = mock.MagicMock()
        listener = inputs.BaseListener(pipe)

        x_list, y_list = listener.emulate_abs(1324, 246, (100, 1))
        x_info = next(inputs.iter_unpack(x_list))
        self.assertEqual(x_info, (100, 1, 3, 0, 1324))
        y_info = next(inputs.iter_unpack(y_list))
        self.assertEqual(y_info, (100, 1, 3, 1, 246))
    def test_emulate_wheel_x(self):
        """Returns an event list for the x mouse wheel turn."""
        pipe = mock.MagicMock()
        listener = inputs.BaseListener(pipe)
        eventlist = listener.emulate_wheel(20, 'x', (100, 1))
        event_info = next(inputs.iter_unpack(eventlist))
        self.assertEqual(event_info, (100, 1, 2, 6, 20))

        eventlist = listener.emulate_wheel(-20, 'x', (100, 1))
        event_info = next(inputs.iter_unpack(eventlist))
        self.assertEqual(event_info, (100, 1, 2, 6, -20))
    def test_sync_marker(self):
        """Returns a sync marker."""
        pipe = mock.MagicMock()
        listener = inputs.BaseListener(pipe)

        sync_list = listener.sync_marker((100, 1))
        sync_info = next(inputs.iter_unpack(sync_list))
        self.assertEqual(sync_info, (100, 1, 0, 0, 0))

        sync_list = listener.sync_marker((200, 2))
        sync_info = next(inputs.iter_unpack(sync_list))
        self.assertEqual(sync_info, (200, 2, 0, 0, 0))
    def test_emulate_press_up(self):
        """Returns an event list for button."""
        pipe = mock.MagicMock()
        listener = inputs.BaseListener(pipe)

        scan_list, button_list = listener.emulate_press(
            272, 589825, 0, (100, 1))
        scan_info = next(inputs.iter_unpack(scan_list))
        button_info = next(inputs.iter_unpack(button_list))

        self.assertEqual(scan_info, (100, 1, 4, 4, 589825))
        self.assertEqual(button_info, (100, 1, 1, 272, 0))
    def test_set_timeval(self):
        """Sets the cached timeval."""
        pipe = mock.MagicMock()
        listener = inputs.BaseListener(pipe)

        # We start with no timeval
        self.assertIsNone(listener.timeval)

        # We update the timeval
        listener.update_timeval()
        seconds, microseconds = listener.get_timeval()
        self.assertTrue(seconds > 0)
        self.assertTrue(microseconds > 0)
    def test_emulate_wheel_win(self):
        """Returns an event list for the mouse wheel turn on Windows."""
        inputs.WIN = True
        pipe = mock.MagicMock()
        listener = inputs.BaseListener(pipe)
        eventlist = listener.emulate_wheel(240, 'x', (100, 1))
        event_info = next(inputs.iter_unpack(eventlist))
        self.assertEqual(event_info, (100, 1, 2, 6, 2))

        eventlist = listener.emulate_wheel(-240, 'x', (100, 1))
        event_info = next(inputs.iter_unpack(eventlist))
        self.assertEqual(event_info, (100, 1, 2, 6, -2))
        inputs.WIN = False
    def test_emulate_repeat(self):
        """Returns a repeat event, e.g. doubleclick, triple click."""
        pipe = mock.MagicMock()
        listener = inputs.BaseListener(pipe)

        repeat_list = listener.emulate_repeat(1, (100, 1))
        repeat_info = next(inputs.iter_unpack(repeat_list))
        self.assertEqual(repeat_info, (100, 1, 20, 2, 1))

        repeat_list = listener.emulate_repeat(2, (100, 1))
        repeat_info = next(inputs.iter_unpack(repeat_list))
        self.assertEqual(repeat_info, (100, 1, 20, 2, 2))

        repeat_list = listener.emulate_repeat(3, (100, 1))
        repeat_info = next(inputs.iter_unpack(repeat_list))
        self.assertEqual(repeat_info, (100, 1, 20, 2, 3))
    def test_emulate_rel(self):
        """Returns an event list for relative mouse movement."""
        pipe = mock.MagicMock()
        listener = inputs.BaseListener(pipe)

        eventlist = listener.emulate_rel(0, 1, (100, 1))
        event_info = next(inputs.iter_unpack(eventlist))
        self.assertEqual(event_info, (100, 1, 2, 0, 1))

        eventlist = listener.emulate_rel(0, -5, (100, 1))
        event_info = next(inputs.iter_unpack(eventlist))
        self.assertEqual(event_info, (100, 1, 2, 0, -5))

        eventlist = listener.emulate_rel(1, 44, (100, 1))
        event_info = next(inputs.iter_unpack(eventlist))
        self.assertEqual(event_info, (100, 1, 2, 1, 44))

        eventlist = listener.emulate_rel(1, -10, (100, 1))
        event_info = next(inputs.iter_unpack(eventlist))
        self.assertEqual(event_info, (100, 1, 2, 1, -10))
 def test_create_banana_event_object(self):
     """It should raise an exception."""
     pipe = mock.MagicMock()
     listener = inputs.BaseListener(pipe)
     with self.assertRaises(inputs.UnknownEventType):
         listener.create_event_object("Banana", 0, 285, (100, 1))
 def test_init(self):
     """The listener has type_codes."""
     pipe = mock.MagicMock()
     listener = inputs.BaseListener(pipe)
     self.assertEqual(len(listener.type_codes), 14)