needed to do some actual testing to see error in code

This commit is contained in:
Mike Kinney
2021-12-23 09:30:23 -08:00
parent 01ac345cf9
commit a56a92b166
2 changed files with 21 additions and 2 deletions

View File

@@ -244,7 +244,7 @@ def onConnected(interface):
channelIndex = 0
if args.ch_index is not None:
channelIndex = int(args.ch_index)
ch = interface.getChannelByChannelIndex(channelIndex)
ch = getNode().getChannelByChannelIndex(channelIndex)
if ch and ch.role != channel_pb2.Channel.Role.DISABLED:
print(f"Sending text message {args.sendtext} to {args.destOrAll} on channelIndex:{channelIndex}")
interface.sendText(args.sendtext, args.destOrAll, wantAck=True, channelIndex=channelIndex)

View File

@@ -449,7 +449,26 @@ def test_main_sendtext_with_invalid_channel(capsys, reset_globals):
iface = MagicMock(autospec=SerialInterface)
iface.getChannelByChannelIndex.return_value = None
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
#mo.getChannelByChannelIndex.return_value = None
iface.getNode.return_value.getChannelByChannelIndex.return_value = None
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
out, err = capsys.readouterr()
assert re.search(r'is not a valid channel', out, re.MULTILINE)
assert err == ''
mo.assert_called()
@pytest.mark.unit
def test_main_sendtext_with_invalid_channel_nine(capsys, reset_globals):
"""Test --sendtext"""
sys.argv = ['', '--sendtext', 'hello', '--ch-index', '9']
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
iface.getNode.return_value.getChannelByChannelIndex.return_value = None
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit