Skip to content

Commit

Permalink
transport 100% test coverage (again) (#2333)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Sep 24, 2024
1 parent cf7c6a9 commit 2d51f8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/transport/test_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async def test_split_serial_packet(self, client, server, use_port):
)
async def test_serial_poll(self, client, server, use_port):
"""Test connection and data exchange."""
if SerialTransport.force_poll:
if SerialTransport.force_poll: # pragma: no cover
client.close()
server.close()
return
Expand Down
13 changes: 10 additions & 3 deletions test/transport/test_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
import contextlib
import os
import sys
from functools import partial
from unittest import mock

Expand Down Expand Up @@ -81,7 +82,7 @@ async def test_create_serial(self):

async def test_force_poll(self):
"""Test external methods."""
if SerialTransport.force_poll:
if SerialTransport.force_poll: # pragma: no cover
return
SerialTransport.force_poll = True
transport, protocol = await create_serial_connection(
Expand All @@ -93,10 +94,9 @@ async def test_force_poll(self):
transport.close()
SerialTransport.force_poll = False


async def test_write_force_poll(self):
"""Test write with poll."""
if SerialTransport.force_poll:
if SerialTransport.force_poll: # pragma: no cover
return
SerialTransport.force_poll = True
transport, protocol = await create_serial_connection(
Expand Down Expand Up @@ -195,3 +195,10 @@ async def test_read_ready(self):
comm.sync_serial.read.return_value = b'abcd'
comm.intern_read_ready()
comm.intern_protocol.data_received.assert_called_once()

async def test_import_pyserial(self):
"""Test pyserial not installed."""
with mock.patch.dict(sys.modules, {'no_modules': None}) as mock_modules:
del mock_modules['serial']
with pytest.raises(RuntimeError):
SerialTransport(asyncio.get_running_loop(), mock.Mock(), "dummy", None, None, None, None, None)

0 comments on commit 2d51f8c

Please sign in to comment.