Skip to content

Commit 9f853cf

Browse files
committed
chore: Formatting.
1 parent df67391 commit 9f853cf

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

smpclient/transport/serial.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ async def send(self, data: bytes) -> None:
229229
try:
230230
for packet in smppacket.encode(data, line_length=self._line_length):
231231
self._conn.write(packet)
232-
logger.debug(
233-
f"Writing encoded packet of size {len(packet)}B; {self._line_length=}"
234-
)
232+
logger.debug(f"Writing encoded packet of size {len(packet)}B; {self._line_length=}")
235233

236234
# fake async until I get around to replacing pyserial
237235
while self._conn.out_waiting > 0:
@@ -366,9 +364,7 @@ def _find_smp_packet_start(self, buf: bytearray) -> int:
366364
]
367365
return min(indices) if indices else -1
368366

369-
async def handle_serial_data(
370-
self, data: bytearray, flush_remaining: bool = False
371-
) -> None:
367+
async def handle_serial_data(self, data: bytearray, flush_remaining: bool = False) -> None:
372368
"""Move given bytes to the serial buffer and try to flush any lines to the user queue."""
373369
self._incomplete_serial_data_buffer.extend(data)
374370
lines: list[bytearray] = self._incomplete_serial_data_buffer.split(b"\n")
@@ -426,9 +422,7 @@ def max_unencoded_size(self) -> int:
426422
# encoded frame_length and CRC16 and the start/continue delimiter.
427423
# Add to that the cost of the stop delimiter.
428424
packet_framing_size: Final = (
429-
_base64_cost(
430-
smppacket.FRAME_LENGTH_STRUCT.size + smppacket.CRC16_STRUCT.size
431-
)
425+
_base64_cost(smppacket.FRAME_LENGTH_STRUCT.size + smppacket.CRC16_STRUCT.size)
432426
+ smppacket.DELIMITER_SIZE
433427
) * self._line_buffers + len(smppacket.END_DELIMITER)
434428

tests/test_smp_serial_transport.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import asyncio
66
import logging
7+
from typing import Any, Generator
78
from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch
89

910
import pytest
@@ -15,15 +16,13 @@
1516

1617

1718
@pytest.fixture(autouse=True)
18-
def mock_serial():
19+
def mock_serial() -> Generator[None, Any, None]:
1920
with patch("smpclient.transport.serial.Serial"):
2021
yield
2122

2223

2324
def test_constructor() -> None:
24-
t = SMPSerialTransport(
25-
max_smp_encoded_frame_size=512, line_length=128, line_buffers=4
26-
)
25+
t = SMPSerialTransport(max_smp_encoded_frame_size=512, line_length=128, line_buffers=4)
2726
assert t.mtu == 512
2827
assert t.max_unencoded_size < 512
2928

@@ -71,9 +70,7 @@ async def test_send() -> None:
7170

7271
await t.send(r.BYTES)
7372
t._conn.write.assert_called_once()
74-
assert (
75-
p.call_count == 2
76-
) # called twice since out buffer was not drained on first call
73+
assert p.call_count == 2 # called twice since out buffer was not drained on first call
7774

7875

7976
@pytest.mark.asyncio
@@ -256,10 +253,7 @@ async def test_disconnect_flushes_partial_smp_as_serial(
256253
await t.disconnect()
257254
messages = {r.message for r in caplog.records}
258255
assert "/dev/ttyACM0: Normal serial" in messages
259-
assert any(
260-
b"AAAA" in r.message.encode("utf-8", errors="ignore")
261-
for r in caplog.records
262-
)
256+
assert any(b"AAAA" in r.message.encode("utf-8", errors="ignore") for r in caplog.records)
263257

264258

265259
@pytest.mark.asyncio
@@ -280,16 +274,11 @@ async def bad_callback(data: bytes) -> None:
280274
t = SMPSerialTransport(serial_line_callback=bad_callback)
281275
await t.connect("/dev/ttyACM0", timeout_s=1.0)
282276

283-
t._conn.read_all = MagicMock( # type: ignore
284-
side_effect=[b"Line 1\n", b"Line 2\n"]
285-
)
277+
t._conn.read_all = MagicMock(side_effect=[b"Line 1\n", b"Line 2\n"]) # type: ignore
286278

287279
with caplog.at_level(logging.ERROR):
288280
await asyncio.sleep(0.05) # Flush mock serial.
289-
assert any(
290-
"Serial data callback raised an exception" in r.message
291-
for r in caplog.records
292-
)
281+
assert any("Serial data callback raised an exception" in r.message for r in caplog.records)
293282

294283
await t.disconnect()
295284

0 commit comments

Comments
 (0)