From d2a9b87968253c6bcc77c525aa624a3acfe23b63 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Sun, 12 Dec 2021 17:05:38 -0800 Subject: [PATCH] add main unit test for --seturl --- meshtastic/__main__.py | 2 +- meshtastic/tests/test_main.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 5b7a110..84d4fc6 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -732,7 +732,7 @@ def initParser(): "--setlon", help="Set device longitude (allows use without GPS)") parser.add_argument( - "--pos-fields", help="Specify position message fields. Use '0' for list of valid values. "\ + "--pos-fields", help="Specify fields to send when sending a position. Use no argument for a list of valid values. "\ "Can pass multiple values as a space separated list like "\ "this: '--pos-fields POS_ALTITUDE POS_ALT_MSL'", nargs="*", action="store") diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index d9f0006..41ebb7d 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -604,3 +604,24 @@ def test_main_set_team_invalid(capsys): assert err == '' mo.assert_called() mm.Value.assert_called() + + +@pytest.mark.unit +def test_main_seturl(capsys): + """Test --seturl (url used below is what is generated after a factory_reset)""" + sys.argv = ['', '--seturl', 'https://www.meshtastic.org/d/#CgUYAyIBAQ'] + args = sys.argv + parser = None + parser = argparse.ArgumentParser() + our_globals = Globals.getInstance() + our_globals.set_parser(parser) + our_globals.set_args(args) + iface = MagicMock(autospec=SerialInterface) + with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo: + main() + out, err = capsys.readouterr() + print('out:', out) + print('err:', err) + assert re.search(r'Connected to radio', out, re.MULTILINE) + assert err == '' + mo.assert_called()