diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index 6adba2b..4521a72 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -367,6 +367,27 @@ def test_main_qr(capsys): mo.assert_called() +@pytest.mark.unit +@pytest.mark.usefixtures("reset_globals") +def test_main_onConnected_exception(capsys): + """Test the exception in onConnected""" + sys.argv = ['', '--qr'] + Globals.getInstance().set_args(sys.argv) + + def throw_an_exception(junk): + raise Exception("Fake exception.") + + iface = MagicMock(autospec=SerialInterface) + with patch('meshtastic.serial_interface.SerialInterface', return_value=iface): + with patch('pyqrcode.create', side_effect=throw_an_exception): + with pytest.raises(Exception) as pytest_wrapped_e: + main() + out, err = capsys.readouterr() + assert re.search('Aborting due to: Fake exception', out, re.MULTILINE) + assert err == '' + assert pytest_wrapped_e.type == Exception + + @pytest.mark.unit @pytest.mark.usefixtures("reset_globals") def test_main_nodes(capsys):