Skip to content

Commit

Permalink
Merge pull request #177 from mkinney/fix_channel_change
Browse files Browse the repository at this point in the history
needed to do some actual testing to see error in code
  • Loading branch information
mkinney committed Dec 23, 2021
2 parents 01ac345 + a56a92b commit 942600f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def getNode():
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)
Expand Down
21 changes: 20 additions & 1 deletion meshtastic/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 942600f

Please sign in to comment.