test: Test base product information

* test: Test base product information

Related #1097

* Fix dependencies for gi
This commit is contained in:
MattHag 2024-03-10 15:11:02 +01:00 committed by GitHub
parent e226b76b8b
commit 0d225f6cb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 2 deletions

View File

@ -26,7 +26,7 @@ install_dnf:
install_brew: install_brew:
@echo "Installing Solaar dependencies via brew" @echo "Installing Solaar dependencies via brew"
brew update brew update
brew install hidapi gtk+3 pygobject3 brew install hidapi gtk+3 pygobject3 gobject-introspection
install_pip: install_pip:
@echo "Installing Solaar via pip" @echo "Installing Solaar via pip"

View File

@ -17,6 +17,8 @@
# Base low-level functions used by the API proper. # Base low-level functions used by the API proper.
# Unlikely to be used directly unless you're expanding the API. # Unlikely to be used directly unless you're expanding the API.
from __future__ import annotations
import logging import logging
import threading as _threading import threading as _threading
@ -74,9 +76,10 @@ def other_device_check(bus_id, vendor_id, product_id):
return _bt_device(product_id) return _bt_device(product_id)
def product_information(usb_id): def product_information(usb_id: int | str) -> dict:
if isinstance(usb_id, str): if isinstance(usb_id, str):
usb_id = int(usb_id, 16) usb_id = int(usb_id, 16)
for r in _RECEIVER_USB_IDS: for r in _RECEIVER_USB_IDS:
if usb_id == r.get("product_id"): if usb_id == r.get("product_id"):
return r return r

View File

@ -0,0 +1,21 @@
import pytest
from logitech_receiver import base
@pytest.mark.parametrize(
"usb_id, expected_name, expected_receiver_kind",
[
("0xC548", "Bolt Receiver", "bolt"),
("0xC52B", "Unifying Receiver", "unifying"),
("0xC531", "Nano Receiver", "nano"),
("0xC53F", "Lightspeed Receiver", None),
("0xC517", "EX100 Receiver 27 Mhz", "27Mhz"),
],
)
def test_product_information(usb_id, expected_name, expected_receiver_kind):
res = base.product_information(usb_id)
assert res["name"] == expected_name
if expected_receiver_kind:
assert res["receiver_kind"] == expected_receiver_kind