Skip to content

Commit 49c47ae

Browse files
committed
chore: Formatting.
1 parent df67391 commit 49c47ae

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
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: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ def mock_serial():
2121

2222

2323
def test_constructor() -> None:
24-
t = SMPSerialTransport(
25-
max_smp_encoded_frame_size=512, line_length=128, line_buffers=4
26-
)
24+
t = SMPSerialTransport(max_smp_encoded_frame_size=512, line_length=128, line_buffers=4)
2725
assert t.mtu == 512
2826
assert t.max_unencoded_size < 512
2927

@@ -71,9 +69,7 @@ async def test_send() -> None:
7169

7270
await t.send(r.BYTES)
7371
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
72+
assert p.call_count == 2 # called twice since out buffer was not drained on first call
7773

7874

7975
@pytest.mark.asyncio
@@ -256,10 +252,7 @@ async def test_disconnect_flushes_partial_smp_as_serial(
256252
await t.disconnect()
257253
messages = {r.message for r in caplog.records}
258254
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-
)
255+
assert any(b"AAAA" in r.message.encode("utf-8", errors="ignore") for r in caplog.records)
263256

264257

265258
@pytest.mark.asyncio
@@ -280,16 +273,11 @@ async def bad_callback(data: bytes) -> None:
280273
t = SMPSerialTransport(serial_line_callback=bad_callback)
281274
await t.connect("/dev/ttyACM0", timeout_s=1.0)
282275

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

287278
with caplog.at_level(logging.ERROR):
288279
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-
)
280+
assert any("Serial data callback raised an exception" in r.message for r in caplog.records)
293281

294282
await t.disconnect()
295283

0 commit comments

Comments
 (0)