From d1ea68d7dca7a264e9cd918dfdd52e9704b82860 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Thu, 6 Jan 2022 12:17:42 -0800 Subject: [PATCH] add code coverage to recently added code --- meshtastic/tests/test_main.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index d408e5c..150a210 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -201,6 +201,25 @@ def test_main_info(capsys, reset_globals): mo.assert_called() +@pytest.mark.unit +def test_main_info_with_permission_error(capsys, caplog, reset_globals): + """Test --info""" + sys.argv = ['', '--info'] + Globals.getInstance().set_args(sys.argv) + + iface = MagicMock(autospec=SerialInterface) + with caplog.at_level(logging.DEBUG): + with pytest.raises(SystemExit) as pytest_wrapped_e: + with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo: + mo.side_effect = PermissionError('bla bla') + main() + assert pytest_wrapped_e.type == SystemExit + assert pytest_wrapped_e.value.code == 1 + out, err = capsys.readouterr() + assert re.search(r'Need to add yourself', out, re.MULTILINE) + assert err == '' + + @pytest.mark.unit def test_main_info_with_tcp_interface(capsys, reset_globals): """Test --info"""