Skip to content

Commit

Permalink
tests: tests for a few simple hidpp20 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed Feb 11, 2024
1 parent 719e0db commit a1d4a41
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/test_hidpp20_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from collections import namedtuple

import logitech_receiver.hidpp20 as hidpp20

response = namedtuple('response', 'response device feature function params')


def feature_request(device, feature, function=0x00, *params, no_reply=False):
global responses
assert len(responses) > 0, f"extra call of feature_request {device}, {feature}, {function}, {params}, {no_reply}"
r = responses[0]
if r.device == device and r.feature == feature and r.function == function and r.params == params:
responses = responses[1:]
return bytes.fromhex(r.response) if r.response is not None else None
raise AssertionError(f"incorrect call of feature_request {device}, {feature}, {function}, {params}, {no_reply}")


def test_set_host_name(mocker): # FIXME
global responses
mocker.patch('logitech_receiver.hidpp20.feature_request', wraps=feature_request)
responses = [response('03FFFFFFFF', None, hidpp20.FEATURE.HOSTS_INFO, 0x00, ())] # FIXME
hidpp20.set_host_name(None, 'THIS IS A LONG HOST NAME')
assert responses == []


def test_get_polling_rate(mocker):
global responses
mocker.patch('logitech_receiver.hidpp20.feature_request', wraps=feature_request)
responses = [response('03FFFF', None, hidpp20.FEATURE.REPORT_RATE, 0x10, ())]
result = hidpp20.get_polling_rate(None)
assert result == '3ms'
assert responses == []
responses = [
response(None, None, hidpp20.FEATURE.REPORT_RATE, 0x10, ()),
response('04FFFF', None, hidpp20.FEATURE.EXTENDED_ADJUSTABLE_REPORT_RATE, 0x20, ())
]
result = hidpp20.get_polling_rate(None)
assert result == '500us'
assert responses == []


def test_get_remaining_pairing(mocker):
global responses
mocker.patch('logitech_receiver.hidpp20.feature_request', wraps=feature_request)
responses = [response('03FFFF', None, hidpp20.FEATURE.REMAINING_PAIRING, 0x0, ())]
result = hidpp20.get_remaining_pairing(None)
assert result == 0x03
assert responses == []

0 comments on commit a1d4a41

Please sign in to comment.