Skip to content

Commit ea45a8a

Browse files
committed
Mock pynput usage for Actions test run
1 parent 28393dd commit ea45a8a

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

kvm_serial/backend/mouse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
import logging
3-
from pynput import mouse
3+
from pynput.mouse import Button, Listener
44
from serial import Serial
55
from screeninfo import get_monitors
66

@@ -11,7 +11,7 @@
1111

1212
class MouseListener:
1313
def __init__(self, serial, block=True):
14-
self.listener = mouse.Listener(
14+
self.listener = Listener(
1515
on_move=self.on_move,
1616
on_click=self.on_click,
1717
on_scroll=self.on_scroll,
@@ -22,9 +22,9 @@ def __init__(self, serial, block=True):
2222
# Mouse movement control character
2323
self.control_chars = {
2424
"NU": b"\x00", # Release
25-
mouse.Button.left: b"\x01", # Left click
26-
mouse.Button.right: b"\x02", # Right click
27-
mouse.Button.middle: b"\x04", # Centre Click
25+
Button.left: b"\x01", # Left click
26+
Button.right: b"\x02", # Right click
27+
Button.middle: b"\x04", # Centre Click
2828
}
2929

3030
# Get screen dimensions
@@ -68,7 +68,7 @@ def on_move(self, x, y):
6868

6969
return True
7070

71-
def on_click(self, x, y, button: mouse.Button, down):
71+
def on_click(self, x, y, button: Button, down):
7272
data = bytearray(b"\x01") # Relative coordinates (0x01)
7373
data += self.control_chars[button] if down else b"\x00" # Mouse button
7474
data += b"\x00\x00" # Rel. mouse position x/y coordinate (2 bytes 0x0)
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
from unittest.mock import patch
1+
from unittest.mock import patch, MagicMock
22

33
from kvm_serial.backend.implementations.pynputop import PynputOp
44
from tests._utilities import MockSerial, mock_serial
55

66

7+
# Mock the entire pynput.keyboard module
8+
@patch("kvm_serial.backend.implementations.pynputop.Key")
9+
@patch("kvm_serial.backend.implementations.pynputop.KeyCode")
10+
@patch("kvm_serial.backend.implementations.pynputop.Listener")
11+
@patch("serial.Serial", MockSerial)
712
class TestPynputOperation:
8-
@patch("serial.Serial", MockSerial)
9-
def test_name_property(self, mock_serial):
13+
def test_name_property(self, mock_serial, mock_listener, mock_keycode):
1014
"""Test that the name property returns 'pynput'"""
1115
op = PynputOp(mock_serial)
1216
assert op.name == "pynput"

tests/backend/test_mouse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55

66
class TestMouse:
7+
@patch("kvm_serial.backend.mouse.Button")
8+
@patch("kvm_serial.backend.mouse.Listener")
79
@patch("serial.Serial", MockSerial)
810
@patch("kvm_serial.backend.mouse.DataComm")
9-
def test_mouse_listener(self, mock_datacomm, mock_serial):
11+
def test_mouse_listener(self, mock_datacomm, mock_serial, mock_button):
1012
"""Test basic MouseListener initialization"""
1113
# Ensure DataComm mock is properly configured
1214
mock_datacomm.return_value = MagicMock()

0 commit comments

Comments
 (0)