From 6c8661f13806ab75b15fd3c03f10a210a285d1ec Mon Sep 17 00:00:00 2001 From: Matthias Hagmann <16444067+MattHag@users.noreply.github.com> Date: Thu, 29 Feb 2024 00:52:48 +0100 Subject: [PATCH] tests: Add hidpp10 tests Related #1097 --- setup.py | 2 +- tests/logitech_receiver/test_hidpp10.py | 42 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/logitech_receiver/test_hidpp10.py diff --git a/setup.py b/setup.py index 9b40ddce68..80e26e8b16 100755 --- a/setup.py +++ b/setup.py @@ -86,7 +86,7 @@ def _data_files(): "report-descriptor": ["hid-parser"], "desktop-notifications": ["Notify (>= 0.7)"], "git-commit": ["python-git-info"], - "test": ["pytest", "pytest-cov"], + "test": ["pytest", "pytest-mock", "pytest-cov"], "dev": ["ruff"], }, package_dir={"": "lib"}, diff --git a/tests/logitech_receiver/test_hidpp10.py b/tests/logitech_receiver/test_hidpp10.py new file mode 100644 index 0000000000..955c20701b --- /dev/null +++ b/tests/logitech_receiver/test_hidpp10.py @@ -0,0 +1,42 @@ +import pytest + +from logitech_receiver import hidpp10, hidpp10_constants + + +class FakeDevice: + kind = "fake" + online = True + registers = [hidpp10_constants.REGISTERS.three_leds] + + def request(self, *params): + return b"fake request" + + def read_register(self, register_number, *params): + return "fake register" + + +@pytest.fixture +def setup_hidpp10(): + device = FakeDevice() + hid = hidpp10.Hidpp10() + + yield device, hid + + +def test_hidpp10(setup_hidpp10): + device, hid = setup_hidpp10 + + firmwares = hid.get_firmware(device) + + assert len(firmwares) == 3 + for firmware in firmwares: + assert firmware.kind in ["Firmware", "Bootloader", "Other"] + + +def test_set_3leds(setup_hidpp10, mocker): + device, hid = setup_hidpp10 + spy_write_register = mocker.spy(hidpp10, "write_register") + + hid.set_3leds(device) + + spy_write_register.assert_called_once_with(device, hidpp10_constants.REGISTERS.three_leds, 17, 17)