tests: expand tests for settings_templates

This commit is contained in:
Peter F. Patel-Schneider 2024-03-31 07:20:07 -04:00
parent c7a2f1698b
commit 9bb2a1ff5c
2 changed files with 38 additions and 9 deletions

View File

@ -233,6 +233,16 @@ responses_gestures = [ # the commented-out messages are not used by either the
Response("000180FF", 0x0480, "000180FF"), # write param 0 Response("000180FF", 0x0480, "000180FF"), # write param 0
] ]
responses_speedchange = [
Response("0100", 0x0400),
Response("0120", 0x0410, "0120"),
Response("050001", 0x0000, "1B04"), # REPROG_CONTROLS_V4
Response("01", 0x0500),
Response("00ED009D310003070500000000000000", 0x0510, "00"), # DPI Change
Response("00ED0000000000000000000000000000", 0x0520, "00ED"), # DPI Change current
Response("060000", 0x0000, "2205"), # POINTER_SPEED
]
# A fake device that uses provided data (responses) to respond to HID++ commands. # A fake device that uses provided data (responses) to respond to HID++ commands.
# Some methods from the real device are used to set up data structures needed for settings # Some methods from the real device are used to set up data structures needed for settings
@ -248,7 +258,6 @@ class Device:
version: Optional[int] = 0 version: Optional[int] = 0
wpid: Optional[str] = "0000" wpid: Optional[str] = "0000"
setting_callback: Any = None setting_callback: Any = None
settings = []
sliding = profiles = _backlight = _keys = _remap_keys = _led_effects = _gestures = None sliding = profiles = _backlight = _keys = _remap_keys = _led_effects = _gestures = None
_gestures_lock = threading.Lock() _gestures_lock = threading.Lock()
@ -263,6 +272,7 @@ class Device:
def __post_init__(self): def __post_init__(self):
self.persister = configuration._DeviceEntry() self.persister = configuration._DeviceEntry()
self.settings = []
if self.feature is not None: if self.feature is not None:
self.features = hidpp20.FeaturesArray(self) self.features = hidpp20.FeaturesArray(self)
self.responses = [Response("010001", 0x0000, "0001"), Response("20", 0x0100)] + self.responses self.responses = [Response("010001", 0x0000, "0001"), Response("20", 0x0100)] + self.responses

View File

@ -25,12 +25,13 @@ import pytest
from logitech_receiver import common from logitech_receiver import common
from logitech_receiver import hidpp20 from logitech_receiver import hidpp20
from logitech_receiver import hidpp20_constants
from logitech_receiver import settings_templates from logitech_receiver import settings_templates
from logitech_receiver import special_keys from logitech_receiver import special_keys
from . import hidpp from . import hidpp
# TODO action part of DpiSlidingXY, MouseGesturesXY, SpeedChange # TODO action part of DpiSlidingXY, MouseGesturesXY
class Setup: class Setup:
@ -457,13 +458,7 @@ simple_tests = [
Setup( Setup(
FeatureTest(settings_templates.SpeedChange, 0, None, 0), # need to set up all settings to successfully write FeatureTest(settings_templates.SpeedChange, 0, None, 0), # need to set up all settings to successfully write
common.NamedInts(**{"Off": 0, "DPI Change": 0xED}), common.NamedInts(**{"Off": 0, "DPI Change": 0xED}),
hidpp.Response("040001", 0x0000, "2205"), # POINTER_SPEED *hidpp.responses_speedchange,
hidpp.Response("0100", 0x0400),
hidpp.Response("0120", 0x0410, "0120"),
hidpp.Response("050001", 0x0000, "1B04"), # REPROG_CONTROLS_V4
hidpp.Response("01", 0x0500),
hidpp.Response("00ED009D310003070500000000000000", 0x0510, "00"), # DPI Change
hidpp.Response("00ED0000000000000000000000000000", 0x0520, "00ED"), # DPI Change current
), ),
] ]
@ -716,6 +711,30 @@ def test_key_template(test, mocker):
hidpp.match_requests(tst.matched_calls, test.responses, spy_request.call_args_list) hidpp.match_requests(tst.matched_calls, test.responses, spy_request.call_args_list)
@pytest.mark.parametrize(
"responses, currentSpeed, newSpeed",
[
(hidpp.responses_speedchange, 100, 200),
(hidpp.responses_speedchange, None, 250),
],
)
def test_SpeedChange_action(responses, currentSpeed, newSpeed, mocker):
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.POINTER_SPEED)
spy_setting_callback = mocker.spy(device, "setting_callback")
settings_templates.check_feature_settings(device, device.settings) # need to set up all the settings
device.persister = {"pointer_speed": currentSpeed, "_speed-change": newSpeed}
speed_setting = next(filter(lambda s: s.name == "speed-change", device.settings), None)
pointer_setting = next(filter(lambda s: s.name == "pointer_speed", device.settings), None)
speed_setting.write(237)
speed_setting._rw.press_action()
if newSpeed is not None and speed_setting is not None:
spy_setting_callback.assert_any_call(device, type(pointer_setting), [newSpeed])
assert device.persister["_speed-change"] == currentSpeed
assert device.persister["pointer_speed"] == newSpeed
@pytest.mark.parametrize("test", simple_tests + key_tests) @pytest.mark.parametrize("test", simple_tests + key_tests)
def test_check_feature_settings(test, mocker): def test_check_feature_settings(test, mocker):
tst = test.test tst = test.test