diff --git a/lib/hidapi/hidapi_impl.py b/lib/hidapi/hidapi_impl.py index 9e04153a21..062e47e7d9 100644 --- a/lib/hidapi/hidapi_impl.py +++ b/lib/hidapi/hidapi_impl.py @@ -171,7 +171,7 @@ class HIDError(Exception): pass -def _enumerate_devices(): +def _enumerate_devices() -> list: """Returns all HID devices which are potentially useful to us""" devices = [] c_devices = _hidapi.hid_enumerate(0, 0) @@ -201,7 +201,7 @@ def _enumerate_devices(): # Use a separate thread to check if devices have been removed or connected -class _DeviceMonitor(Thread): +class DeviceMonitor(Thread): def __init__(self, device_callback, polling_delay=5.0): self.device_callback = device_callback self.polling_delay = polling_delay @@ -359,11 +359,11 @@ def device_callback(action: str, device): # Removed devices will be detected by Solaar directly pass - monitor = _DeviceMonitor(device_callback=device_callback) + monitor = DeviceMonitor(device_callback=device_callback) monitor.start() -def enumerate(filter_func) -> DeviceInfo: +def enumerate(filter_func: Callable) -> DeviceInfo: """Enumerate the HID Devices. List all the HID devices attached to the system, optionally filtering by diff --git a/tests/integrationtests/test_device_monitor.py b/tests/integrationtests/test_device_monitor.py new file mode 100644 index 0000000000..699fd6c9f1 --- /dev/null +++ b/tests/integrationtests/test_device_monitor.py @@ -0,0 +1,25 @@ +import platform +import time + +import pytest + + +@pytest.mark.skipif(platform.system() == "Linux", reason="Test for non Linux platforms") +def test_device_monitor(mocker): + from hidapi.hidapi_impl import DeviceMonitor + + mock_callback = mocker.Mock() + monitor = DeviceMonitor(device_callback=mock_callback, polling_delay=1) + monitor.start() + + while not monitor.is_alive(): + time.sleep(0.1) + + assert monitor.alive + + monitor.stop() + + while monitor.is_alive(): + time.sleep(0.1) + + assert not monitor.alive diff --git a/tests/integrationtests/test_events_listener.py b/tests/integrationtests/test_events_listener.py new file mode 100644 index 0000000000..8c08c85ae6 --- /dev/null +++ b/tests/integrationtests/test_events_listener.py @@ -0,0 +1,16 @@ +from logitech_receiver.listener import EventsListener + + +def test_events_listener(mocker): + receiver = mocker.MagicMock() + status_callback = mocker.MagicMock() + + e = EventsListener(receiver, status_callback) + e.start() + + assert bool(e) + + e.stop() + + assert not bool(e) + assert status_callback.call_count == 0 diff --git a/tests/integrationtests/test_solaar_listener.py b/tests/integrationtests/test_solaar_listener.py new file mode 100644 index 0000000000..166d601b07 --- /dev/null +++ b/tests/integrationtests/test_solaar_listener.py @@ -0,0 +1,15 @@ +from solaar.listener import SolaarListener + + +def test_solaar_listener(mocker): + receiver = mocker.MagicMock() + receiver.handle = 1 + receiver.path = "dsda" + status_callback = mocker.MagicMock() + + rl = SolaarListener(receiver, status_callback) + # rl.run() + # rl.stop() + + assert not rl.is_alive() + assert status_callback.call_count == 0 diff --git a/tests/integrationtests/test_task_runner.py b/tests/integrationtests/test_task_runner.py new file mode 100644 index 0000000000..0ff7c3e894 --- /dev/null +++ b/tests/integrationtests/test_task_runner.py @@ -0,0 +1,15 @@ +from solaar import tasks + + +def run_task(): + print("Hi!") + + +def test_task_runner(mocker): + tr = tasks.TaskRunner(name="Testrunner") + tr.queue.put((run_task, {}, {})) + # tr.run() + # tr.stop() + # assert tr.alive + # tr.stop() + # assert not tr.alive