mirror of
https://github.com/meshtastic/python.git
synced 2026-04-17 21:42:20 -04:00
add some coverage to getPref() and setPref()
This commit is contained in:
@@ -19,6 +19,7 @@ from ..tcp_interface import TCPInterface
|
||||
from ..node import Node
|
||||
from ..channel_pb2 import Channel
|
||||
from ..remote_hardware import onGPIOreceive
|
||||
from ..radioconfig_pb2 import RadioConfig
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -1908,6 +1909,74 @@ def test_main_setPref_valid_field_int_as_string(capsys):
|
||||
assert err == ''
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.usefixtures("reset_globals")
|
||||
def test_main_setPref_valid_field_invalid_enum(capsys, caplog):
|
||||
"""Test setPref() with a valid field but invalid enum value"""
|
||||
|
||||
radioConfig = RadioConfig()
|
||||
prefs = radioConfig.preferences
|
||||
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
setPref(prefs, 'charge_current', 'foo')
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r'charge_current does not have an enum called foo', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.usefixtures("reset_globals")
|
||||
def test_main_setPref_valid_field_invalid_enum_camel(capsys, caplog):
|
||||
"""Test setPref() with a valid field but invalid enum value"""
|
||||
Globals.getInstance().set_camel_case()
|
||||
|
||||
radioConfig = RadioConfig()
|
||||
prefs = radioConfig.preferences
|
||||
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
setPref(prefs, 'charge_current', 'foo')
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r'chargeCurrent does not have an enum called foo', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.usefixtures("reset_globals")
|
||||
def test_main_setPref_valid_field_valid_enum(capsys, caplog):
|
||||
"""Test setPref() with a valid field and valid enum value"""
|
||||
|
||||
# charge_current
|
||||
# some valid values: MA100 MA1000 MA1080
|
||||
|
||||
radioConfig = RadioConfig()
|
||||
prefs = radioConfig.preferences
|
||||
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
setPref(prefs, 'charge_current', 'MA100')
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r'Set charge_current to MA100', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.usefixtures("reset_globals")
|
||||
def test_main_setPref_valid_field_valid_enum_camel(capsys, caplog):
|
||||
"""Test setPref() with a valid field and valid enum value"""
|
||||
Globals.getInstance().set_camel_case()
|
||||
|
||||
# charge_current
|
||||
# some valid values: MA100 MA1000 MA1080
|
||||
|
||||
radioConfig = RadioConfig()
|
||||
prefs = radioConfig.preferences
|
||||
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
setPref(prefs, 'charge_current', 'MA100')
|
||||
out, err = capsys.readouterr()
|
||||
assert re.search(r'Set chargeCurrent to MA100', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.usefixtures("reset_globals")
|
||||
def test_main_setPref_invalid_field(capsys):
|
||||
|
||||
Reference in New Issue
Block a user