diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index e0cc2b9..7a5fc19 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -598,8 +598,9 @@ def common(): 'This option has been deprecated, see help below for the correct replacement...') parser.print_help(sys.stderr) sys.exit(1) - elif args.test: - result = test.testAll() + elif args.numTests: + numTests = int(args.numTests[0]) + result = test.testAll(numTests) if not result: our_exit("Warning: Test was not successful.") else: @@ -770,7 +771,7 @@ def initParser(): action="store_true") parser.add_argument("--test", help="Run stress test against all connected Meshtastic devices", - action="store_true") + nargs=1, dest='numTests', action="store") parser.add_argument("--ble", help="BLE mac address to connect to (BLE is not yet supported for this tool)", default=None) diff --git a/meshtastic/test.py b/meshtastic/test.py index e4c6af6..3607bf7 100644 --- a/meshtastic/test.py +++ b/meshtastic/test.py @@ -117,7 +117,7 @@ def runTests(numTests=50, wantAck=False, maxFailures=0): return True -def testThread(numTests=5): +def testThread(numTests=50): """Test thread""" logging.info("Found devices, starting tests...") result = runTests(numTests, wantAck=True) @@ -140,7 +140,7 @@ def openDebugLog(portName): return open(debugname, 'w+', buffering=1) -def testAll(): +def testAll(numTests=50): """ Run a series of tests using devices we can find. This is called from the cli with the "--test" option. @@ -157,7 +157,7 @@ def testAll(): port, debugOut=openDebugLog(port), connectNow=True), ports)) logging.info("Ports opened, starting test") - result = testThread() + result = testThread(numTests) for i in interfaces: i.close() diff --git a/meshtastic/test/test_mesh_interface.py b/meshtastic/test/test_mesh_interface.py index 4232519..77a5608 100644 --- a/meshtastic/test/test_mesh_interface.py +++ b/meshtastic/test/test_mesh_interface.py @@ -1,14 +1,23 @@ """Meshtastic unit tests for node.py""" +import re + import pytest from meshtastic.mesh_interface import MeshInterface @pytest.mark.unit -def test_MeshInterface(): +def test_MeshInterface(capsys): """Test that we instantiate a MeshInterface""" iface = MeshInterface(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 == '' iface.close() diff --git a/meshtastic/test/test_smoke2.py b/meshtastic/test/test_smoke2.py index 4788a2e..2d1a6c4 100644 --- a/meshtastic/test/test_smoke2.py +++ b/meshtastic/test/test_smoke2.py @@ -16,7 +16,7 @@ def test_smoke2_info(): @pytest.mark.smoke2 def test_smoke2_test(): """Test --test""" - return_value, out = subprocess.getstatusoutput('meshtastic --test') + return_value, out = subprocess.getstatusoutput('meshtastic --test 5') assert re.search(r'Writing serial debugging', out, re.MULTILINE) assert re.search(r'Ports opened', out, re.MULTILINE) assert re.search(r'Running 5 tests', out, re.MULTILINE) diff --git a/meshtastic/test/test_util.py b/meshtastic/test/test_util.py index f86d629..ea3253b 100644 --- a/meshtastic/test/test_util.py +++ b/meshtastic/test/test_util.py @@ -1,8 +1,20 @@ """Meshtastic unit tests for node.py""" +import re + import pytest -from meshtastic.util import pskToString, our_exit +from meshtastic.util import fixme, stripnl, pskToString, our_exit, support_info + + +@pytest.mark.unit +def test_stripnl(): + """Test stripnl""" + assert stripnl('') == '' + assert stripnl('a\n') == 'a' + assert stripnl(' a \n ') == 'a' + assert stripnl('a\nb') == 'a b' + @pytest.mark.unit def test_pskToString_empty_string(): @@ -50,3 +62,23 @@ def test_our_exit_non_zero_return_value(): our_exit("Error: Some message", 1) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == 1 + + +@pytest.mark.unit +def test_fixme(): + """Test fixme""" + with pytest.raises(Exception) as pytest_wrapped_e: + fixme("some exception") + assert pytest_wrapped_e.type == Exception + + +@pytest.mark.unit +def test_support_info(capsys): + """Test support_info""" + support_info() + out, err = capsys.readouterr() + assert re.search(r'System', out, re.MULTILINE) + assert re.search(r'Platform', out, re.MULTILINE) + assert re.search(r'Machine', out, re.MULTILINE) + assert re.search(r'Executable', out, re.MULTILINE) + assert err == ''