add some tests

This commit is contained in:
Mike Kinney
2021-12-08 23:20:20 -08:00
parent e8fd40e145
commit 55e374c89b
4 changed files with 43 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
"""Meshtastic unit tests for node.py"""
"""Meshtastic unit tests for mesh_interface.py"""
import re
@@ -9,7 +9,7 @@ from meshtastic.mesh_interface import MeshInterface
@pytest.mark.unit
def test_MeshInterface(capsys):
"""Test that we instantiate a MeshInterface"""
"""Test that we can instantiate a MeshInterface"""
iface = MeshInterface(noProto=True)
iface.showInfo()
iface.localNode.showInfo()

View File

@@ -0,0 +1,14 @@
"""Meshtastic unit tests for stream_interface.py"""
import pytest
from meshtastic.stream_interface import StreamInterface
@pytest.mark.unit
def test_StreamInterface():
"""Test that we can instantiate a StreamInterface"""
with pytest.raises(Exception) as pytest_wrapped_e:
StreamInterface(noProto=True)
assert pytest_wrapped_e.type == Exception

View File

@@ -0,0 +1,26 @@
"""Meshtastic unit tests for tcp_interface.py"""
import re
from unittest.mock import patch
import pytest
from meshtastic.tcp_interface import TCPInterface
@pytest.mark.unit
def test_TCPInterface(capsys):
"""Test that we can instantiate a TCPInterface"""
with patch('socket.socket') as mock_socket:
iface = TCPInterface(hostname='localhost', noProto=True)
iface.showInfo()
iface.localNode.showInfo()
out, err = capsys.readouterr()
assert re.search(r'Owner: None \(None\)', out, re.MULTILINE)
assert re.search(r'Nodes', out, re.MULTILINE)
assert re.search(r'Preferences', out, re.MULTILINE)
assert re.search(r'Channels', out, re.MULTILINE)
assert re.search(r'Primary channel URL', out, re.MULTILINE)
assert err == ''
assert mock_socket.called
iface.close()

View File

@@ -1,4 +1,4 @@
"""Meshtastic unit tests for node.py"""
"""Meshtastic unit tests for util.py"""
import re