Skip to content

Commit a394ca0

Browse files
committed
style: format code with black
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
1 parent 4905e06 commit a394ca0

6 files changed

Lines changed: 25 additions & 17 deletions

File tree

tests/helper.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import uhubctl
1212

13+
1314
class MockHub(uhubctl.Hub):
1415
def __init__(self, path: str, num_ports: int = 5) -> None:
1516
self.path = path
@@ -24,14 +25,14 @@ def __init__(self, path: str, num_ports: int = 5) -> None:
2425

2526
def __stdout(self, prefix: str = "Current", port_filter: int = None):
2627
stdout = [
27-
f"{prefix} status for hub {self.path} [0424:9512, USB 2.00, {self.num_ports} ports, ppps]".encode()]
28+
f"{prefix} status for hub {self.path} [0424:9512, USB 2.00, {self.num_ports} ports, ppps]".encode()
29+
]
2830

2931
for idx in range(self.num_ports):
30-
if port_filter is not None and idx+1 != int(port_filter):
32+
if port_filter is not None and idx + 1 != int(port_filter):
3133
continue
3234

33-
stdout.append(
34-
f" Port {idx+1}: 0100 {self.__power_status(idx)}".encode())
35+
stdout.append(f" Port {idx+1}: 0100 {self.__power_status(idx)}".encode())
3536

3637
return stdout
3738

@@ -46,7 +47,12 @@ def __power_status(self, port_number: int):
4647

4748
return self.__status(self.status[port_number])
4849

49-
def cmd(self, fp: pytest_subprocess.FakeProcess, port_number: int = None, new_status: bool = None) -> None:
50+
def cmd(
51+
self,
52+
fp: pytest_subprocess.FakeProcess,
53+
port_number: int = None,
54+
new_status: bool = None,
55+
) -> None:
5056
if port_number is not None:
5157
assert port_number <= self.num_ports
5258

tests/test_hub.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ def test_port_enumeration(mock_hub: MockHub, fp: pytest_subprocess.FakeProcess):
5252

5353

5454
def test_no_devices(fp: pytest_subprocess.FakeProcess):
55-
fp.register(["uhubctl", "-N"],
56-
stdout=["No compatible devices detected!".encode()])
55+
fp.register(["uhubctl", "-N"], stdout=["No compatible devices detected!".encode()])
5756

5857
hubs = uhubctl.discover_hubs()
5958

tests/test_uhubctl_binary.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
def test_uhubctl_binary_invalid():
77
import uhubctl
8+
89
uhubctl.utils.UHUBCTL_BINARY = "invalid-uhubctl"
910

1011
with pytest.raises(Exception):
@@ -13,6 +14,7 @@ def test_uhubctl_binary_invalid():
1314

1415
def test_uhubctl_binary_echo():
1516
import uhubctl
17+
1618
uhubctl.utils.UHUBCTL_BINARY = "/bin/echo"
1719

18-
assert uhubctl.discover_hubs() == []
20+
assert uhubctl.discover_hubs() == []

uhubctl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from .usb import discover_hubs, Hub, Port
33
from . import utils
44

5-
__all__ = ['discover_hubs', 'Hub', 'Port', 'utils']
5+
__all__ = ["discover_hubs", "Hub", "Port", "utils"]

uhubctl/usb.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .utils import _uhubctl
66

77

8-
def discover_hubs() -> List['Hub']:
8+
def discover_hubs() -> List["Hub"]:
99
"""
1010
Return list of all by uhubctl supported USB hubs with their ports
1111
@@ -46,7 +46,7 @@ def __init__(self, path: str, enumerate_ports: bool = False) -> None:
4646
if enumerate_ports:
4747
self.discover_ports()
4848

49-
def add_port(self, port_number: int) -> 'Port':
49+
def add_port(self, port_number: int) -> "Port":
5050
"""
5151
Add port to hub by port number
5252
@@ -70,10 +70,10 @@ def add_ports(self, first_port: int, last_port: int):
7070
first_port: First port's indentification number
7171
last_port: Last port's ndentification number
7272
"""
73-
for port_number in range(first_port, last_port+1):
73+
for port_number in range(first_port, last_port + 1):
7474
self.add_port(port_number)
7575

76-
def find_port(self, port_number: int) -> Optional['Port']:
76+
def find_port(self, port_number: int) -> Optional["Port"]:
7777
"""
7878
Find port by port number
7979
@@ -131,14 +131,15 @@ def status(self) -> bool:
131131
"""
132132
status = None
133133
pattern = re.compile(
134-
fr" Port {self.port_number}: \d{{4}} (power|off|indicator)")
134+
rf" Port {self.port_number}: \d{{4}} (power|off|indicator)"
135+
)
135136

136137
args = ["-l", self.hub.path, "-p", str(self.port_number)]
137138
for line in _uhubctl(args):
138139
reg = pattern.match(line)
139140

140141
if reg:
141-
status = (reg.group(1) == "power")
142+
status = reg.group(1) == "power"
142143

143144
if status is None:
144145
raise Exception()

uhubctl/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def _uhubctl(args: list = None) -> list:
88
cmd = UHUBCTL_BINARY.split(" ")
9-
cmd.append('-N')
9+
cmd.append("-N")
1010

1111
if args is not None:
1212
cmd += args
@@ -15,7 +15,7 @@ def _uhubctl(args: list = None) -> list:
1515
result = subprocess.run(cmd, capture_output=True, check=True)
1616
stdout = result.stdout.decode()
1717

18-
return stdout.split('\n')
18+
return stdout.split("\n")
1919
except subprocess.CalledProcessError as exc:
2020
stderr = exc.stderr.decode()
2121

0 commit comments

Comments
 (0)