Skip to content

Commit 052c557

Browse files
committed
test: Add tests for device description, VID and PID
1 parent ade29a2 commit 052c557

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

tests/helper.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ def __power_status(self, port_number: int):
4545

4646
return self.__status(self.status[port_number])
4747

48+
def register_port_details(
49+
self,
50+
fp: pytest_subprocess.FakeProcess,
51+
port_number: int = None,
52+
vendor_id: int = None,
53+
product_id: int = None,
54+
description: str = None,
55+
):
56+
stdout = f" Port {port_number}: 0103 power enable connect"
57+
if vendor_id is not None and product_id is not None:
58+
stdout += f" [{vendor_id:04x}:{product_id:04x}"
59+
60+
if description is not None:
61+
stdout += f" {description}"
62+
63+
stdout += "]"
64+
65+
fp.register(["uhubctl", "-l", self.path, "-p", str(port_number)], stdout=stdout)
66+
4867
def cmd(
4968
self,
5069
fp: pytest_subprocess.FakeProcess,

tests/test_port.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,26 @@ def test_port_from_path():
6161

6262
assert port.hub.path == path
6363
assert port.port_number == port_number
64+
65+
66+
def test_device_data(mock_hub: MockHub, fp: pytest_subprocess.FakeProcess):
67+
port_number = 1
68+
vendor_id = 0xDEAD
69+
product_id = 0xBEEF
70+
description = "Some fancy USB device"
71+
72+
port = Port(mock_hub, port_number)
73+
74+
mock_hub.register_port_details(fp, port_number)
75+
assert port.description(cached_results=False) is None
76+
77+
mock_hub.register_port_details(fp, port_number)
78+
assert port.vendor_id(cached_results=False) is None
79+
80+
mock_hub.register_port_details(fp, port_number)
81+
assert port.product_id(cached_results=False) is None
82+
83+
mock_hub.register_port_details(fp, port_number, vendor_id, product_id, description)
84+
assert port.description(cached_results=False) == description
85+
assert port.vendor_id(cached_results=True) == vendor_id
86+
assert port.product_id(cached_results=True) == product_id

0 commit comments

Comments
 (0)