mirror of
https://github.com/meshtastic/python.git
synced 2025-12-30 03:17:54 -05:00
figured out how to unit test --set
This commit is contained in:
@@ -19,10 +19,10 @@ from . import remote_hardware
|
||||
from . import portnums_pb2, channel_pb2, radioconfig_pb2
|
||||
from .globals import Globals
|
||||
|
||||
|
||||
"""We only import the tunnel code if we are on a platform that can run it"""
|
||||
have_tunnel = platform.system() == 'Linux'
|
||||
|
||||
|
||||
def onReceive(packet, interface):
|
||||
"""Callback invoked when a packet arrives"""
|
||||
our_globals = Globals.getInstance()
|
||||
@@ -290,8 +290,7 @@ def onConnected(interface):
|
||||
|
||||
# Handle the int/float/bool arguments
|
||||
for pref in args.set:
|
||||
setPref(
|
||||
prefs, pref[0], pref[1])
|
||||
setPref(prefs, pref[0], pref[1])
|
||||
|
||||
print("Writing modified preferences to device")
|
||||
getNode().writeConfig()
|
||||
|
||||
@@ -11,6 +11,7 @@ from meshtastic.__main__ import initParser, main, Globals
|
||||
|
||||
from ..serial_interface import SerialInterface
|
||||
from ..node import Node
|
||||
from ..radioconfig_pb2 import RadioConfig
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -625,3 +626,35 @@ def test_main_seturl(capsys):
|
||||
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
mo.assert_called()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_main_set_valid(capsys):
|
||||
"""Test --set with valid field"""
|
||||
sys.argv = ['', '--set', 'wifi_ssid', 'foo']
|
||||
args = sys.argv
|
||||
parser = None
|
||||
parser = argparse.ArgumentParser()
|
||||
our_globals = Globals.getInstance()
|
||||
our_globals.set_parser(parser)
|
||||
our_globals.set_args(args)
|
||||
|
||||
mocked_user_prefs = MagicMock(autospec=RadioConfig.UserPreferences)
|
||||
mocked_user_prefs.phone_timeout_secs.return_value = 900
|
||||
mocked_user_prefs.ls_secs.return_value = 300
|
||||
|
||||
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()
|
||||
print('out:', out)
|
||||
print('err:', err)
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user