From b53521c029a057824918c3830993d554a520ae8a Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Fri, 10 Dec 2021 10:17:37 -0800 Subject: [PATCH 1/2] add two more smoke1 tests --- meshtastic/__main__.py | 2 +- meshtastic/tests/test_smoke1.py | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index fdf0de5..82763b7 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -619,7 +619,7 @@ def initParser(): action="store_true") parser.add_argument( - "--get", help="Get a preferences field", nargs=1, action='append') + "--get", help="Get a preferences field. Use an invalid field such as '0' to get a list of all fields.", nargs=1, action='append') parser.add_argument( "--set", help="Set a preferences field", nargs=2, action='append') diff --git a/meshtastic/tests/test_smoke1.py b/meshtastic/tests/test_smoke1.py index 0eb66c1..767da1a 100644 --- a/meshtastic/tests/test_smoke1.py +++ b/meshtastic/tests/test_smoke1.py @@ -285,6 +285,33 @@ def test_smoke1_ch_set_name(): assert return_value == 0 +@pytest.mark.smoke1 +def test_smoke1_ch_set_downlink_and_uplink(): + """Test -ch-set downlink_enabled X and --ch-set uplink_enabled X""" + return_value, out = subprocess.getstatusoutput('meshtastic --ch-set downlink_enabled false --ch-set uplink_enabled false') + assert re.match(r'Connected to radio', out) + assert return_value == 0 + # pause for the radio + time.sleep(PAUSE_AFTER_COMMAND) + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert not re.search(r'uplinkEnabled', out, re.MULTILINE) + assert not re.search(r'downlinkEnabled', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(PAUSE_AFTER_COMMAND) + return_value, out = subprocess.getstatusoutput('meshtastic --ch-set downlink_enabled true --ch-set uplink_enabled true') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Set downlink_enabled to true', out, re.MULTILINE) + assert re.search(r'^Set uplink_enabled to true', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(PAUSE_AFTER_COMMAND) + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert re.search(r'uplinkEnabled', out, re.MULTILINE) + assert re.search(r'downlinkEnabled', out, re.MULTILINE) + assert return_value == 0 + + @pytest.mark.smoke1 def test_smoke1_ch_add_and_ch_del(): """Test --ch-add""" @@ -403,6 +430,22 @@ def test_smoke1_set_ham(): assert return_value == 0 +@pytest.mark.smoke1 +def test_smoke1_set_wifi_settings(): + """Test --set wifi_ssid and --set wifi_password""" + return_value, out = subprocess.getstatusoutput('meshtastic --set wifi_ssid "some_ssid" --set wifi_password "temp1234"') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Set wifi_ssid to some_ssid', out, re.MULTILINE) + assert re.search(r'^Set wifi_password to temp1234', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(PAUSE_AFTER_COMMAND) + return_value, out = subprocess.getstatusoutput('meshtastic --get wifi_ssid --get wifi_password') + assert re.search(r'^wifi_ssid: some_ssid', out, re.MULTILINE) + assert re.search(r'^wifi_password: sekrit', out, re.MULTILINE) + assert return_value == 0 + + @pytest.mark.smoke1 def test_smoke1_factory_reset(): """Test factory reset""" From ada45ca86021ef065cfc08f4cfb0f9c07ad8c2b1 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Fri, 10 Dec 2021 10:20:16 -0800 Subject: [PATCH 2/2] make unit tests pass even if hardware is connected serially --- meshtastic/tests/test_main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index dbfbe23..8bd8742 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -103,7 +103,8 @@ def test_main_support(capsys): @pytest.mark.unit -def test_main_ch_index_no_devices(capsys): +@patch('meshtastic.util.findPorts', return_value=[]) +def test_main_ch_index_no_devices(patched_find_ports, capsys): """Test --ch-index 1""" sys.argv = ['', '--ch-index', '1'] args = sys.argv @@ -122,6 +123,7 @@ def test_main_ch_index_no_devices(capsys): out, err = capsys.readouterr() assert re.search(r'Warning: No Meshtastic devices detected', out, re.MULTILINE) assert err == '' + patched_find_ports.assert_called() @pytest.mark.unit