Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transport 100% test coverage (again) #2333

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)