add some coverage to getPref() and setPref()

This commit is contained in:
Mike Kinney
2022-01-15 00:01:44 -08:00
parent e85af2f9e9
commit 7921db007b
2 changed files with 73 additions and 2 deletions

View File

@@ -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):