mirror of
https://github.com/meshtastic/python.git
synced 2025-12-28 18:37:52 -05:00
3606 lines
159 KiB
HTML
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">"""Meshtastic unit tests for __main__.py"""
|
|
|
|
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):
|
|
"""Test no arguments"""
|
|
sys.argv = ['']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
initParser()
|
|
out, err = capsys.readouterr()
|
|
assert out == ''
|
|
assert err == ''
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_init_parser_version(capsys, reset_globals):
|
|
"""Test --version"""
|
|
sys.argv = ['', '--version']
|
|
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'[0-9]+\.[0-9]+\.[0-9]', out)
|
|
assert err == ''
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_main_version(capsys, reset_globals):
|
|
"""Test --version"""
|
|
sys.argv = ['', '--version']
|
|
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'[0-9]+\.[0-9]+\.[0-9]', out)
|
|
assert err == ''
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_main_no_args(reset_globals):
|
|
"""Test with no args"""
|
|
sys.argv = ['']
|
|
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):
|
|
"""Test --support"""
|
|
sys.argv = ['', '--support']
|
|
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'System', out, re.MULTILINE)
|
|
assert re.search(r'Platform', out, re.MULTILINE)
|
|
assert re.search(r'Machine', out, re.MULTILINE)
|
|
assert re.search(r'Executable', out, re.MULTILINE)
|
|
assert err == ''
|
|
|
|
|
|
@pytest.mark.unit
|
|
@patch('meshtastic.util.findPorts', return_value=[])
|
|
def test_main_ch_index_no_devices(patched_find_ports, capsys, reset_globals):
|
|
"""Test --ch-index 1"""
|
|
sys.argv = ['', '--ch-index', '1']
|
|
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'Warning: No Meshtastic devices detected', out, re.MULTILINE)
|
|
assert err == ''
|
|
patched_find_ports.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
@patch('meshtastic.util.findPorts', return_value=[])
|
|
def test_main_test_no_ports(patched_find_ports, reset_globals):
|
|
"""Test --test with no hardware"""
|
|
sys.argv = ['', '--test']
|
|
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('meshtastic.util.findPorts', return_value=['/dev/ttyFake1'])
|
|
def test_main_test_one_port(patched_find_ports, reset_globals):
|
|
"""Test --test with one fake port"""
|
|
sys.argv = ['', '--test']
|
|
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('meshtastic.test.testAll', return_value=True)
|
|
@patch('meshtastic.util.findPorts', return_value=['/dev/ttyFake1', '/dev/ttyFake2'])
|
|
def test_main_test_two_ports_success(patched_find_ports, patched_test_all, reset_globals):
|
|
"""Test --test two fake ports and testAll() is a simulated success"""
|
|
sys.argv = ['', '--test']
|
|
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('meshtastic.test.testAll', return_value=False)
|
|
@patch('meshtastic.util.findPorts', return_value=['/dev/ttyFake1', '/dev/ttyFake2'])
|
|
def test_main_test_two_ports_fails(patched_find_ports, patched_test_all, reset_globals):
|
|
"""Test --test two fake ports and testAll() is a simulated failure"""
|
|
sys.argv = ['', '--test']
|
|
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):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_info_with_tcp_interface(capsys, reset_globals):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info', '--host', 'meshtastic.local']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=TCPInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.tcp_interface.TCPInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_info_with_ble_interface(capsys, reset_globals):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info', '--ble', 'foo']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=BLEInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.ble_interface.BLEInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_no_proto(capsys, reset_globals):
|
|
"""Test --noproto (using --info for output)"""
|
|
sys.argv = ['', '--info', '--noproto']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
|
|
# Override the time.sleep so there is no loop
|
|
def my_sleep(amount):
|
|
sys.exit(0)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface):
|
|
with patch('time.sleep', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_info_with_seriallog_stdout(capsys, reset_globals):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info', '--seriallog', 'stdout']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_info_with_seriallog_output_txt(capsys, reset_globals):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info', '--seriallog', 'output.txt']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
# do some cleanup
|
|
os.remove('output.txt')
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_qr(capsys, reset_globals):
|
|
"""Test --qr"""
|
|
sys.argv = ['', '--qr']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
# TODO: could mock/check url
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Primary channel URL', out, re.MULTILINE)
|
|
# if a qr code is generated it will have lots of these
|
|
assert re.search(r'\[7m', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_nodes(capsys, reset_globals):
|
|
"""Test --nodes"""
|
|
sys.argv = ['', '--nodes']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showNodes():
|
|
print('inside mocked showNodes')
|
|
iface.showNodes.side_effect = mock_showNodes
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showNodes', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_set_owner_to_bob(capsys, reset_globals):
|
|
"""Test --set-owner bob"""
|
|
sys.argv = ['', '--set-owner', 'bob']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting device owner to bob', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_set_ham_to_KI123(capsys, reset_globals):
|
|
"""Test --set-ham KI123"""
|
|
sys.argv = ['', '--set-ham', 'KI123']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_turnOffEncryptionOnPrimaryChannel():
|
|
print('inside mocked turnOffEncryptionOnPrimaryChannel')
|
|
def mock_setOwner(name, is_licensed):
|
|
print('inside mocked setOwner')
|
|
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('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting HAM ID to KI123', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked setOwner', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked turnOffEncryptionOnPrimaryChannel', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_reboot(capsys, reset_globals):
|
|
"""Test --reboot"""
|
|
sys.argv = ['', '--reboot']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_reboot():
|
|
print('inside mocked reboot')
|
|
mocked_node.reboot.side_effect = mock_reboot
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked reboot', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_sendtext(capsys, reset_globals):
|
|
"""Test --sendtext"""
|
|
sys.argv = ['', '--sendtext', 'hello']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendText(text, dest, wantAck):
|
|
print('inside mocked sendText')
|
|
iface.sendText.side_effect = mock_sendText
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Sending text message', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendText', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_sendtext_with_dest(capsys, reset_globals):
|
|
"""Test --sendtext with --dest"""
|
|
sys.argv = ['', '--sendtext', 'hello', '--dest', 'foo']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendText(text, dest, wantAck):
|
|
print('inside mocked sendText')
|
|
iface.sendText.side_effect = mock_sendText
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Sending text message', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendText', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_sendping(capsys, reset_globals):
|
|
"""Test --sendping"""
|
|
sys.argv = ['', '--sendping']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendData(payload, dest, portNum, wantAck, wantResponse):
|
|
print('inside mocked sendData')
|
|
iface.sendData.side_effect = mock_sendData
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Sending ping message', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendData', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_setlat(capsys, reset_globals):
|
|
"""Test --sendlat"""
|
|
sys.argv = ['', '--setlat', '37.5']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_writeConfig():
|
|
print('inside mocked writeConfig')
|
|
mocked_node.writeConfig.side_effect = mock_writeConfig
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendPosition(lat, lon, alt):
|
|
print('inside mocked sendPosition')
|
|
iface.sendPosition.side_effect = mock_sendPosition
|
|
iface.localNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Fixing latitude', out, re.MULTILINE)
|
|
assert re.search(r'Setting device position', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendPosition', out, re.MULTILINE)
|
|
# TODO: Why does this not work? assert re.search(r'inside mocked writeConfig', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_setlon(capsys, reset_globals):
|
|
"""Test --setlon"""
|
|
sys.argv = ['', '--setlon', '-122.1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_writeConfig():
|
|
print('inside mocked writeConfig')
|
|
mocked_node.writeConfig.side_effect = mock_writeConfig
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendPosition(lat, lon, alt):
|
|
print('inside mocked sendPosition')
|
|
iface.sendPosition.side_effect = mock_sendPosition
|
|
iface.localNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Fixing longitude', out, re.MULTILINE)
|
|
assert re.search(r'Setting device position', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendPosition', out, re.MULTILINE)
|
|
# TODO: Why does this not work? assert re.search(r'inside mocked writeConfig', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_setalt(capsys, reset_globals):
|
|
"""Test --setalt"""
|
|
sys.argv = ['', '--setalt', '51']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_writeConfig():
|
|
print('inside mocked writeConfig')
|
|
mocked_node.writeConfig.side_effect = mock_writeConfig
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendPosition(lat, lon, alt):
|
|
print('inside mocked sendPosition')
|
|
iface.sendPosition.side_effect = mock_sendPosition
|
|
iface.localNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Fixing altitude', out, re.MULTILINE)
|
|
assert re.search(r'Setting device position', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendPosition', out, re.MULTILINE)
|
|
# TODO: Why does this not work? assert re.search(r'inside mocked writeConfig', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_set_team_valid(capsys, reset_globals):
|
|
"""Test --set-team"""
|
|
sys.argv = ['', '--set-team', 'CYAN']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_setOwner(team):
|
|
print('inside mocked setOwner')
|
|
mocked_node.setOwner.side_effect = mock_setOwner
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.localNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
with patch('meshtastic.mesh_pb2.Team') as mm:
|
|
mm.Name.return_value = 'FAKENAME'
|
|
mm.Value.return_value = 'FAKEVAL'
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting team to', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
mm.Name.assert_called()
|
|
mm.Value.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_set_team_invalid(capsys, reset_globals):
|
|
"""Test --set-team using an invalid team name"""
|
|
sys.argv = ['', '--set-team', 'NOTCYAN']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
|
|
def throw_an_exception(exc):
|
|
raise ValueError("Fake exception.")
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
with patch('meshtastic.mesh_pb2.Team') as mm:
|
|
mm.Value.side_effect = throw_an_exception
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'ERROR: Team', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
mm.Value.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_seturl(capsys, reset_globals):
|
|
"""Test --seturl (url used below is what is generated after a factory_reset)"""
|
|
sys.argv = ['', '--seturl', 'https://www.meshtastic.org/d/#CgUYAyIBAQ']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_set_valid(capsys, reset_globals):
|
|
"""Test --set with valid field"""
|
|
sys.argv = ['', '--set', 'wifi_ssid', 'foo']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Set wifi_ssid to foo', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_set_with_invalid(capsys, reset_globals):
|
|
"""Test --set with invalid field"""
|
|
sys.argv = ['', '--set', 'foo', 'foo']
|
|
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('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'does not have an attribute called foo', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
# TODO: write some negative --configure tests
|
|
@pytest.mark.unit
|
|
def test_main_configure(capsys, reset_globals):
|
|
"""Test --configure with valid file"""
|
|
sys.argv = ['', '--configure', 'example_config.yaml']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting device owner', out, re.MULTILINE)
|
|
assert re.search(r'Setting channel url', out, re.MULTILINE)
|
|
assert re.search(r'Fixing altitude', out, re.MULTILINE)
|
|
assert re.search(r'Fixing latitude', out, re.MULTILINE)
|
|
assert re.search(r'Fixing longitude', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified preferences', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_add_valid(capsys, reset_globals):
|
|
"""Test --ch-add with valid channel name, and that channel name does not already exist"""
|
|
sys.argv = ['', '--ch-add', 'testing']
|
|
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('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified channels to device', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_add_invalid_name_too_long(capsys, reset_globals):
|
|
"""Test --ch-add with invalid channel name, name too long"""
|
|
sys.argv = ['', '--ch-add', 'testingtestingtesting']
|
|
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('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Channel name must be shorter', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_add_but_name_already_exists(capsys, reset_globals):
|
|
"""Test --ch-add with a channel name that already exists"""
|
|
sys.argv = ['', '--ch-add', 'testing']
|
|
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('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: This node already has', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_add_but_no_more_channels(capsys, reset_globals):
|
|
"""Test --ch-add with but there are no more channels"""
|
|
sys.argv = ['', '--ch-add', 'testing']
|
|
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('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: No free channels were found', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_del(capsys, reset_globals):
|
|
"""Test --ch-del with valid secondary channel to be deleted"""
|
|
sys.argv = ['', '--ch-del', '--ch-index', '1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Deleting channel', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_del_no_ch_index_specified(capsys, reset_globals):
|
|
"""Test --ch-del without a valid ch-index"""
|
|
sys.argv = ['', '--ch-del']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Need to specify', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_del_primary_channel(capsys, reset_globals):
|
|
"""Test --ch-del on ch-index=0"""
|
|
sys.argv = ['', '--ch-del', '--ch-index', '0']
|
|
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('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Cannot delete primary channel', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_enable_valid_secondary_channel(capsys, reset_globals):
|
|
"""Test --ch-enable with --ch-index"""
|
|
sys.argv = ['', '--ch-enable', '--ch-index', '1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified channels', out, re.MULTILINE)
|
|
assert err == ''
|
|
assert Globals.getInstance().get_channel_index() == 1
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_disable_valid_secondary_channel(capsys, reset_globals):
|
|
"""Test --ch-disable with --ch-index"""
|
|
sys.argv = ['', '--ch-disable', '--ch-index', '1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified channels', out, re.MULTILINE)
|
|
assert err == ''
|
|
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):
|
|
"""Test --ch-enable without --ch-index"""
|
|
sys.argv = ['', '--ch-enable']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Need to specify', out, re.MULTILINE)
|
|
assert err == ''
|
|
assert Globals.getInstance().get_channel_index() is None
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_enable_primary_channel(capsys, reset_globals):
|
|
"""Test --ch-enable with --ch-index = 0"""
|
|
sys.argv = ['', '--ch-enable', '--ch-index', '0']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Cannot enable/disable PRIMARY', out, re.MULTILINE)
|
|
assert err == ''
|
|
assert Globals.getInstance().get_channel_index() == 0
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_range_options(capsys, reset_globals):
|
|
"""Test changing the various range options."""
|
|
range_options = ['--ch-longslow', '--ch-longfast', '--ch-mediumslow',
|
|
'--ch-mediumfast', '--ch-shortslow', '--ch-shortfast']
|
|
for range_option in range_options:
|
|
sys.argv = ['', f"{range_option}" ]
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified channels', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_ch_longsfast_on_non_primary_channel(capsys, reset_globals):
|
|
"""Test --ch-longfast --ch-index 1"""
|
|
sys.argv = ['', '--ch-longfast', '--ch-index', '1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Standard channel settings', out, re.MULTILINE)
|
|
assert err == ''
|
|
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):
|
|
"""Test --pos-fields no args (which shows settings)"""
|
|
sys.argv = ['', '--pos-fields']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface') as mo:
|
|
with patch('meshtastic.radioconfig_pb2.PositionFlags', 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 = [ 'POS_ALTITUDE', 'POS_ALT_MSL', 'POS_BATTERY' ]
|
|
|
|
main()
|
|
|
|
mrc.Name.assert_called()
|
|
mrc.values.assert_called()
|
|
mo.assert_called()
|
|
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'POS_ALTITUDE POS_ALT_MSL POS_BATTERY', out, re.MULTILINE)
|
|
assert err == ''
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_pos_fields_arg_of_zero(capsys, reset_globals):
|
|
"""Test --pos-fields an arg of 0 (which shows list)"""
|
|
sys.argv = ['', '--pos-fields', '0']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface') as mo:
|
|
with patch('meshtastic.radioconfig_pb2.PositionFlags', 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 = [ 'POS_UNDEFINED', 'POS_ALTITUDE', 'POS_ALT_MSL',
|
|
'POS_GEO_SEP', 'POS_DOP', 'POS_HVDOP', 'POS_BATTERY',
|
|
'POS_SATINVIEW', 'POS_SEQ_NOS', 'POS_TIMESTAMP']
|
|
|
|
main()
|
|
|
|
mrc.Value.assert_called()
|
|
mrc.keys.assert_called()
|
|
mo.assert_called()
|
|
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'ERROR: supported position fields are:', out, re.MULTILINE)
|
|
assert re.search(r"['POS_UNDEFINED', 'POS_ALTITUDE', 'POS_ALT_MSL', 'POS_GEO_SEP',"\
|
|
"'POS_DOP', 'POS_HVDOP', 'POS_BATTERY', 'POS_SATINVIEW', 'POS_SEQ_NOS',"\
|
|
"'POS_TIMESTAMP']", out, re.MULTILINE)
|
|
assert err == ''
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_pos_fields_valid_values(capsys, reset_globals):
|
|
"""Test --pos-fields with valid values"""
|
|
sys.argv = ['', '--pos-fields', 'POS_GEO_SEP', 'POS_ALT_MSL']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface') as mo:
|
|
with patch('meshtastic.radioconfig_pb2.PositionFlags', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting position fields to 6', out, re.MULTILINE)
|
|
assert re.search(r'Set position_flags to 6', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified preferences to device', out, re.MULTILINE)
|
|
assert err == ''
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_get_with_valid_values(capsys, reset_globals):
|
|
"""Test --get with valid values (with string, number, boolean)"""
|
|
sys.argv = ['', '--get', 'ls_secs', '--get', 'wifi_ssid', '--get', 'fixed_position']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface') 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 = 'foo'
|
|
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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'ls_secs: 300', out, re.MULTILINE)
|
|
assert re.search(r'wifi_ssid: foo', out, re.MULTILINE)
|
|
assert re.search(r'fixed_position: False', out, re.MULTILINE)
|
|
assert err == ''
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_get_with_invalid(capsys, reset_globals):
|
|
"""Test --get with invalid field"""
|
|
sys.argv = ['', '--get', 'foo']
|
|
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('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'does not have an attribute called foo', out, re.MULTILINE)
|
|
assert re.search(r'Choices in sorted order are', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_setchan(capsys, reset_globals):
|
|
"""Test --setchan (deprecated)"""
|
|
sys.argv = ['', '--setchan', 'a', 'b']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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):
|
|
"""Test onReceive"""
|
|
sys.argv = ['']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
packet = {'decoded': 'foo'}
|
|
onReceive(packet, iface)
|
|
# TODO: how do we know we actually called it?
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_main_onConnection(reset_globals, capsys):
|
|
"""Test onConnection"""
|
|
sys.argv = ['']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
class TempTopic:
|
|
""" temp class for topic """
|
|
def getName(self):
|
|
""" return the fake name of a topic"""
|
|
return 'foo'
|
|
mytopic = TempTopic()
|
|
onConnection(iface, mytopic)
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connection changed: foo', out, re.MULTILINE)
|
|
assert err == ''</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 –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):
|
|
"""Test --ch-add with a channel name that already exists"""
|
|
sys.argv = ['', '--ch-add', 'testing']
|
|
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('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: This node already has', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --ch-add with but there are no more channels"""
|
|
sys.argv = ['', '--ch-add', 'testing']
|
|
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('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: No free channels were found', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --ch-add with invalid channel name, name too long"""
|
|
sys.argv = ['', '--ch-add', 'testingtestingtesting']
|
|
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('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Channel name must be shorter', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --ch-add with valid channel name, and that channel name does not already exist"""
|
|
sys.argv = ['', '--ch-add', 'testing']
|
|
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('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified channels to device', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --ch-del with valid secondary channel to be deleted"""
|
|
sys.argv = ['', '--ch-del', '--ch-index', '1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Deleting channel', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --ch-del without a valid ch-index"""
|
|
sys.argv = ['', '--ch-del']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Need to specify', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --ch-del on ch-index=0"""
|
|
sys.argv = ['', '--ch-del', '--ch-index', '0']
|
|
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('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Cannot delete primary channel', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –ch-disable with –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):
|
|
"""Test --ch-disable with --ch-index"""
|
|
sys.argv = ['', '--ch-disable', '--ch-index', '1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified channels', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –ch-enable with –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):
|
|
"""Test --ch-enable with --ch-index = 0"""
|
|
sys.argv = ['', '--ch-enable', '--ch-index', '0']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Cannot enable/disable PRIMARY', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –ch-enable with –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):
|
|
"""Test --ch-enable with --ch-index"""
|
|
sys.argv = ['', '--ch-enable', '--ch-index', '1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified channels', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –ch-enable without –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):
|
|
"""Test --ch-enable without --ch-index"""
|
|
sys.argv = ['', '--ch-enable']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Need to specify', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –ch-index 1</p></div>
|
|
<details class="source">
|
|
<summary>
|
|
<span>Expand source code</span>
|
|
</summary>
|
|
<pre><code class="python">@pytest.mark.unit
|
|
@patch('meshtastic.util.findPorts', return_value=[])
|
|
def test_main_ch_index_no_devices(patched_find_ports, capsys, reset_globals):
|
|
"""Test --ch-index 1"""
|
|
sys.argv = ['', '--ch-index', '1']
|
|
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'Warning: No Meshtastic devices detected', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –ch-longfast –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):
|
|
"""Test --ch-longfast --ch-index 1"""
|
|
sys.argv = ['', '--ch-longfast', '--ch-index', '1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Warning: Standard channel settings', out, re.MULTILINE)
|
|
assert err == ''
|
|
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):
|
|
"""Test changing the various range options."""
|
|
range_options = ['--ch-longslow', '--ch-longfast', '--ch-mediumslow',
|
|
'--ch-mediumfast', '--ch-shortslow', '--ch-shortfast']
|
|
for range_option in range_options:
|
|
sys.argv = ['', f"{range_option}" ]
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified channels', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --configure with valid file"""
|
|
sys.argv = ['', '--configure', 'example_config.yaml']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting device owner', out, re.MULTILINE)
|
|
assert re.search(r'Setting channel url', out, re.MULTILINE)
|
|
assert re.search(r'Fixing altitude', out, re.MULTILINE)
|
|
assert re.search(r'Fixing latitude', out, re.MULTILINE)
|
|
assert re.search(r'Fixing longitude', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified preferences', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --get with invalid field"""
|
|
sys.argv = ['', '--get', 'foo']
|
|
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('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'does not have an attribute called foo', out, re.MULTILINE)
|
|
assert re.search(r'Choices in sorted order are', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --get with valid values (with string, number, boolean)"""
|
|
sys.argv = ['', '--get', 'ls_secs', '--get', 'wifi_ssid', '--get', 'fixed_position']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface') 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 = 'foo'
|
|
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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'ls_secs: 300', out, re.MULTILINE)
|
|
assert re.search(r'wifi_ssid: foo', out, re.MULTILINE)
|
|
assert re.search(r'fixed_position: False', out, re.MULTILINE)
|
|
assert err == ''</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 –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):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info', '--ble', 'foo']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=BLEInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.ble_interface.BLEInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info', '--seriallog', 'output.txt']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
mo.assert_called()
|
|
# do some cleanup
|
|
os.remove('output.txt')</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 –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):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info', '--seriallog', 'stdout']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --info"""
|
|
sys.argv = ['', '--info', '--host', 'meshtastic.local']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=TCPInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
with patch('meshtastic.tcp_interface.TCPInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''
|
|
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):
|
|
"""Test no arguments"""
|
|
sys.argv = ['']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
initParser()
|
|
out, err = capsys.readouterr()
|
|
assert out == ''
|
|
assert err == ''</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 –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):
|
|
"""Test --version"""
|
|
sys.argv = ['', '--version']
|
|
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'[0-9]+\.[0-9]+\.[0-9]', out)
|
|
assert err == ''</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):
|
|
"""Test with no args"""
|
|
sys.argv = ['']
|
|
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 –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):
|
|
"""Test --version"""
|
|
sys.argv = ['', '--version']
|
|
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'[0-9]+\.[0-9]+\.[0-9]', out)
|
|
assert err == ''</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 –noproto (using –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):
|
|
"""Test --noproto (using --info for output)"""
|
|
sys.argv = ['', '--info', '--noproto']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showInfo():
|
|
print('inside mocked showInfo')
|
|
iface.showInfo.side_effect = mock_showInfo
|
|
|
|
# Override the time.sleep so there is no loop
|
|
def my_sleep(amount):
|
|
sys.exit(0)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface):
|
|
with patch('time.sleep', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showInfo', out, re.MULTILINE)
|
|
assert err == ''</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 –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):
|
|
"""Test --nodes"""
|
|
sys.argv = ['', '--nodes']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_showNodes():
|
|
print('inside mocked showNodes')
|
|
iface.showNodes.side_effect = mock_showNodes
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked showNodes', out, re.MULTILINE)
|
|
assert err == ''
|
|
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):
|
|
"""Test onConnection"""
|
|
sys.argv = ['']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
class TempTopic:
|
|
""" temp class for topic """
|
|
def getName(self):
|
|
""" return the fake name of a topic"""
|
|
return 'foo'
|
|
mytopic = TempTopic()
|
|
onConnection(iface, mytopic)
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connection changed: foo', out, re.MULTILINE)
|
|
assert err == ''</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):
|
|
"""Test onReceive"""
|
|
sys.argv = ['']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
packet = {'decoded': 'foo'}
|
|
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 –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):
|
|
"""Test --pos-fields an arg of 0 (which shows list)"""
|
|
sys.argv = ['', '--pos-fields', '0']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface') as mo:
|
|
with patch('meshtastic.radioconfig_pb2.PositionFlags', 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 = [ 'POS_UNDEFINED', 'POS_ALTITUDE', 'POS_ALT_MSL',
|
|
'POS_GEO_SEP', 'POS_DOP', 'POS_HVDOP', 'POS_BATTERY',
|
|
'POS_SATINVIEW', 'POS_SEQ_NOS', 'POS_TIMESTAMP']
|
|
|
|
main()
|
|
|
|
mrc.Value.assert_called()
|
|
mrc.keys.assert_called()
|
|
mo.assert_called()
|
|
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'ERROR: supported position fields are:', out, re.MULTILINE)
|
|
assert re.search(r"['POS_UNDEFINED', 'POS_ALTITUDE', 'POS_ALT_MSL', 'POS_GEO_SEP',"\
|
|
"'POS_DOP', 'POS_HVDOP', 'POS_BATTERY', 'POS_SATINVIEW', 'POS_SEQ_NOS',"\
|
|
"'POS_TIMESTAMP']", out, re.MULTILINE)
|
|
assert err == ''</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 –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):
|
|
"""Test --pos-fields no args (which shows settings)"""
|
|
sys.argv = ['', '--pos-fields']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface') as mo:
|
|
with patch('meshtastic.radioconfig_pb2.PositionFlags', 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 = [ 'POS_ALTITUDE', 'POS_ALT_MSL', 'POS_BATTERY' ]
|
|
|
|
main()
|
|
|
|
mrc.Name.assert_called()
|
|
mrc.values.assert_called()
|
|
mo.assert_called()
|
|
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'POS_ALTITUDE POS_ALT_MSL POS_BATTERY', out, re.MULTILINE)
|
|
assert err == ''</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 –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):
|
|
"""Test --pos-fields with valid values"""
|
|
sys.argv = ['', '--pos-fields', 'POS_GEO_SEP', 'POS_ALT_MSL']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
pos_flags = MagicMock(autospec=meshtastic.radioconfig_pb2.PositionFlags)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface') as mo:
|
|
with patch('meshtastic.radioconfig_pb2.PositionFlags', 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'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting position fields to 6', out, re.MULTILINE)
|
|
assert re.search(r'Set position_flags to 6', out, re.MULTILINE)
|
|
assert re.search(r'Writing modified preferences to device', out, re.MULTILINE)
|
|
assert err == ''</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 –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):
|
|
"""Test --qr"""
|
|
sys.argv = ['', '--qr']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
# TODO: could mock/check url
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Primary channel URL', out, re.MULTILINE)
|
|
# if a qr code is generated it will have lots of these
|
|
assert re.search(r'\[7m', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --reboot"""
|
|
sys.argv = ['', '--reboot']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_reboot():
|
|
print('inside mocked reboot')
|
|
mocked_node.reboot.side_effect = mock_reboot
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked reboot', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --sendping"""
|
|
sys.argv = ['', '--sendping']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendData(payload, dest, portNum, wantAck, wantResponse):
|
|
print('inside mocked sendData')
|
|
iface.sendData.side_effect = mock_sendData
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Sending ping message', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendData', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --sendtext"""
|
|
sys.argv = ['', '--sendtext', 'hello']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendText(text, dest, wantAck):
|
|
print('inside mocked sendText')
|
|
iface.sendText.side_effect = mock_sendText
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Sending text message', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendText', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –sendtext with –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):
|
|
"""Test --sendtext with --dest"""
|
|
sys.argv = ['', '--sendtext', 'hello', '--dest', 'foo']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendText(text, dest, wantAck):
|
|
print('inside mocked sendText')
|
|
iface.sendText.side_effect = mock_sendText
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Sending text message', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendText', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --set-ham KI123"""
|
|
sys.argv = ['', '--set-ham', 'KI123']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_turnOffEncryptionOnPrimaryChannel():
|
|
print('inside mocked turnOffEncryptionOnPrimaryChannel')
|
|
def mock_setOwner(name, is_licensed):
|
|
print('inside mocked setOwner')
|
|
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('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting HAM ID to KI123', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked setOwner', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked turnOffEncryptionOnPrimaryChannel', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --set-owner bob"""
|
|
sys.argv = ['', '--set-owner', 'bob']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting device owner to bob', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --set-team using an invalid team name"""
|
|
sys.argv = ['', '--set-team', 'NOTCYAN']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
|
|
def throw_an_exception(exc):
|
|
raise ValueError("Fake exception.")
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
with patch('meshtastic.mesh_pb2.Team') as mm:
|
|
mm.Value.side_effect = throw_an_exception
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'ERROR: Team', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --set-team"""
|
|
sys.argv = ['', '--set-team', 'CYAN']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_setOwner(team):
|
|
print('inside mocked setOwner')
|
|
mocked_node.setOwner.side_effect = mock_setOwner
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.localNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
with patch('meshtastic.mesh_pb2.Team') as mm:
|
|
mm.Name.return_value = 'FAKENAME'
|
|
mm.Value.return_value = 'FAKEVAL'
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Setting team to', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --set with valid field"""
|
|
sys.argv = ['', '--set', 'wifi_ssid', 'foo']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
iface.getNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Set wifi_ssid to foo', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --set with invalid field"""
|
|
sys.argv = ['', '--set', 'foo', 'foo']
|
|
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('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'does not have an attribute called foo', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --setalt"""
|
|
sys.argv = ['', '--setalt', '51']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_writeConfig():
|
|
print('inside mocked writeConfig')
|
|
mocked_node.writeConfig.side_effect = mock_writeConfig
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendPosition(lat, lon, alt):
|
|
print('inside mocked sendPosition')
|
|
iface.sendPosition.side_effect = mock_sendPosition
|
|
iface.localNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Fixing altitude', out, re.MULTILINE)
|
|
assert re.search(r'Setting device position', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendPosition', out, re.MULTILINE)
|
|
# TODO: Why does this not work? assert re.search(r'inside mocked writeConfig', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --setchan (deprecated)"""
|
|
sys.argv = ['', '--setchan', 'a', 'b']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', 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 –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):
|
|
"""Test --sendlat"""
|
|
sys.argv = ['', '--setlat', '37.5']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_writeConfig():
|
|
print('inside mocked writeConfig')
|
|
mocked_node.writeConfig.side_effect = mock_writeConfig
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendPosition(lat, lon, alt):
|
|
print('inside mocked sendPosition')
|
|
iface.sendPosition.side_effect = mock_sendPosition
|
|
iface.localNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Fixing latitude', out, re.MULTILINE)
|
|
assert re.search(r'Setting device position', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendPosition', out, re.MULTILINE)
|
|
# TODO: Why does this not work? assert re.search(r'inside mocked writeConfig', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --setlon"""
|
|
sys.argv = ['', '--setlon', '-122.1']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
mocked_node = MagicMock(autospec=Node)
|
|
def mock_writeConfig():
|
|
print('inside mocked writeConfig')
|
|
mocked_node.writeConfig.side_effect = mock_writeConfig
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
def mock_sendPosition(lat, lon, alt):
|
|
print('inside mocked sendPosition')
|
|
iface.sendPosition.side_effect = mock_sendPosition
|
|
iface.localNode.return_value = mocked_node
|
|
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert re.search(r'Fixing longitude', out, re.MULTILINE)
|
|
assert re.search(r'Setting device position', out, re.MULTILINE)
|
|
assert re.search(r'inside mocked sendPosition', out, re.MULTILINE)
|
|
# TODO: Why does this not work? assert re.search(r'inside mocked writeConfig', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --seturl (url used below is what is generated after a factory_reset)"""
|
|
sys.argv = ['', '--seturl', 'https://www.meshtastic.org/d/#CgUYAyIBAQ']
|
|
Globals.getInstance().set_args(sys.argv)
|
|
|
|
iface = MagicMock(autospec=SerialInterface)
|
|
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
|
main()
|
|
out, err = capsys.readouterr()
|
|
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
|
assert err == ''
|
|
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 –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):
|
|
"""Test --support"""
|
|
sys.argv = ['', '--support']
|
|
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'System', out, re.MULTILINE)
|
|
assert re.search(r'Platform', out, re.MULTILINE)
|
|
assert re.search(r'Machine', out, re.MULTILINE)
|
|
assert re.search(r'Executable', out, re.MULTILINE)
|
|
assert err == ''</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 –test with no hardware</p></div>
|
|
<details class="source">
|
|
<summary>
|
|
<span>Expand source code</span>
|
|
</summary>
|
|
<pre><code class="python">@pytest.mark.unit
|
|
@patch('meshtastic.util.findPorts', return_value=[])
|
|
def test_main_test_no_ports(patched_find_ports, reset_globals):
|
|
"""Test --test with no hardware"""
|
|
sys.argv = ['', '--test']
|
|
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 –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('meshtastic.util.findPorts', return_value=['/dev/ttyFake1'])
|
|
def test_main_test_one_port(patched_find_ports, reset_globals):
|
|
"""Test --test with one fake port"""
|
|
sys.argv = ['', '--test']
|
|
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 –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('meshtastic.test.testAll', return_value=False)
|
|
@patch('meshtastic.util.findPorts', return_value=['/dev/ttyFake1', '/dev/ttyFake2'])
|
|
def test_main_test_two_ports_fails(patched_find_ports, patched_test_all, reset_globals):
|
|
"""Test --test two fake ports and testAll() is a simulated failure"""
|
|
sys.argv = ['', '--test']
|
|
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 –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('meshtastic.test.testAll', return_value=True)
|
|
@patch('meshtastic.util.findPorts', return_value=['/dev/ttyFake1', '/dev/ttyFake2'])
|
|
def test_main_test_two_ports_success(patched_find_ports, patched_test_all, reset_globals):
|
|
"""Test --test two fake ports and testAll() is a simulated success"""
|
|
sys.argv = ['', '--test']
|
|
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'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['key']._sizer(self.key)
|
|
size += descriptor.fields_by_name['value']._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('Protocol message %s has no "%s" field.' %
|
|
(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], 'InvalidateIterators'):
|
|
self._fields[field].InvalidateIterators()
|
|
|
|
# Note: If the field is a sub-message, its listener will still point
|
|
# at us. That'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):
|
|
"""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. "foo.bar[5].baz".
|
|
"""
|
|
|
|
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 = '(%s)' % field.full_name
|
|
else:
|
|
name = field.name
|
|
|
|
if _IsMapField(field):
|
|
if _IsMessageMapField(field):
|
|
for key in value:
|
|
element = value[key]
|
|
prefix = '%s[%s].' % (name, key)
|
|
sub_errors = element.FindInitializationErrors()
|
|
errors += [prefix + error for error in sub_errors]
|
|
else:
|
|
# ScalarMaps can't have any initialization errors.
|
|
pass
|
|
elif field.label == _FieldDescriptor.LABEL_REPEATED:
|
|
for i in range(len(value)):
|
|
element = value[i]
|
|
prefix = '%s[%d].' % (name, i)
|
|
sub_errors = element.FindInitializationErrors()
|
|
errors += [prefix + error for error in sub_errors]
|
|
else:
|
|
prefix = name + '.'
|
|
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):
|
|
"""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.
|
|
"""
|
|
|
|
# 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(
|
|
'Parameter to MergeFrom() must be instance of same class: '
|
|
'expected %s got %s.' % (_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('Unexpected end-group tag.')
|
|
except (IndexError, TypeError):
|
|
# Now ord(buf[p:p+1]) == ord('') gets TypeError.
|
|
raise message_mod.DecodeError('Truncated message.')
|
|
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(
|
|
'Message %s is missing required fields: %s' % (
|
|
self.DESCRIPTOR.full_name, ','.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):
|
|
"""Sets the _cached_byte_size_dirty bit to true,
|
|
and propagates this to our listener iff this was a state change.
|
|
"""
|
|
|
|
# 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):
|
|
"""Returns the name of the currently set field inside a oneof, or None."""
|
|
try:
|
|
field = message_descriptor.oneofs_by_name[oneof_name]
|
|
except KeyError:
|
|
raise ValueError(
|
|
'Protocol message has no oneof "%s" field.' % 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> |