start to add unit tests for tunnel

This commit is contained in:
Mike Kinney
2021-12-30 19:37:38 -08:00
parent 684b2885aa
commit 50523ec1b1
3 changed files with 28 additions and 3 deletions

View File

@@ -1,2 +1,6 @@
[run]
omit = meshtastic/*_pb2.py,meshtastic/tests/*.py,meshtastic/test.py
[report]
exclude_lines =
if __name__ == .__main__.:

View File

@@ -6,13 +6,21 @@ import pytest
@pytest.mark.int
def test_int_no_args():
"""Test without any args"""
def test_int_meshtastic_no_args():
"""Test meshtastic without any args"""
return_value, out = subprocess.getstatusoutput('meshtastic')
assert re.match(r'usage: meshtastic', out)
assert return_value == 1
@pytest.mark.int
def test_int_mesh_tunnel_no_args():
"""Test mesh-tunnel without any args"""
return_value, out = subprocess.getstatusoutput('mesh-tunnel')
assert re.match(r'usage: mesh-tunnel', out)
assert return_value == 1
@pytest.mark.int
def test_int_version():
"""Test '--version'."""

View File

@@ -9,7 +9,7 @@ import logging
from unittest.mock import patch, MagicMock
import pytest
from meshtastic.__main__ import initParser, main, Globals, onReceive, onConnection, export_config, getPref, setPref, onNode
from meshtastic.__main__ import initParser, main, Globals, onReceive, onConnection, export_config, getPref, setPref, onNode, tunnelMain
#from ..radioconfig_pb2 import UserPreferences
import meshtastic.radioconfig_pb2
from ..serial_interface import SerialInterface
@@ -1679,3 +1679,16 @@ def test_onNode(capsys, reset_globals):
out, err = capsys.readouterr()
assert re.search(r'Node changed', out, re.MULTILINE)
assert err == ''
@pytest.mark.unit
def test_tunnel_no_args(capsys, reset_globals):
"""Test tunnel no arguments"""
sys.argv = ['']
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
tunnelMain()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
_, err = capsys.readouterr()
assert re.search(r'usage: ', err, re.MULTILINE)