From 50523ec1b13d7ee3bb5e729fdfb50a2024a2b75f Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Thu, 30 Dec 2021 19:37:38 -0800 Subject: [PATCH] start to add unit tests for tunnel --- .coveragerc | 4 ++++ meshtastic/tests/test_int.py | 12 ++++++++++-- meshtastic/tests/test_main.py | 15 ++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.coveragerc b/.coveragerc index dc58f07..5171a00 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,2 +1,6 @@ [run] omit = meshtastic/*_pb2.py,meshtastic/tests/*.py,meshtastic/test.py + +[report] +exclude_lines = + if __name__ == .__main__.: diff --git a/meshtastic/tests/test_int.py b/meshtastic/tests/test_int.py index 1b4615c..a46e86e 100644 --- a/meshtastic/tests/test_int.py +++ b/meshtastic/tests/test_int.py @@ -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'.""" diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index 7aed976..3c5b423 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -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)