diff --git a/meshtastic/serial_interface.py b/meshtastic/serial_interface.py index 4f8ddf3..90b6922 100644 --- a/meshtastic/serial_interface.py +++ b/meshtastic/serial_interface.py @@ -6,8 +6,8 @@ import os import stat import serial +import meshtastic.util from .stream_interface import StreamInterface -from .util import findPorts, our_exit class SerialInterface(StreamInterface): """Interface class for meshtastic devices over a serial link""" @@ -22,14 +22,14 @@ class SerialInterface(StreamInterface): """ if devPath is None: - ports = findPorts() + ports = meshtastic.util.findPorts() logging.debug(f"ports:{ports}") if len(ports) == 0: - our_exit("Warning: No Meshtastic devices detected.") + meshtastic.util.our_exit("Warning: No Meshtastic devices detected.") elif len(ports) > 1: message = "Warning: Multiple serial ports were detected so one serial port must be specified with the '--port'.\n" message += f" Ports detected:{ports}" - our_exit(message) + meshtastic.util.our_exit(message) else: devPath = ports[0] diff --git a/meshtastic/test/test_serial_interface.py b/meshtastic/test/test_serial_interface.py new file mode 100644 index 0000000..df6f12f --- /dev/null +++ b/meshtastic/test/test_serial_interface.py @@ -0,0 +1,18 @@ +"""Meshtastic unit tests for serial_interface.py""" + +from unittest.mock import patch +import pytest + +from ..serial_interface import SerialInterface + +@pytest.mark.unit +@patch('serial.Serial') +@patch('meshtastic.util.findPorts', return_value=['/dev/ttyUSBfake']) +def test_SerialInterface(mocked_findPorts, mocked_serial): + """Test that we can instantiate a SerialInterface""" + iface = SerialInterface(noProto=True) + iface.showInfo() + iface.localNode.showInfo() + iface.close() + mocked_findPorts.assert_called() + mocked_serial.assert_called()