Files
python/docs/meshtastic/tests/test_main.html
2021-12-16 13:57:42 -05:00

3606 lines
159 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>meshtastic.tests.test_main API documentation</title>
<meta name="description" content="Meshtastic unit tests for __main__.py" />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>meshtastic.tests.test_main</code></h1>
</header>
<section id="section-intro">
<p>Meshtastic unit tests for <strong>main</strong>.py</p>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">&#34;&#34;&#34;Meshtastic unit tests for __main__.py&#34;&#34;&#34;
import sys
import os
import re
from unittest.mock import patch, MagicMock
import pytest
from meshtastic.__main__ import initParser, main, Globals, onReceive, onConnection
import meshtastic.radioconfig_pb2
from ..serial_interface import SerialInterface
from ..tcp_interface import TCPInterface
from ..ble_interface import BLEInterface
from ..node import Node
from ..channel_pb2 import Channel
@pytest.mark.unit
def test_main_init_parser_no_args(capsys, reset_globals):
&#34;&#34;&#34;Test no arguments&#34;&#34;&#34;
sys.argv = [&#39;&#39;]
Globals.getInstance().set_args(sys.argv)
initParser()
out, err = capsys.readouterr()
assert out == &#39;&#39;
assert err == &#39;&#39;
@pytest.mark.unit
def test_main_init_parser_version(capsys, reset_globals):
&#34;&#34;&#34;Test --version&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--version&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
initParser()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
out, err = capsys.readouterr()
assert re.match(r&#39;[0-9]+\.[0-9]+\.[0-9]&#39;, out)
assert err == &#39;&#39;
@pytest.mark.unit
def test_main_main_version(capsys, reset_globals):
&#34;&#34;&#34;Test --version&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--version&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
out, err = capsys.readouterr()
assert re.match(r&#39;[0-9]+\.[0-9]+\.[0-9]&#39;, out)
assert err == &#39;&#39;
@pytest.mark.unit
def test_main_main_no_args(reset_globals):
&#34;&#34;&#34;Test with no args&#34;&#34;&#34;
sys.argv = [&#39;&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
@pytest.mark.unit
def test_main_support(capsys, reset_globals):
&#34;&#34;&#34;Test --support&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--support&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
out, err = capsys.readouterr()
assert re.search(r&#39;System&#39;, out, re.MULTILINE)
assert re.search(r&#39;Platform&#39;, out, re.MULTILINE)
assert re.search(r&#39;Machine&#39;, out, re.MULTILINE)
assert re.search(r&#39;Executable&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
@pytest.mark.unit
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[])
def test_main_ch_index_no_devices(patched_find_ports, capsys, reset_globals):
&#34;&#34;&#34;Test --ch-index 1&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert Globals.getInstance().get_channel_index() == 1
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
out, err = capsys.readouterr()
assert re.search(r&#39;Warning: No Meshtastic devices detected&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
patched_find_ports.assert_called()
@pytest.mark.unit
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[])
def test_main_test_no_ports(patched_find_ports, reset_globals):
&#34;&#34;&#34;Test --test with no hardware&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--test&#39;]
Globals.getInstance().set_args(sys.argv)
assert Globals.getInstance().get_target_node() is None
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
patched_find_ports.assert_called()
@pytest.mark.unit
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[&#39;/dev/ttyFake1&#39;])
def test_main_test_one_port(patched_find_ports, reset_globals):
&#34;&#34;&#34;Test --test with one fake port&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--test&#39;]
Globals.getInstance().set_args(sys.argv)
assert Globals.getInstance().get_target_node() is None
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
patched_find_ports.assert_called()
@pytest.mark.unit
@patch(&#39;meshtastic.test.testAll&#39;, return_value=True)
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[&#39;/dev/ttyFake1&#39;, &#39;/dev/ttyFake2&#39;])
def test_main_test_two_ports_success(patched_find_ports, patched_test_all, reset_globals):
&#34;&#34;&#34;Test --test two fake ports and testAll() is a simulated success&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--test&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
# TODO: why does this fail? patched_find_ports.assert_called()
patched_test_all.assert_called()
@pytest.mark.unit
@patch(&#39;meshtastic.test.testAll&#39;, return_value=False)
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[&#39;/dev/ttyFake1&#39;, &#39;/dev/ttyFake2&#39;])
def test_main_test_two_ports_fails(patched_find_ports, patched_test_all, reset_globals):
&#34;&#34;&#34;Test --test two fake ports and testAll() is a simulated failure&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--test&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
# TODO: why does this fail? patched_find_ports.assert_called()
patched_test_all.assert_called()
@pytest.mark.unit
def test_main_info(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_info_with_tcp_interface(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--host&#39;, &#39;meshtastic.local&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=TCPInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.tcp_interface.TCPInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_info_with_ble_interface(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--ble&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=BLEInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.ble_interface.BLEInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_no_proto(capsys, reset_globals):
&#34;&#34;&#34;Test --noproto (using --info for output)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--noproto&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
# Override the time.sleep so there is no loop
def my_sleep(amount):
sys.exit(0)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface):
with patch(&#39;time.sleep&#39;, side_effect=my_sleep):
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
@pytest.mark.unit
def test_main_info_with_seriallog_stdout(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--seriallog&#39;, &#39;stdout&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_info_with_seriallog_output_txt(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--seriallog&#39;, &#39;output.txt&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
# do some cleanup
os.remove(&#39;output.txt&#39;)
@pytest.mark.unit
def test_main_qr(capsys, reset_globals):
&#34;&#34;&#34;Test --qr&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--qr&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
# TODO: could mock/check url
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Primary channel URL&#39;, out, re.MULTILINE)
# if a qr code is generated it will have lots of these
assert re.search(r&#39;\[7m&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_nodes(capsys, reset_globals):
&#34;&#34;&#34;Test --nodes&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--nodes&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showNodes():
print(&#39;inside mocked showNodes&#39;)
iface.showNodes.side_effect = mock_showNodes
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showNodes&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_set_owner_to_bob(capsys, reset_globals):
&#34;&#34;&#34;Test --set-owner bob&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set-owner&#39;, &#39;bob&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device owner to bob&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_set_ham_to_KI123(capsys, reset_globals):
&#34;&#34;&#34;Test --set-ham KI123&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set-ham&#39;, &#39;KI123&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_turnOffEncryptionOnPrimaryChannel():
print(&#39;inside mocked turnOffEncryptionOnPrimaryChannel&#39;)
def mock_setOwner(name, is_licensed):
print(&#39;inside mocked setOwner&#39;)
mocked_node.turnOffEncryptionOnPrimaryChannel.side_effect = mock_turnOffEncryptionOnPrimaryChannel
mocked_node.setOwner.side_effect = mock_setOwner
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting HAM ID to KI123&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked setOwner&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked turnOffEncryptionOnPrimaryChannel&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_reboot(capsys, reset_globals):
&#34;&#34;&#34;Test --reboot&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--reboot&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_reboot():
print(&#39;inside mocked reboot&#39;)
mocked_node.reboot.side_effect = mock_reboot
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked reboot&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_sendtext(capsys, reset_globals):
&#34;&#34;&#34;Test --sendtext&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--sendtext&#39;, &#39;hello&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_sendText(text, dest, wantAck):
print(&#39;inside mocked sendText&#39;)
iface.sendText.side_effect = mock_sendText
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Sending text message&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendText&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_sendtext_with_dest(capsys, reset_globals):
&#34;&#34;&#34;Test --sendtext with --dest&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--sendtext&#39;, &#39;hello&#39;, &#39;--dest&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_sendText(text, dest, wantAck):
print(&#39;inside mocked sendText&#39;)
iface.sendText.side_effect = mock_sendText
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Sending text message&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendText&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_sendping(capsys, reset_globals):
&#34;&#34;&#34;Test --sendping&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--sendping&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_sendData(payload, dest, portNum, wantAck, wantResponse):
print(&#39;inside mocked sendData&#39;)
iface.sendData.side_effect = mock_sendData
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Sending ping message&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendData&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_setlat(capsys, reset_globals):
&#34;&#34;&#34;Test --sendlat&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--setlat&#39;, &#39;37.5&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_writeConfig():
print(&#39;inside mocked writeConfig&#39;)
mocked_node.writeConfig.side_effect = mock_writeConfig
iface = MagicMock(autospec=SerialInterface)
def mock_sendPosition(lat, lon, alt):
print(&#39;inside mocked sendPosition&#39;)
iface.sendPosition.side_effect = mock_sendPosition
iface.localNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing latitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device position&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendPosition&#39;, out, re.MULTILINE)
# TODO: Why does this not work? assert re.search(r&#39;inside mocked writeConfig&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_setlon(capsys, reset_globals):
&#34;&#34;&#34;Test --setlon&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--setlon&#39;, &#39;-122.1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_writeConfig():
print(&#39;inside mocked writeConfig&#39;)
mocked_node.writeConfig.side_effect = mock_writeConfig
iface = MagicMock(autospec=SerialInterface)
def mock_sendPosition(lat, lon, alt):
print(&#39;inside mocked sendPosition&#39;)
iface.sendPosition.side_effect = mock_sendPosition
iface.localNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing longitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device position&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendPosition&#39;, out, re.MULTILINE)
# TODO: Why does this not work? assert re.search(r&#39;inside mocked writeConfig&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_setalt(capsys, reset_globals):
&#34;&#34;&#34;Test --setalt&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--setalt&#39;, &#39;51&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_writeConfig():
print(&#39;inside mocked writeConfig&#39;)
mocked_node.writeConfig.side_effect = mock_writeConfig
iface = MagicMock(autospec=SerialInterface)
def mock_sendPosition(lat, lon, alt):
print(&#39;inside mocked sendPosition&#39;)
iface.sendPosition.side_effect = mock_sendPosition
iface.localNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing altitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device position&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendPosition&#39;, out, re.MULTILINE)
# TODO: Why does this not work? assert re.search(r&#39;inside mocked writeConfig&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_set_team_valid(capsys, reset_globals):
&#34;&#34;&#34;Test --set-team&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set-team&#39;, &#39;CYAN&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_setOwner(team):
print(&#39;inside mocked setOwner&#39;)
mocked_node.setOwner.side_effect = mock_setOwner
iface = MagicMock(autospec=SerialInterface)
iface.localNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
with patch(&#39;meshtastic.mesh_pb2.Team&#39;) as mm:
mm.Name.return_value = &#39;FAKENAME&#39;
mm.Value.return_value = &#39;FAKEVAL&#39;
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting team to&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
mm.Name.assert_called()
mm.Value.assert_called()
@pytest.mark.unit
def test_main_set_team_invalid(capsys, reset_globals):
&#34;&#34;&#34;Test --set-team using an invalid team name&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set-team&#39;, &#39;NOTCYAN&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def throw_an_exception(exc):
raise ValueError(&#34;Fake exception.&#34;)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
with patch(&#39;meshtastic.mesh_pb2.Team&#39;) as mm:
mm.Value.side_effect = throw_an_exception
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;ERROR: Team&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
mm.Value.assert_called()
@pytest.mark.unit
def test_main_seturl(capsys, reset_globals):
&#34;&#34;&#34;Test --seturl (url used below is what is generated after a factory_reset)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--seturl&#39;, &#39;https://www.meshtastic.org/d/#CgUYAyIBAQ&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_set_valid(capsys, reset_globals):
&#34;&#34;&#34;Test --set with valid field&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set&#39;, &#39;wifi_ssid&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Set wifi_ssid to foo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_set_with_invalid(capsys, reset_globals):
&#34;&#34;&#34;Test --set with invalid field&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set&#39;, &#39;foo&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_user_prefs = MagicMock()
mocked_user_prefs.DESCRIPTOR.fields_by_name.get.return_value = None
mocked_node = MagicMock(autospec=Node)
mocked_node.radioConfig.preferences = ( mocked_user_prefs )
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;does not have an attribute called foo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
# TODO: write some negative --configure tests
@pytest.mark.unit
def test_main_configure(capsys, reset_globals):
&#34;&#34;&#34;Test --configure with valid file&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--configure&#39;, &#39;example_config.yaml&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device owner&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting channel url&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing altitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing latitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing longitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified preferences&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_ch_add_valid(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-add with valid channel name, and that channel name does not already exist&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-add&#39;, &#39;testing&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_channel = MagicMock(autospec=Channel)
# TODO: figure out how to get it to print the channel name instead of MagicMock
mocked_node = MagicMock(autospec=Node)
# set it up so we do not already have a channel named this
mocked_node.getChannelByName.return_value = False
# set it up so we have free channels
mocked_node.getDisabledChannel.return_value = mocked_channel
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified channels to device&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_ch_add_invalid_name_too_long(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-add with invalid channel name, name too long&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-add&#39;, &#39;testingtestingtesting&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_channel = MagicMock(autospec=Channel)
# TODO: figure out how to get it to print the channel name instead of MagicMock
mocked_node = MagicMock(autospec=Node)
# set it up so we do not already have a channel named this
mocked_node.getChannelByName.return_value = False
# set it up so we have free channels
mocked_node.getDisabledChannel.return_value = mocked_channel
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Channel name must be shorter&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_ch_add_but_name_already_exists(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-add with a channel name that already exists&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-add&#39;, &#39;testing&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
# set it up so we do not already have a channel named this
mocked_node.getChannelByName.return_value = True
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: This node already has&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_ch_add_but_no_more_channels(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-add with but there are no more channels&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-add&#39;, &#39;testing&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
# set it up so we do not already have a channel named this
mocked_node.getChannelByName.return_value = False
# set it up so we have free channels
mocked_node.getDisabledChannel.return_value = None
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: No free channels were found&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_ch_del(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-del with valid secondary channel to be deleted&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-del&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Deleting channel&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_ch_del_no_ch_index_specified(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-del without a valid ch-index&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-del&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Need to specify&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_ch_del_primary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-del on ch-index=0&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-del&#39;, &#39;--ch-index&#39;, &#39;0&#39;]
Globals.getInstance().set_args(sys.argv)
Globals.getInstance().set_channel_index(1)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Cannot delete primary channel&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_ch_enable_valid_secondary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-enable with --ch-index&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-enable&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified channels&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
assert Globals.getInstance().get_channel_index() == 1
mo.assert_called()
@pytest.mark.unit
def test_main_ch_disable_valid_secondary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-disable with --ch-index&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-disable&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified channels&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
assert Globals.getInstance().get_channel_index() == 1
mo.assert_called()
@pytest.mark.unit
def test_main_ch_enable_without_a_ch_index(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-enable without --ch-index&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-enable&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Need to specify&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
assert Globals.getInstance().get_channel_index() is None
mo.assert_called()
@pytest.mark.unit
def test_main_ch_enable_primary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-enable with --ch-index = 0&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-enable&#39;, &#39;--ch-index&#39;, &#39;0&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Cannot enable/disable PRIMARY&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
assert Globals.getInstance().get_channel_index() == 0
mo.assert_called()
@pytest.mark.unit
def test_main_ch_range_options(capsys, reset_globals):
&#34;&#34;&#34;Test changing the various range options.&#34;&#34;&#34;
range_options = [&#39;--ch-longslow&#39;, &#39;--ch-longfast&#39;, &#39;--ch-mediumslow&#39;,
&#39;--ch-mediumfast&#39;, &#39;--ch-shortslow&#39;, &#39;--ch-shortfast&#39;]
for range_option in range_options:
sys.argv = [&#39;&#39;, f&#34;{range_option}&#34; ]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified channels&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_ch_longsfast_on_non_primary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-longfast --ch-index 1&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-longfast&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Standard channel settings&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
# PositionFlags:
# Misc info that might be helpful (this info will grow stale, just
# a snapshot of the values.) The radioconfig_pb2.PositionFlags.Name and bit values are:
# POS_UNDEFINED 0
# POS_ALTITUDE 1
# POS_ALT_MSL 2
# POS_GEO_SEP 4
# POS_DOP 8
# POS_HVDOP 16
# POS_BATTERY 32
# POS_SATINVIEW 64
# POS_SEQ_NOS 128
# POS_TIMESTAMP 256
@pytest.mark.unit
def test_main_pos_fields_no_args(capsys, reset_globals):
&#34;&#34;&#34;Test --pos-fields no args (which shows settings)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--pos-fields&#39;]
Globals.getInstance().set_args(sys.argv)
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;) as mo:
with patch(&#39;meshtastic.radioconfig_pb2.PositionFlags&#39;, return_value=pos_flags) as mrc:
# kind of cheating here, we are setting up the node
mocked_node = MagicMock(autospec=Node)
anode = mocked_node()
anode.radioConfig.preferences.position_flags = 35
Globals.getInstance().set_target_node(anode)
mrc.values.return_value = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256]
# Note: When you use side_effect and a list, each call will use a value from the front of the list then
# remove that value from the list. If there are three values in the list, we expect it to be called
# three times.
mrc.Name.side_effect = [ &#39;POS_ALTITUDE&#39;, &#39;POS_ALT_MSL&#39;, &#39;POS_BATTERY&#39; ]
main()
mrc.Name.assert_called()
mrc.values.assert_called()
mo.assert_called()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;POS_ALTITUDE POS_ALT_MSL POS_BATTERY&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
@pytest.mark.unit
def test_main_pos_fields_arg_of_zero(capsys, reset_globals):
&#34;&#34;&#34;Test --pos-fields an arg of 0 (which shows list)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--pos-fields&#39;, &#39;0&#39;]
Globals.getInstance().set_args(sys.argv)
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;) as mo:
with patch(&#39;meshtastic.radioconfig_pb2.PositionFlags&#39;, return_value=pos_flags) as mrc:
def throw_value_error_exception(exc):
raise ValueError()
mrc.Value.side_effect = throw_value_error_exception
mrc.keys.return_value = [ &#39;POS_UNDEFINED&#39;, &#39;POS_ALTITUDE&#39;, &#39;POS_ALT_MSL&#39;,
&#39;POS_GEO_SEP&#39;, &#39;POS_DOP&#39;, &#39;POS_HVDOP&#39;, &#39;POS_BATTERY&#39;,
&#39;POS_SATINVIEW&#39;, &#39;POS_SEQ_NOS&#39;, &#39;POS_TIMESTAMP&#39;]
main()
mrc.Value.assert_called()
mrc.keys.assert_called()
mo.assert_called()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;ERROR: supported position fields are:&#39;, out, re.MULTILINE)
assert re.search(r&#34;[&#39;POS_UNDEFINED&#39;, &#39;POS_ALTITUDE&#39;, &#39;POS_ALT_MSL&#39;, &#39;POS_GEO_SEP&#39;,&#34;\
&#34;&#39;POS_DOP&#39;, &#39;POS_HVDOP&#39;, &#39;POS_BATTERY&#39;, &#39;POS_SATINVIEW&#39;, &#39;POS_SEQ_NOS&#39;,&#34;\
&#34;&#39;POS_TIMESTAMP&#39;]&#34;, out, re.MULTILINE)
assert err == &#39;&#39;
@pytest.mark.unit
def test_main_pos_fields_valid_values(capsys, reset_globals):
&#34;&#34;&#34;Test --pos-fields with valid values&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--pos-fields&#39;, &#39;POS_GEO_SEP&#39;, &#39;POS_ALT_MSL&#39;]
Globals.getInstance().set_args(sys.argv)
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;) as mo:
with patch(&#39;meshtastic.radioconfig_pb2.PositionFlags&#39;, return_value=pos_flags) as mrc:
mrc.Value.side_effect = [ 4, 2 ]
main()
mrc.Value.assert_called()
mo.assert_called()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting position fields to 6&#39;, out, re.MULTILINE)
assert re.search(r&#39;Set position_flags to 6&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified preferences to device&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
@pytest.mark.unit
def test_main_get_with_valid_values(capsys, reset_globals):
&#34;&#34;&#34;Test --get with valid values (with string, number, boolean)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--get&#39;, &#39;ls_secs&#39;, &#39;--get&#39;, &#39;wifi_ssid&#39;, &#39;--get&#39;, &#39;fixed_position&#39;]
Globals.getInstance().set_args(sys.argv)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;) as mo:
# kind of cheating here, we are setting up the node
mocked_node = MagicMock(autospec=Node)
anode = mocked_node()
anode.radioConfig.preferences.wifi_ssid = &#39;foo&#39;
anode.radioConfig.preferences.ls_secs = 300
anode.radioConfig.preferences.fixed_position = False
Globals.getInstance().set_target_node(anode)
main()
mo.assert_called()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;ls_secs: 300&#39;, out, re.MULTILINE)
assert re.search(r&#39;wifi_ssid: foo&#39;, out, re.MULTILINE)
assert re.search(r&#39;fixed_position: False&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
@pytest.mark.unit
def test_main_get_with_invalid(capsys, reset_globals):
&#34;&#34;&#34;Test --get with invalid field&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--get&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_user_prefs = MagicMock()
mocked_user_prefs.DESCRIPTOR.fields_by_name.get.return_value = None
mocked_node = MagicMock(autospec=Node)
mocked_node.radioConfig.preferences = ( mocked_user_prefs )
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;does not have an attribute called foo&#39;, out, re.MULTILINE)
assert re.search(r&#39;Choices in sorted order are&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
@pytest.mark.unit
def test_main_setchan(capsys, reset_globals):
&#34;&#34;&#34;Test --setchan (deprecated)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--setchan&#39;, &#39;a&#39;, &#39;b&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface):
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
@pytest.mark.unit
def test_main_onReceive_empty(reset_globals):
&#34;&#34;&#34;Test onReceive&#34;&#34;&#34;
sys.argv = [&#39;&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
packet = {&#39;decoded&#39;: &#39;foo&#39;}
onReceive(packet, iface)
# TODO: how do we know we actually called it?
@pytest.mark.unit
def test_main_onConnection(reset_globals, capsys):
&#34;&#34;&#34;Test onConnection&#34;&#34;&#34;
sys.argv = [&#39;&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
class TempTopic:
&#34;&#34;&#34; temp class for topic &#34;&#34;&#34;
def getName(self):
&#34;&#34;&#34; return the fake name of a topic&#34;&#34;&#34;
return &#39;foo&#39;
mytopic = TempTopic()
onConnection(iface, mytopic)
out, err = capsys.readouterr()
assert re.search(r&#39;Connection changed: foo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="meshtastic.tests.test_main.test_main_ch_add_but_name_already_exists"><code class="name flex">
<span>def <span class="ident">test_main_ch_add_but_name_already_exists</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-add with a channel name that already exists</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_add_but_name_already_exists(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-add with a channel name that already exists&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-add&#39;, &#39;testing&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
# set it up so we do not already have a channel named this
mocked_node.getChannelByName.return_value = True
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: This node already has&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_add_but_no_more_channels"><code class="name flex">
<span>def <span class="ident">test_main_ch_add_but_no_more_channels</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-add with but there are no more channels</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_add_but_no_more_channels(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-add with but there are no more channels&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-add&#39;, &#39;testing&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
# set it up so we do not already have a channel named this
mocked_node.getChannelByName.return_value = False
# set it up so we have free channels
mocked_node.getDisabledChannel.return_value = None
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: No free channels were found&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_add_invalid_name_too_long"><code class="name flex">
<span>def <span class="ident">test_main_ch_add_invalid_name_too_long</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-add with invalid channel name, name too long</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_add_invalid_name_too_long(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-add with invalid channel name, name too long&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-add&#39;, &#39;testingtestingtesting&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_channel = MagicMock(autospec=Channel)
# TODO: figure out how to get it to print the channel name instead of MagicMock
mocked_node = MagicMock(autospec=Node)
# set it up so we do not already have a channel named this
mocked_node.getChannelByName.return_value = False
# set it up so we have free channels
mocked_node.getDisabledChannel.return_value = mocked_channel
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Channel name must be shorter&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_add_valid"><code class="name flex">
<span>def <span class="ident">test_main_ch_add_valid</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-add with valid channel name, and that channel name does not already exist</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_add_valid(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-add with valid channel name, and that channel name does not already exist&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-add&#39;, &#39;testing&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_channel = MagicMock(autospec=Channel)
# TODO: figure out how to get it to print the channel name instead of MagicMock
mocked_node = MagicMock(autospec=Node)
# set it up so we do not already have a channel named this
mocked_node.getChannelByName.return_value = False
# set it up so we have free channels
mocked_node.getDisabledChannel.return_value = mocked_channel
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified channels to device&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_del"><code class="name flex">
<span>def <span class="ident">test_main_ch_del</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-del with valid secondary channel to be deleted</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_del(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-del with valid secondary channel to be deleted&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-del&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Deleting channel&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_del_no_ch_index_specified"><code class="name flex">
<span>def <span class="ident">test_main_ch_del_no_ch_index_specified</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-del without a valid ch-index</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_del_no_ch_index_specified(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-del without a valid ch-index&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-del&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Need to specify&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_del_primary_channel"><code class="name flex">
<span>def <span class="ident">test_main_ch_del_primary_channel</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-del on ch-index=0</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_del_primary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-del on ch-index=0&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-del&#39;, &#39;--ch-index&#39;, &#39;0&#39;]
Globals.getInstance().set_args(sys.argv)
Globals.getInstance().set_channel_index(1)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Cannot delete primary channel&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_disable_valid_secondary_channel"><code class="name flex">
<span>def <span class="ident">test_main_ch_disable_valid_secondary_channel</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-disable with &ndash;ch-index</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_disable_valid_secondary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-disable with --ch-index&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-disable&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified channels&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
assert Globals.getInstance().get_channel_index() == 1
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_enable_primary_channel"><code class="name flex">
<span>def <span class="ident">test_main_ch_enable_primary_channel</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-enable with &ndash;ch-index = 0</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_enable_primary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-enable with --ch-index = 0&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-enable&#39;, &#39;--ch-index&#39;, &#39;0&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Cannot enable/disable PRIMARY&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
assert Globals.getInstance().get_channel_index() == 0
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_enable_valid_secondary_channel"><code class="name flex">
<span>def <span class="ident">test_main_ch_enable_valid_secondary_channel</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-enable with &ndash;ch-index</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_enable_valid_secondary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-enable with --ch-index&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-enable&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified channels&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
assert Globals.getInstance().get_channel_index() == 1
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_enable_without_a_ch_index"><code class="name flex">
<span>def <span class="ident">test_main_ch_enable_without_a_ch_index</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-enable without &ndash;ch-index</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_enable_without_a_ch_index(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-enable without --ch-index&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-enable&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Need to specify&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
assert Globals.getInstance().get_channel_index() is None
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_index_no_devices"><code class="name flex">
<span>def <span class="ident">test_main_ch_index_no_devices</span></span>(<span>patched_find_ports, capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-index 1</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[])
def test_main_ch_index_no_devices(patched_find_ports, capsys, reset_globals):
&#34;&#34;&#34;Test --ch-index 1&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert Globals.getInstance().get_channel_index() == 1
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
out, err = capsys.readouterr()
assert re.search(r&#39;Warning: No Meshtastic devices detected&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
patched_find_ports.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_longsfast_on_non_primary_channel"><code class="name flex">
<span>def <span class="ident">test_main_ch_longsfast_on_non_primary_channel</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;ch-longfast &ndash;ch-index 1</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_longsfast_on_non_primary_channel(capsys, reset_globals):
&#34;&#34;&#34;Test --ch-longfast --ch-index 1&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--ch-longfast&#39;, &#39;--ch-index&#39;, &#39;1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
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&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Warning: Standard channel settings&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_ch_range_options"><code class="name flex">
<span>def <span class="ident">test_main_ch_range_options</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test changing the various range options.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_ch_range_options(capsys, reset_globals):
&#34;&#34;&#34;Test changing the various range options.&#34;&#34;&#34;
range_options = [&#39;--ch-longslow&#39;, &#39;--ch-longfast&#39;, &#39;--ch-mediumslow&#39;,
&#39;--ch-mediumfast&#39;, &#39;--ch-shortslow&#39;, &#39;--ch-shortfast&#39;]
for range_option in range_options:
sys.argv = [&#39;&#39;, f&#34;{range_option}&#34; ]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified channels&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_configure"><code class="name flex">
<span>def <span class="ident">test_main_configure</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;configure with valid file</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_configure(capsys, reset_globals):
&#34;&#34;&#34;Test --configure with valid file&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--configure&#39;, &#39;example_config.yaml&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device owner&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting channel url&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing altitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing latitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing longitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified preferences&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_get_with_invalid"><code class="name flex">
<span>def <span class="ident">test_main_get_with_invalid</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;get with invalid field</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_get_with_invalid(capsys, reset_globals):
&#34;&#34;&#34;Test --get with invalid field&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--get&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_user_prefs = MagicMock()
mocked_user_prefs.DESCRIPTOR.fields_by_name.get.return_value = None
mocked_node = MagicMock(autospec=Node)
mocked_node.radioConfig.preferences = ( mocked_user_prefs )
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;does not have an attribute called foo&#39;, out, re.MULTILINE)
assert re.search(r&#39;Choices in sorted order are&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_get_with_valid_values"><code class="name flex">
<span>def <span class="ident">test_main_get_with_valid_values</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;get with valid values (with string, number, boolean)</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_get_with_valid_values(capsys, reset_globals):
&#34;&#34;&#34;Test --get with valid values (with string, number, boolean)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--get&#39;, &#39;ls_secs&#39;, &#39;--get&#39;, &#39;wifi_ssid&#39;, &#39;--get&#39;, &#39;fixed_position&#39;]
Globals.getInstance().set_args(sys.argv)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;) as mo:
# kind of cheating here, we are setting up the node
mocked_node = MagicMock(autospec=Node)
anode = mocked_node()
anode.radioConfig.preferences.wifi_ssid = &#39;foo&#39;
anode.radioConfig.preferences.ls_secs = 300
anode.radioConfig.preferences.fixed_position = False
Globals.getInstance().set_target_node(anode)
main()
mo.assert_called()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;ls_secs: 300&#39;, out, re.MULTILINE)
assert re.search(r&#39;wifi_ssid: foo&#39;, out, re.MULTILINE)
assert re.search(r&#39;fixed_position: False&#39;, out, re.MULTILINE)
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_info"><code class="name flex">
<span>def <span class="ident">test_main_info</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;info</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_info(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_info_with_ble_interface"><code class="name flex">
<span>def <span class="ident">test_main_info_with_ble_interface</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;info</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_info_with_ble_interface(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--ble&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=BLEInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.ble_interface.BLEInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_info_with_seriallog_output_txt"><code class="name flex">
<span>def <span class="ident">test_main_info_with_seriallog_output_txt</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;info</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_info_with_seriallog_output_txt(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--seriallog&#39;, &#39;output.txt&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
# do some cleanup
os.remove(&#39;output.txt&#39;)</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_info_with_seriallog_stdout"><code class="name flex">
<span>def <span class="ident">test_main_info_with_seriallog_stdout</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;info</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_info_with_seriallog_stdout(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--seriallog&#39;, &#39;stdout&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_info_with_tcp_interface"><code class="name flex">
<span>def <span class="ident">test_main_info_with_tcp_interface</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;info</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_info_with_tcp_interface(capsys, reset_globals):
&#34;&#34;&#34;Test --info&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--host&#39;, &#39;meshtastic.local&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=TCPInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
with patch(&#39;meshtastic.tcp_interface.TCPInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_init_parser_no_args"><code class="name flex">
<span>def <span class="ident">test_main_init_parser_no_args</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test no arguments</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_init_parser_no_args(capsys, reset_globals):
&#34;&#34;&#34;Test no arguments&#34;&#34;&#34;
sys.argv = [&#39;&#39;]
Globals.getInstance().set_args(sys.argv)
initParser()
out, err = capsys.readouterr()
assert out == &#39;&#39;
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_init_parser_version"><code class="name flex">
<span>def <span class="ident">test_main_init_parser_version</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;version</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_init_parser_version(capsys, reset_globals):
&#34;&#34;&#34;Test --version&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--version&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
initParser()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
out, err = capsys.readouterr()
assert re.match(r&#39;[0-9]+\.[0-9]+\.[0-9]&#39;, out)
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_main_no_args"><code class="name flex">
<span>def <span class="ident">test_main_main_no_args</span></span>(<span>reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test with no args</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_main_no_args(reset_globals):
&#34;&#34;&#34;Test with no args&#34;&#34;&#34;
sys.argv = [&#39;&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_main_version"><code class="name flex">
<span>def <span class="ident">test_main_main_version</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;version</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_main_version(capsys, reset_globals):
&#34;&#34;&#34;Test --version&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--version&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
out, err = capsys.readouterr()
assert re.match(r&#39;[0-9]+\.[0-9]+\.[0-9]&#39;, out)
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_no_proto"><code class="name flex">
<span>def <span class="ident">test_main_no_proto</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;noproto (using &ndash;info for output)</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_no_proto(capsys, reset_globals):
&#34;&#34;&#34;Test --noproto (using --info for output)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--info&#39;, &#39;--noproto&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showInfo():
print(&#39;inside mocked showInfo&#39;)
iface.showInfo.side_effect = mock_showInfo
# Override the time.sleep so there is no loop
def my_sleep(amount):
sys.exit(0)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface):
with patch(&#39;time.sleep&#39;, side_effect=my_sleep):
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showInfo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_nodes"><code class="name flex">
<span>def <span class="ident">test_main_nodes</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;nodes</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_nodes(capsys, reset_globals):
&#34;&#34;&#34;Test --nodes&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--nodes&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_showNodes():
print(&#39;inside mocked showNodes&#39;)
iface.showNodes.side_effect = mock_showNodes
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked showNodes&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_onConnection"><code class="name flex">
<span>def <span class="ident">test_main_onConnection</span></span>(<span>reset_globals, capsys)</span>
</code></dt>
<dd>
<div class="desc"><p>Test onConnection</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_onConnection(reset_globals, capsys):
&#34;&#34;&#34;Test onConnection&#34;&#34;&#34;
sys.argv = [&#39;&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
class TempTopic:
&#34;&#34;&#34; temp class for topic &#34;&#34;&#34;
def getName(self):
&#34;&#34;&#34; return the fake name of a topic&#34;&#34;&#34;
return &#39;foo&#39;
mytopic = TempTopic()
onConnection(iface, mytopic)
out, err = capsys.readouterr()
assert re.search(r&#39;Connection changed: foo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_onReceive_empty"><code class="name flex">
<span>def <span class="ident">test_main_onReceive_empty</span></span>(<span>reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test onReceive</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_onReceive_empty(reset_globals):
&#34;&#34;&#34;Test onReceive&#34;&#34;&#34;
sys.argv = [&#39;&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
packet = {&#39;decoded&#39;: &#39;foo&#39;}
onReceive(packet, iface)
# TODO: how do we know we actually called it?</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_pos_fields_arg_of_zero"><code class="name flex">
<span>def <span class="ident">test_main_pos_fields_arg_of_zero</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;pos-fields an arg of 0 (which shows list)</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_pos_fields_arg_of_zero(capsys, reset_globals):
&#34;&#34;&#34;Test --pos-fields an arg of 0 (which shows list)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--pos-fields&#39;, &#39;0&#39;]
Globals.getInstance().set_args(sys.argv)
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;) as mo:
with patch(&#39;meshtastic.radioconfig_pb2.PositionFlags&#39;, return_value=pos_flags) as mrc:
def throw_value_error_exception(exc):
raise ValueError()
mrc.Value.side_effect = throw_value_error_exception
mrc.keys.return_value = [ &#39;POS_UNDEFINED&#39;, &#39;POS_ALTITUDE&#39;, &#39;POS_ALT_MSL&#39;,
&#39;POS_GEO_SEP&#39;, &#39;POS_DOP&#39;, &#39;POS_HVDOP&#39;, &#39;POS_BATTERY&#39;,
&#39;POS_SATINVIEW&#39;, &#39;POS_SEQ_NOS&#39;, &#39;POS_TIMESTAMP&#39;]
main()
mrc.Value.assert_called()
mrc.keys.assert_called()
mo.assert_called()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;ERROR: supported position fields are:&#39;, out, re.MULTILINE)
assert re.search(r&#34;[&#39;POS_UNDEFINED&#39;, &#39;POS_ALTITUDE&#39;, &#39;POS_ALT_MSL&#39;, &#39;POS_GEO_SEP&#39;,&#34;\
&#34;&#39;POS_DOP&#39;, &#39;POS_HVDOP&#39;, &#39;POS_BATTERY&#39;, &#39;POS_SATINVIEW&#39;, &#39;POS_SEQ_NOS&#39;,&#34;\
&#34;&#39;POS_TIMESTAMP&#39;]&#34;, out, re.MULTILINE)
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_pos_fields_no_args"><code class="name flex">
<span>def <span class="ident">test_main_pos_fields_no_args</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;pos-fields no args (which shows settings)</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_pos_fields_no_args(capsys, reset_globals):
&#34;&#34;&#34;Test --pos-fields no args (which shows settings)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--pos-fields&#39;]
Globals.getInstance().set_args(sys.argv)
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;) as mo:
with patch(&#39;meshtastic.radioconfig_pb2.PositionFlags&#39;, return_value=pos_flags) as mrc:
# kind of cheating here, we are setting up the node
mocked_node = MagicMock(autospec=Node)
anode = mocked_node()
anode.radioConfig.preferences.position_flags = 35
Globals.getInstance().set_target_node(anode)
mrc.values.return_value = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256]
# Note: When you use side_effect and a list, each call will use a value from the front of the list then
# remove that value from the list. If there are three values in the list, we expect it to be called
# three times.
mrc.Name.side_effect = [ &#39;POS_ALTITUDE&#39;, &#39;POS_ALT_MSL&#39;, &#39;POS_BATTERY&#39; ]
main()
mrc.Name.assert_called()
mrc.values.assert_called()
mo.assert_called()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;POS_ALTITUDE POS_ALT_MSL POS_BATTERY&#39;, out, re.MULTILINE)
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_pos_fields_valid_values"><code class="name flex">
<span>def <span class="ident">test_main_pos_fields_valid_values</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;pos-fields with valid values</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_pos_fields_valid_values(capsys, reset_globals):
&#34;&#34;&#34;Test --pos-fields with valid values&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--pos-fields&#39;, &#39;POS_GEO_SEP&#39;, &#39;POS_ALT_MSL&#39;]
Globals.getInstance().set_args(sys.argv)
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;) as mo:
with patch(&#39;meshtastic.radioconfig_pb2.PositionFlags&#39;, return_value=pos_flags) as mrc:
mrc.Value.side_effect = [ 4, 2 ]
main()
mrc.Value.assert_called()
mo.assert_called()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting position fields to 6&#39;, out, re.MULTILINE)
assert re.search(r&#39;Set position_flags to 6&#39;, out, re.MULTILINE)
assert re.search(r&#39;Writing modified preferences to device&#39;, out, re.MULTILINE)
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_qr"><code class="name flex">
<span>def <span class="ident">test_main_qr</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;qr</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_qr(capsys, reset_globals):
&#34;&#34;&#34;Test --qr&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--qr&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
# TODO: could mock/check url
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Primary channel URL&#39;, out, re.MULTILINE)
# if a qr code is generated it will have lots of these
assert re.search(r&#39;\[7m&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_reboot"><code class="name flex">
<span>def <span class="ident">test_main_reboot</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;reboot</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_reboot(capsys, reset_globals):
&#34;&#34;&#34;Test --reboot&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--reboot&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_reboot():
print(&#39;inside mocked reboot&#39;)
mocked_node.reboot.side_effect = mock_reboot
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked reboot&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_sendping"><code class="name flex">
<span>def <span class="ident">test_main_sendping</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;sendping</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_sendping(capsys, reset_globals):
&#34;&#34;&#34;Test --sendping&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--sendping&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_sendData(payload, dest, portNum, wantAck, wantResponse):
print(&#39;inside mocked sendData&#39;)
iface.sendData.side_effect = mock_sendData
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Sending ping message&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendData&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_sendtext"><code class="name flex">
<span>def <span class="ident">test_main_sendtext</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;sendtext</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_sendtext(capsys, reset_globals):
&#34;&#34;&#34;Test --sendtext&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--sendtext&#39;, &#39;hello&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_sendText(text, dest, wantAck):
print(&#39;inside mocked sendText&#39;)
iface.sendText.side_effect = mock_sendText
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Sending text message&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendText&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_sendtext_with_dest"><code class="name flex">
<span>def <span class="ident">test_main_sendtext_with_dest</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;sendtext with &ndash;dest</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_sendtext_with_dest(capsys, reset_globals):
&#34;&#34;&#34;Test --sendtext with --dest&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--sendtext&#39;, &#39;hello&#39;, &#39;--dest&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def mock_sendText(text, dest, wantAck):
print(&#39;inside mocked sendText&#39;)
iface.sendText.side_effect = mock_sendText
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Sending text message&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendText&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_set_ham_to_KI123"><code class="name flex">
<span>def <span class="ident">test_main_set_ham_to_KI123</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;set-ham KI123</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_set_ham_to_KI123(capsys, reset_globals):
&#34;&#34;&#34;Test --set-ham KI123&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set-ham&#39;, &#39;KI123&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_turnOffEncryptionOnPrimaryChannel():
print(&#39;inside mocked turnOffEncryptionOnPrimaryChannel&#39;)
def mock_setOwner(name, is_licensed):
print(&#39;inside mocked setOwner&#39;)
mocked_node.turnOffEncryptionOnPrimaryChannel.side_effect = mock_turnOffEncryptionOnPrimaryChannel
mocked_node.setOwner.side_effect = mock_setOwner
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting HAM ID to KI123&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked setOwner&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked turnOffEncryptionOnPrimaryChannel&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_set_owner_to_bob"><code class="name flex">
<span>def <span class="ident">test_main_set_owner_to_bob</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;set-owner bob</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_set_owner_to_bob(capsys, reset_globals):
&#34;&#34;&#34;Test --set-owner bob&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set-owner&#39;, &#39;bob&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device owner to bob&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_set_team_invalid"><code class="name flex">
<span>def <span class="ident">test_main_set_team_invalid</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;set-team using an invalid team name</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_set_team_invalid(capsys, reset_globals):
&#34;&#34;&#34;Test --set-team using an invalid team name&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set-team&#39;, &#39;NOTCYAN&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
def throw_an_exception(exc):
raise ValueError(&#34;Fake exception.&#34;)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
with patch(&#39;meshtastic.mesh_pb2.Team&#39;) as mm:
mm.Value.side_effect = throw_an_exception
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;ERROR: Team&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
mm.Value.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_set_team_valid"><code class="name flex">
<span>def <span class="ident">test_main_set_team_valid</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;set-team</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_set_team_valid(capsys, reset_globals):
&#34;&#34;&#34;Test --set-team&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set-team&#39;, &#39;CYAN&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_setOwner(team):
print(&#39;inside mocked setOwner&#39;)
mocked_node.setOwner.side_effect = mock_setOwner
iface = MagicMock(autospec=SerialInterface)
iface.localNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
with patch(&#39;meshtastic.mesh_pb2.Team&#39;) as mm:
mm.Name.return_value = &#39;FAKENAME&#39;
mm.Value.return_value = &#39;FAKEVAL&#39;
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting team to&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()
mm.Name.assert_called()
mm.Value.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_set_valid"><code class="name flex">
<span>def <span class="ident">test_main_set_valid</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;set with valid field</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_set_valid(capsys, reset_globals):
&#34;&#34;&#34;Test --set with valid field&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set&#39;, &#39;wifi_ssid&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Set wifi_ssid to foo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_set_with_invalid"><code class="name flex">
<span>def <span class="ident">test_main_set_with_invalid</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;set with invalid field</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_set_with_invalid(capsys, reset_globals):
&#34;&#34;&#34;Test --set with invalid field&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--set&#39;, &#39;foo&#39;, &#39;foo&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_user_prefs = MagicMock()
mocked_user_prefs.DESCRIPTOR.fields_by_name.get.return_value = None
mocked_node = MagicMock(autospec=Node)
mocked_node.radioConfig.preferences = ( mocked_user_prefs )
iface = MagicMock(autospec=SerialInterface)
iface.getNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;does not have an attribute called foo&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_setalt"><code class="name flex">
<span>def <span class="ident">test_main_setalt</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;setalt</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_setalt(capsys, reset_globals):
&#34;&#34;&#34;Test --setalt&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--setalt&#39;, &#39;51&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_writeConfig():
print(&#39;inside mocked writeConfig&#39;)
mocked_node.writeConfig.side_effect = mock_writeConfig
iface = MagicMock(autospec=SerialInterface)
def mock_sendPosition(lat, lon, alt):
print(&#39;inside mocked sendPosition&#39;)
iface.sendPosition.side_effect = mock_sendPosition
iface.localNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing altitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device position&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendPosition&#39;, out, re.MULTILINE)
# TODO: Why does this not work? assert re.search(r&#39;inside mocked writeConfig&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_setchan"><code class="name flex">
<span>def <span class="ident">test_main_setchan</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;setchan (deprecated)</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_setchan(capsys, reset_globals):
&#34;&#34;&#34;Test --setchan (deprecated)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--setchan&#39;, &#39;a&#39;, &#39;b&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface):
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_setlat"><code class="name flex">
<span>def <span class="ident">test_main_setlat</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;sendlat</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_setlat(capsys, reset_globals):
&#34;&#34;&#34;Test --sendlat&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--setlat&#39;, &#39;37.5&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_writeConfig():
print(&#39;inside mocked writeConfig&#39;)
mocked_node.writeConfig.side_effect = mock_writeConfig
iface = MagicMock(autospec=SerialInterface)
def mock_sendPosition(lat, lon, alt):
print(&#39;inside mocked sendPosition&#39;)
iface.sendPosition.side_effect = mock_sendPosition
iface.localNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing latitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device position&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendPosition&#39;, out, re.MULTILINE)
# TODO: Why does this not work? assert re.search(r&#39;inside mocked writeConfig&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_setlon"><code class="name flex">
<span>def <span class="ident">test_main_setlon</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;setlon</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_setlon(capsys, reset_globals):
&#34;&#34;&#34;Test --setlon&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--setlon&#39;, &#39;-122.1&#39;]
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
def mock_writeConfig():
print(&#39;inside mocked writeConfig&#39;)
mocked_node.writeConfig.side_effect = mock_writeConfig
iface = MagicMock(autospec=SerialInterface)
def mock_sendPosition(lat, lon, alt):
print(&#39;inside mocked sendPosition&#39;)
iface.sendPosition.side_effect = mock_sendPosition
iface.localNode.return_value = mocked_node
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert re.search(r&#39;Fixing longitude&#39;, out, re.MULTILINE)
assert re.search(r&#39;Setting device position&#39;, out, re.MULTILINE)
assert re.search(r&#39;inside mocked sendPosition&#39;, out, re.MULTILINE)
# TODO: Why does this not work? assert re.search(r&#39;inside mocked writeConfig&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_seturl"><code class="name flex">
<span>def <span class="ident">test_main_seturl</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;seturl (url used below is what is generated after a factory_reset)</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_seturl(capsys, reset_globals):
&#34;&#34;&#34;Test --seturl (url used below is what is generated after a factory_reset)&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--seturl&#39;, &#39;https://www.meshtastic.org/d/#CgUYAyIBAQ&#39;]
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
with patch(&#39;meshtastic.serial_interface.SerialInterface&#39;, return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r&#39;Connected to radio&#39;, out, re.MULTILINE)
assert err == &#39;&#39;
mo.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_support"><code class="name flex">
<span>def <span class="ident">test_main_support</span></span>(<span>capsys, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;support</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
def test_main_support(capsys, reset_globals):
&#34;&#34;&#34;Test --support&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--support&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
out, err = capsys.readouterr()
assert re.search(r&#39;System&#39;, out, re.MULTILINE)
assert re.search(r&#39;Platform&#39;, out, re.MULTILINE)
assert re.search(r&#39;Machine&#39;, out, re.MULTILINE)
assert re.search(r&#39;Executable&#39;, out, re.MULTILINE)
assert err == &#39;&#39;</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_test_no_ports"><code class="name flex">
<span>def <span class="ident">test_main_test_no_ports</span></span>(<span>patched_find_ports, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;test with no hardware</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[])
def test_main_test_no_ports(patched_find_ports, reset_globals):
&#34;&#34;&#34;Test --test with no hardware&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--test&#39;]
Globals.getInstance().set_args(sys.argv)
assert Globals.getInstance().get_target_node() is None
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
patched_find_ports.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_test_one_port"><code class="name flex">
<span>def <span class="ident">test_main_test_one_port</span></span>(<span>patched_find_ports, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;test with one fake port</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[&#39;/dev/ttyFake1&#39;])
def test_main_test_one_port(patched_find_ports, reset_globals):
&#34;&#34;&#34;Test --test with one fake port&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--test&#39;]
Globals.getInstance().set_args(sys.argv)
assert Globals.getInstance().get_target_node() is None
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
patched_find_ports.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_test_two_ports_fails"><code class="name flex">
<span>def <span class="ident">test_main_test_two_ports_fails</span></span>(<span>patched_find_ports, patched_test_all, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;test two fake ports and testAll() is a simulated failure</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
@patch(&#39;meshtastic.test.testAll&#39;, return_value=False)
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[&#39;/dev/ttyFake1&#39;, &#39;/dev/ttyFake2&#39;])
def test_main_test_two_ports_fails(patched_find_ports, patched_test_all, reset_globals):
&#34;&#34;&#34;Test --test two fake ports and testAll() is a simulated failure&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--test&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
# TODO: why does this fail? patched_find_ports.assert_called()
patched_test_all.assert_called()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.test_main_test_two_ports_success"><code class="name flex">
<span>def <span class="ident">test_main_test_two_ports_success</span></span>(<span>patched_find_ports, patched_test_all, reset_globals)</span>
</code></dt>
<dd>
<div class="desc"><p>Test &ndash;test two fake ports and testAll() is a simulated success</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@pytest.mark.unit
@patch(&#39;meshtastic.test.testAll&#39;, return_value=True)
@patch(&#39;meshtastic.util.findPorts&#39;, return_value=[&#39;/dev/ttyFake1&#39;, &#39;/dev/ttyFake2&#39;])
def test_main_test_two_ports_success(patched_find_ports, patched_test_all, reset_globals):
&#34;&#34;&#34;Test --test two fake ports and testAll() is a simulated success&#34;&#34;&#34;
sys.argv = [&#39;&#39;, &#39;--test&#39;]
Globals.getInstance().set_args(sys.argv)
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
# TODO: why does this fail? patched_find_ports.assert_called()
patched_test_all.assert_called()</code></pre>
</details>
</dd>
</dl>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="meshtastic.tests.test_main.Channel"><code class="flex name class">
<span>class <span class="ident">Channel</span></span>
<span>(</span><span>**kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>Abstract base class for protocol messages.</p>
<p>Protocol message classes are almost always generated by the protocol
compiler.
These generated types subclass Message and implement the methods
shown below.</p></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>google.protobuf.message.Message</li>
</ul>
<h3>Class variables</h3>
<dl>
<dt id="meshtastic.tests.test_main.Channel.DESCRIPTOR"><code class="name">var <span class="ident">DESCRIPTOR</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="meshtastic.tests.test_main.Channel.DISABLED"><code class="name">var <span class="ident">DISABLED</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="meshtastic.tests.test_main.Channel.INDEX_FIELD_NUMBER"><code class="name">var <span class="ident">INDEX_FIELD_NUMBER</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="meshtastic.tests.test_main.Channel.PRIMARY"><code class="name">var <span class="ident">PRIMARY</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="meshtastic.tests.test_main.Channel.ROLE_FIELD_NUMBER"><code class="name">var <span class="ident">ROLE_FIELD_NUMBER</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="meshtastic.tests.test_main.Channel.Role"><code class="name">var <span class="ident">Role</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="meshtastic.tests.test_main.Channel.SECONDARY"><code class="name">var <span class="ident">SECONDARY</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="meshtastic.tests.test_main.Channel.SETTINGS_FIELD_NUMBER"><code class="name">var <span class="ident">SETTINGS_FIELD_NUMBER</span></code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Static methods</h3>
<dl>
<dt id="meshtastic.tests.test_main.Channel.FromString"><code class="name flex">
<span>def <span class="ident">FromString</span></span>(<span>s)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def FromString(s):
message = cls()
message.MergeFromString(s)
return message</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.RegisterExtension"><code class="name flex">
<span>def <span class="ident">RegisterExtension</span></span>(<span>extension_handle)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def RegisterExtension(extension_handle):
extension_handle.containing_type = cls.DESCRIPTOR
# TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
# pylint: disable=protected-access
cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(extension_handle)
_AttachFieldHelpers(cls, extension_handle)</code></pre>
</details>
</dd>
</dl>
<h3>Instance variables</h3>
<dl>
<dt id="meshtastic.tests.test_main.Channel.index"><code class="name">var <span class="ident">index</span></code></dt>
<dd>
<div class="desc"><p>Getter for index.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def getter(self):
# TODO(protobuf-team): This may be broken since there may not be
# default_value. Combine with has_default_value somehow.
return self._fields.get(field, default_value)</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.role"><code class="name">var <span class="ident">role</span></code></dt>
<dd>
<div class="desc"><p>Getter for role.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def getter(self):
# TODO(protobuf-team): This may be broken since there may not be
# default_value. Combine with has_default_value somehow.
return self._fields.get(field, default_value)</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.settings"><code class="name">var <span class="ident">settings</span></code></dt>
<dd>
<div class="desc"><p>Getter for settings.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def getter(self):
field_value = self._fields.get(field)
if field_value is None:
# Construct a new object to represent this field.
field_value = field._default_constructor(self)
# Atomically check if another thread has preempted us and, if not, swap
# in the new object we just created. If someone has preempted us, we
# take that object and discard ours.
# WARNING: We are relying on setdefault() being atomic. This is true
# in CPython but we haven&#39;t investigated others. This warning appears
# in several other locations in this file.
field_value = self._fields.setdefault(field, field_value)
return field_value</code></pre>
</details>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="meshtastic.tests.test_main.Channel.ByteSize"><code class="name flex">
<span>def <span class="ident">ByteSize</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def ByteSize(self):
if not self._cached_byte_size_dirty:
return self._cached_byte_size
size = 0
descriptor = self.DESCRIPTOR
if descriptor.GetOptions().map_entry:
# Fields of map entry should always be serialized.
size = descriptor.fields_by_name[&#39;key&#39;]._sizer(self.key)
size += descriptor.fields_by_name[&#39;value&#39;]._sizer(self.value)
else:
for field_descriptor, field_value in self.ListFields():
size += field_descriptor._sizer(field_value)
for tag_bytes, value_bytes in self._unknown_fields:
size += len(tag_bytes) + len(value_bytes)
self._cached_byte_size = size
self._cached_byte_size_dirty = False
self._listener_for_children.dirty = False
return size</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.Clear"><code class="name flex">
<span>def <span class="ident">Clear</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def _Clear(self):
# Clear fields.
self._fields = {}
self._unknown_fields = ()
# pylint: disable=protected-access
if self._unknown_field_set is not None:
self._unknown_field_set._clear()
self._unknown_field_set = None
self._oneofs = {}
self._Modified()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.ClearField"><code class="name flex">
<span>def <span class="ident">ClearField</span></span>(<span>self, field_name)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def ClearField(self, field_name):
try:
field = message_descriptor.fields_by_name[field_name]
except KeyError:
try:
field = message_descriptor.oneofs_by_name[field_name]
if field in self._oneofs:
field = self._oneofs[field]
else:
return
except KeyError:
raise ValueError(&#39;Protocol message %s has no &#34;%s&#34; field.&#39; %
(message_descriptor.name, field_name))
if field in self._fields:
# To match the C++ implementation, we need to invalidate iterators
# for map fields when ClearField() happens.
if hasattr(self._fields[field], &#39;InvalidateIterators&#39;):
self._fields[field].InvalidateIterators()
# Note: If the field is a sub-message, its listener will still point
# at us. That&#39;s fine, because the worst than can happen is that it
# will call _Modified() and invalidate our byte size. Big deal.
del self._fields[field]
if self._oneofs.get(field.containing_oneof, None) is field:
del self._oneofs[field.containing_oneof]
# Always call _Modified() -- even if nothing was changed, this is
# a mutating method, and thus calling it should cause the field to become
# present in the parent message.
self._Modified()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.DiscardUnknownFields"><code class="name flex">
<span>def <span class="ident">DiscardUnknownFields</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def _DiscardUnknownFields(self):
self._unknown_fields = []
self._unknown_field_set = None # pylint: disable=protected-access
for field, value in self.ListFields():
if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
if _IsMapField(field):
if _IsMessageMapField(field):
for key in value:
value[key].DiscardUnknownFields()
elif field.label == _FieldDescriptor.LABEL_REPEATED:
for sub_message in value:
sub_message.DiscardUnknownFields()
else:
value.DiscardUnknownFields()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.FindInitializationErrors"><code class="name flex">
<span>def <span class="ident">FindInitializationErrors</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"><p>Finds required fields which are not initialized.</p>
<h2 id="returns">Returns</h2>
<p>A list of strings.
Each string is a path to an uninitialized field from
the top-level message, e.g. "foo.bar[5].baz".</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def FindInitializationErrors(self):
&#34;&#34;&#34;Finds required fields which are not initialized.
Returns:
A list of strings. Each string is a path to an uninitialized field from
the top-level message, e.g. &#34;foo.bar[5].baz&#34;.
&#34;&#34;&#34;
errors = [] # simplify things
for field in required_fields:
if not self.HasField(field.name):
errors.append(field.name)
for field, value in self.ListFields():
if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
if field.is_extension:
name = &#39;(%s)&#39; % field.full_name
else:
name = field.name
if _IsMapField(field):
if _IsMessageMapField(field):
for key in value:
element = value[key]
prefix = &#39;%s[%s].&#39; % (name, key)
sub_errors = element.FindInitializationErrors()
errors += [prefix + error for error in sub_errors]
else:
# ScalarMaps can&#39;t have any initialization errors.
pass
elif field.label == _FieldDescriptor.LABEL_REPEATED:
for i in range(len(value)):
element = value[i]
prefix = &#39;%s[%d].&#39; % (name, i)
sub_errors = element.FindInitializationErrors()
errors += [prefix + error for error in sub_errors]
else:
prefix = name + &#39;.&#39;
sub_errors = value.FindInitializationErrors()
errors += [prefix + error for error in sub_errors]
return errors</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.HasField"><code class="name flex">
<span>def <span class="ident">HasField</span></span>(<span>self, field_name)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def HasField(self, field_name):
try:
field = hassable_fields[field_name]
except KeyError:
raise ValueError(error_msg % (message_descriptor.full_name, field_name))
if isinstance(field, descriptor_mod.OneofDescriptor):
try:
return HasField(self, self._oneofs[field].name)
except KeyError:
return False
else:
if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
value = self._fields.get(field)
return value is not None and value._is_present_in_parent
else:
return field in self._fields</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.IsInitialized"><code class="name flex">
<span>def <span class="ident">IsInitialized</span></span>(<span>self, errors=None)</span>
</code></dt>
<dd>
<div class="desc"><p>Checks if all required fields of a message are set.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>errors</code></strong></dt>
<dd>A list which, if provided, will be populated with the field
paths of all missing required fields.</dd>
</dl>
<h2 id="returns">Returns</h2>
<p>True iff the specified message has all required fields set.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def IsInitialized(self, errors=None):
&#34;&#34;&#34;Checks if all required fields of a message are set.
Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
&#34;&#34;&#34;
# Performance is critical so we avoid HasField() and ListFields().
for field in required_fields:
if (field not in self._fields or
(field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE and
not self._fields[field]._is_present_in_parent)):
if errors is not None:
errors.extend(self.FindInitializationErrors())
return False
for field, value in list(self._fields.items()): # dict can change size!
if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
if field.label == _FieldDescriptor.LABEL_REPEATED:
if (field.message_type.has_options and
field.message_type.GetOptions().map_entry):
continue
for element in value:
if not element.IsInitialized():
if errors is not None:
errors.extend(self.FindInitializationErrors())
return False
elif value._is_present_in_parent and not value.IsInitialized():
if errors is not None:
errors.extend(self.FindInitializationErrors())
return False
return True</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.ListFields"><code class="name flex">
<span>def <span class="ident">ListFields</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def ListFields(self):
all_fields = [item for item in self._fields.items() if _IsPresent(item)]
all_fields.sort(key = lambda item: item[0].number)
return all_fields</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.MergeFrom"><code class="name flex">
<span>def <span class="ident">MergeFrom</span></span>(<span>self, msg)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def MergeFrom(self, msg):
if not isinstance(msg, cls):
raise TypeError(
&#39;Parameter to MergeFrom() must be instance of same class: &#39;
&#39;expected %s got %s.&#39; % (_FullyQualifiedClassName(cls),
_FullyQualifiedClassName(msg.__class__)))
assert msg is not self
self._Modified()
fields = self._fields
for field, value in msg._fields.items():
if field.label == LABEL_REPEATED:
field_value = fields.get(field)
if field_value is None:
# Construct a new object to represent this field.
field_value = field._default_constructor(self)
fields[field] = field_value
field_value.MergeFrom(value)
elif field.cpp_type == CPPTYPE_MESSAGE:
if value._is_present_in_parent:
field_value = fields.get(field)
if field_value is None:
# Construct a new object to represent this field.
field_value = field._default_constructor(self)
fields[field] = field_value
field_value.MergeFrom(value)
else:
self._fields[field] = value
if field.containing_oneof:
self._UpdateOneofState(field)
if msg._unknown_fields:
if not self._unknown_fields:
self._unknown_fields = []
self._unknown_fields.extend(msg._unknown_fields)
# pylint: disable=protected-access
if self._unknown_field_set is None:
self._unknown_field_set = containers.UnknownFieldSet()
self._unknown_field_set._extend(msg._unknown_field_set)</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.MergeFromString"><code class="name flex">
<span>def <span class="ident">MergeFromString</span></span>(<span>self, serialized)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def MergeFromString(self, serialized):
serialized = memoryview(serialized)
length = len(serialized)
try:
if self._InternalParse(serialized, 0, length) != length:
# The only reason _InternalParse would return early is if it
# encountered an end-group tag.
raise message_mod.DecodeError(&#39;Unexpected end-group tag.&#39;)
except (IndexError, TypeError):
# Now ord(buf[p:p+1]) == ord(&#39;&#39;) gets TypeError.
raise message_mod.DecodeError(&#39;Truncated message.&#39;)
except struct.error as e:
raise message_mod.DecodeError(e)
return length # Return this for legacy reasons.</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.SerializePartialToString"><code class="name flex">
<span>def <span class="ident">SerializePartialToString</span></span>(<span>self, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def SerializePartialToString(self, **kwargs):
out = BytesIO()
self._InternalSerialize(out.write, **kwargs)
return out.getvalue()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.SerializeToString"><code class="name flex">
<span>def <span class="ident">SerializeToString</span></span>(<span>self, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def SerializeToString(self, **kwargs):
# Check if the message has all of its required fields set.
if not self.IsInitialized():
raise message_mod.EncodeError(
&#39;Message %s is missing required fields: %s&#39; % (
self.DESCRIPTOR.full_name, &#39;,&#39;.join(self.FindInitializationErrors())))
return self.SerializePartialToString(**kwargs)</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.SetInParent"><code class="name flex">
<span>def <span class="ident">SetInParent</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"><p>Sets the _cached_byte_size_dirty bit to true,
and propagates this to our listener iff this was a state change.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def Modified(self):
&#34;&#34;&#34;Sets the _cached_byte_size_dirty bit to true,
and propagates this to our listener iff this was a state change.
&#34;&#34;&#34;
# Note: Some callers check _cached_byte_size_dirty before calling
# _Modified() as an extra optimization. So, if this method is ever
# changed such that it does stuff even when _cached_byte_size_dirty is
# already true, the callers need to be updated.
if not self._cached_byte_size_dirty:
self._cached_byte_size_dirty = True
self._listener_for_children.dirty = True
self._is_present_in_parent = True
self._listener.Modified()</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.UnknownFields"><code class="name flex">
<span>def <span class="ident">UnknownFields</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def _UnknownFields(self):
if self._unknown_field_set is None: # pylint: disable=protected-access
# pylint: disable=protected-access
self._unknown_field_set = containers.UnknownFieldSet()
return self._unknown_field_set # pylint: disable=protected-access</code></pre>
</details>
</dd>
<dt id="meshtastic.tests.test_main.Channel.WhichOneof"><code class="name flex">
<span>def <span class="ident">WhichOneof</span></span>(<span>self, oneof_name)</span>
</code></dt>
<dd>
<div class="desc"><p>Returns the name of the currently set field inside a oneof, or None.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def WhichOneof(self, oneof_name):
&#34;&#34;&#34;Returns the name of the currently set field inside a oneof, or None.&#34;&#34;&#34;
try:
field = message_descriptor.oneofs_by_name[oneof_name]
except KeyError:
raise ValueError(
&#39;Protocol message has no oneof &#34;%s&#34; field.&#39; % oneof_name)
nested_field = self._oneofs.get(field, None)
if nested_field is not None and self.HasField(nested_field.name):
return nested_field.name
else:
return None</code></pre>
</details>
</dd>
</dl>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="meshtastic.tests" href="index.html">meshtastic.tests</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="meshtastic.tests.test_main.test_main_ch_add_but_name_already_exists" href="#meshtastic.tests.test_main.test_main_ch_add_but_name_already_exists">test_main_ch_add_but_name_already_exists</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_add_but_no_more_channels" href="#meshtastic.tests.test_main.test_main_ch_add_but_no_more_channels">test_main_ch_add_but_no_more_channels</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_add_invalid_name_too_long" href="#meshtastic.tests.test_main.test_main_ch_add_invalid_name_too_long">test_main_ch_add_invalid_name_too_long</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_add_valid" href="#meshtastic.tests.test_main.test_main_ch_add_valid">test_main_ch_add_valid</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_del" href="#meshtastic.tests.test_main.test_main_ch_del">test_main_ch_del</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_del_no_ch_index_specified" href="#meshtastic.tests.test_main.test_main_ch_del_no_ch_index_specified">test_main_ch_del_no_ch_index_specified</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_del_primary_channel" href="#meshtastic.tests.test_main.test_main_ch_del_primary_channel">test_main_ch_del_primary_channel</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_disable_valid_secondary_channel" href="#meshtastic.tests.test_main.test_main_ch_disable_valid_secondary_channel">test_main_ch_disable_valid_secondary_channel</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_enable_primary_channel" href="#meshtastic.tests.test_main.test_main_ch_enable_primary_channel">test_main_ch_enable_primary_channel</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_enable_valid_secondary_channel" href="#meshtastic.tests.test_main.test_main_ch_enable_valid_secondary_channel">test_main_ch_enable_valid_secondary_channel</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_enable_without_a_ch_index" href="#meshtastic.tests.test_main.test_main_ch_enable_without_a_ch_index">test_main_ch_enable_without_a_ch_index</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_index_no_devices" href="#meshtastic.tests.test_main.test_main_ch_index_no_devices">test_main_ch_index_no_devices</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_longsfast_on_non_primary_channel" href="#meshtastic.tests.test_main.test_main_ch_longsfast_on_non_primary_channel">test_main_ch_longsfast_on_non_primary_channel</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_ch_range_options" href="#meshtastic.tests.test_main.test_main_ch_range_options">test_main_ch_range_options</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_configure" href="#meshtastic.tests.test_main.test_main_configure">test_main_configure</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_get_with_invalid" href="#meshtastic.tests.test_main.test_main_get_with_invalid">test_main_get_with_invalid</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_get_with_valid_values" href="#meshtastic.tests.test_main.test_main_get_with_valid_values">test_main_get_with_valid_values</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_info" href="#meshtastic.tests.test_main.test_main_info">test_main_info</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_info_with_ble_interface" href="#meshtastic.tests.test_main.test_main_info_with_ble_interface">test_main_info_with_ble_interface</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_info_with_seriallog_output_txt" href="#meshtastic.tests.test_main.test_main_info_with_seriallog_output_txt">test_main_info_with_seriallog_output_txt</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_info_with_seriallog_stdout" href="#meshtastic.tests.test_main.test_main_info_with_seriallog_stdout">test_main_info_with_seriallog_stdout</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_info_with_tcp_interface" href="#meshtastic.tests.test_main.test_main_info_with_tcp_interface">test_main_info_with_tcp_interface</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_init_parser_no_args" href="#meshtastic.tests.test_main.test_main_init_parser_no_args">test_main_init_parser_no_args</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_init_parser_version" href="#meshtastic.tests.test_main.test_main_init_parser_version">test_main_init_parser_version</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_main_no_args" href="#meshtastic.tests.test_main.test_main_main_no_args">test_main_main_no_args</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_main_version" href="#meshtastic.tests.test_main.test_main_main_version">test_main_main_version</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_no_proto" href="#meshtastic.tests.test_main.test_main_no_proto">test_main_no_proto</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_nodes" href="#meshtastic.tests.test_main.test_main_nodes">test_main_nodes</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_onConnection" href="#meshtastic.tests.test_main.test_main_onConnection">test_main_onConnection</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_onReceive_empty" href="#meshtastic.tests.test_main.test_main_onReceive_empty">test_main_onReceive_empty</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_pos_fields_arg_of_zero" href="#meshtastic.tests.test_main.test_main_pos_fields_arg_of_zero">test_main_pos_fields_arg_of_zero</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_pos_fields_no_args" href="#meshtastic.tests.test_main.test_main_pos_fields_no_args">test_main_pos_fields_no_args</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_pos_fields_valid_values" href="#meshtastic.tests.test_main.test_main_pos_fields_valid_values">test_main_pos_fields_valid_values</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_qr" href="#meshtastic.tests.test_main.test_main_qr">test_main_qr</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_reboot" href="#meshtastic.tests.test_main.test_main_reboot">test_main_reboot</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_sendping" href="#meshtastic.tests.test_main.test_main_sendping">test_main_sendping</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_sendtext" href="#meshtastic.tests.test_main.test_main_sendtext">test_main_sendtext</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_sendtext_with_dest" href="#meshtastic.tests.test_main.test_main_sendtext_with_dest">test_main_sendtext_with_dest</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_set_ham_to_KI123" href="#meshtastic.tests.test_main.test_main_set_ham_to_KI123">test_main_set_ham_to_KI123</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_set_owner_to_bob" href="#meshtastic.tests.test_main.test_main_set_owner_to_bob">test_main_set_owner_to_bob</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_set_team_invalid" href="#meshtastic.tests.test_main.test_main_set_team_invalid">test_main_set_team_invalid</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_set_team_valid" href="#meshtastic.tests.test_main.test_main_set_team_valid">test_main_set_team_valid</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_set_valid" href="#meshtastic.tests.test_main.test_main_set_valid">test_main_set_valid</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_set_with_invalid" href="#meshtastic.tests.test_main.test_main_set_with_invalid">test_main_set_with_invalid</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_setalt" href="#meshtastic.tests.test_main.test_main_setalt">test_main_setalt</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_setchan" href="#meshtastic.tests.test_main.test_main_setchan">test_main_setchan</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_setlat" href="#meshtastic.tests.test_main.test_main_setlat">test_main_setlat</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_setlon" href="#meshtastic.tests.test_main.test_main_setlon">test_main_setlon</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_seturl" href="#meshtastic.tests.test_main.test_main_seturl">test_main_seturl</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_support" href="#meshtastic.tests.test_main.test_main_support">test_main_support</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_test_no_ports" href="#meshtastic.tests.test_main.test_main_test_no_ports">test_main_test_no_ports</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_test_one_port" href="#meshtastic.tests.test_main.test_main_test_one_port">test_main_test_one_port</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_test_two_ports_fails" href="#meshtastic.tests.test_main.test_main_test_two_ports_fails">test_main_test_two_ports_fails</a></code></li>
<li><code><a title="meshtastic.tests.test_main.test_main_test_two_ports_success" href="#meshtastic.tests.test_main.test_main_test_two_ports_success">test_main_test_two_ports_success</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="meshtastic.tests.test_main.Channel" href="#meshtastic.tests.test_main.Channel">Channel</a></code></h4>
<ul class="">
<li><code><a title="meshtastic.tests.test_main.Channel.ByteSize" href="#meshtastic.tests.test_main.Channel.ByteSize">ByteSize</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.Clear" href="#meshtastic.tests.test_main.Channel.Clear">Clear</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.ClearField" href="#meshtastic.tests.test_main.Channel.ClearField">ClearField</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.DESCRIPTOR" href="#meshtastic.tests.test_main.Channel.DESCRIPTOR">DESCRIPTOR</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.DISABLED" href="#meshtastic.tests.test_main.Channel.DISABLED">DISABLED</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.DiscardUnknownFields" href="#meshtastic.tests.test_main.Channel.DiscardUnknownFields">DiscardUnknownFields</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.FindInitializationErrors" href="#meshtastic.tests.test_main.Channel.FindInitializationErrors">FindInitializationErrors</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.FromString" href="#meshtastic.tests.test_main.Channel.FromString">FromString</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.HasField" href="#meshtastic.tests.test_main.Channel.HasField">HasField</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.INDEX_FIELD_NUMBER" href="#meshtastic.tests.test_main.Channel.INDEX_FIELD_NUMBER">INDEX_FIELD_NUMBER</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.IsInitialized" href="#meshtastic.tests.test_main.Channel.IsInitialized">IsInitialized</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.ListFields" href="#meshtastic.tests.test_main.Channel.ListFields">ListFields</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.MergeFrom" href="#meshtastic.tests.test_main.Channel.MergeFrom">MergeFrom</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.MergeFromString" href="#meshtastic.tests.test_main.Channel.MergeFromString">MergeFromString</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.PRIMARY" href="#meshtastic.tests.test_main.Channel.PRIMARY">PRIMARY</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.ROLE_FIELD_NUMBER" href="#meshtastic.tests.test_main.Channel.ROLE_FIELD_NUMBER">ROLE_FIELD_NUMBER</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.RegisterExtension" href="#meshtastic.tests.test_main.Channel.RegisterExtension">RegisterExtension</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.Role" href="#meshtastic.tests.test_main.Channel.Role">Role</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.SECONDARY" href="#meshtastic.tests.test_main.Channel.SECONDARY">SECONDARY</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.SETTINGS_FIELD_NUMBER" href="#meshtastic.tests.test_main.Channel.SETTINGS_FIELD_NUMBER">SETTINGS_FIELD_NUMBER</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.SerializePartialToString" href="#meshtastic.tests.test_main.Channel.SerializePartialToString">SerializePartialToString</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.SerializeToString" href="#meshtastic.tests.test_main.Channel.SerializeToString">SerializeToString</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.SetInParent" href="#meshtastic.tests.test_main.Channel.SetInParent">SetInParent</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.UnknownFields" href="#meshtastic.tests.test_main.Channel.UnknownFields">UnknownFields</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.WhichOneof" href="#meshtastic.tests.test_main.Channel.WhichOneof">WhichOneof</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.index" href="#meshtastic.tests.test_main.Channel.index">index</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.role" href="#meshtastic.tests.test_main.Channel.role">role</a></code></li>
<li><code><a title="meshtastic.tests.test_main.Channel.settings" href="#meshtastic.tests.test_main.Channel.settings">settings</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>