-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor get_receiver_info. Replacing data structure of known receivers to avoid for loop, when an efficient dictionary lookup is possible. Related #2273
- Loading branch information
Showing
2 changed files
with
81 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
|
||
from logitech_receiver import base_usb | ||
from logitech_receiver.common import LOGITECH_VENDOR_ID | ||
|
||
|
||
def test_ensure_known_receivers_mappings_are_valid(): | ||
for key, receiver in base_usb.KNOWN_RECEIVERS.items(): | ||
assert key == receiver["product_id"] | ||
|
||
|
||
def test_get_receiver_info(): | ||
expected = { | ||
"vendor_id": LOGITECH_VENDOR_ID, | ||
"product_id": 0xC548, | ||
"usb_interface": 2, | ||
"name": "Bolt Receiver", | ||
"receiver_kind": "bolt", | ||
"max_devices": 6, | ||
"may_unpair": True, | ||
} | ||
|
||
res = base_usb.get_receiver_info(0xC548) | ||
|
||
assert res == expected | ||
|
||
|
||
def test_get_receiver_info_unknown_device_fails(): | ||
with pytest.raises(ValueError): | ||
base_usb.get_receiver_info(0xC500) |