mirror of
https://github.com/meshtastic/python.git
synced 2025-12-30 03:17:54 -05:00
add some tests for getPref()
This commit is contained in:
@@ -9,7 +9,8 @@ import logging
|
||||
from unittest.mock import patch, MagicMock
|
||||
import pytest
|
||||
|
||||
from meshtastic.__main__ import initParser, main, Globals, onReceive, onConnection, export_config
|
||||
from meshtastic.__main__ import initParser, main, Globals, onReceive, onConnection, export_config, getPref
|
||||
#from ..radioconfig_pb2 import UserPreferences
|
||||
import meshtastic.radioconfig_pb2
|
||||
from ..serial_interface import SerialInterface
|
||||
from ..tcp_interface import TCPInterface
|
||||
@@ -1504,3 +1505,49 @@ def test_main_gpio_rd(caplog, capsys, reset_globals):
|
||||
assert re.search(r'Reading GPIO mask 0x1000 ', out, re.MULTILINE)
|
||||
assert re.search(r'Received RemoteHardware typ=READ_GPIOS_REPLY, gpio_value=4096', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_main_getPref_valid_field(capsys, reset_globals):
|
||||
"""Test getPref() with a valid field"""
|
||||
prefs = MagicMock()
|
||||
prefs.DESCRIPTOR.fields_by_name.get.return_value = 'ls_secs'
|
||||
prefs.wifi_ssid = 'foo'
|
||||
prefs.ls_secs = 300
|
||||
prefs.fixed_position = False
|
||||
|
||||
getPref(prefs, 'ls_secs')
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r'ls_secs: 300', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_main_getPref_invalid_field(capsys, reset_globals):
|
||||
"""Test getPref() with an invalid field"""
|
||||
|
||||
class Field:
|
||||
"""Simple class for testing."""
|
||||
|
||||
def __init__(self, name):
|
||||
"""constructor"""
|
||||
self.name = name
|
||||
|
||||
prefs = MagicMock()
|
||||
prefs.DESCRIPTOR.fields_by_name.get.return_value = None
|
||||
|
||||
# Note: This is a subset of the real fields
|
||||
ls_secs_field = Field('ls_secs')
|
||||
is_router = Field('is_router')
|
||||
fixed_position = Field('fixed_position')
|
||||
|
||||
fields = [ ls_secs_field, is_router, fixed_position ]
|
||||
prefs.DESCRIPTOR.fields = fields
|
||||
|
||||
getPref(prefs, 'foo')
|
||||
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r'does not have an attribute called foo', out, re.MULTILINE)
|
||||
# ensure they are sorted
|
||||
assert re.search(r'fixed_position\s+is_router\s+ls_secs', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
|
||||
Reference in New Issue
Block a user