mirror of
https://github.com/meshtastic/python.git
synced 2026-05-24 08:19:33 -04:00
add some coverage to getPref() and setPref()
This commit is contained in:
@@ -95,6 +95,8 @@ def setPref(attributes, name, valStr):
|
|||||||
|
|
||||||
snake_name = meshtastic.util.camel_to_snake(name)
|
snake_name = meshtastic.util.camel_to_snake(name)
|
||||||
camel_name = meshtastic.util.snake_to_camel(name)
|
camel_name = meshtastic.util.snake_to_camel(name)
|
||||||
|
logging.debug(f'snake_name:{snake_name}')
|
||||||
|
logging.debug(f'camel_name:{camel_name}')
|
||||||
|
|
||||||
objDesc = attributes.DESCRIPTOR
|
objDesc = attributes.DESCRIPTOR
|
||||||
field = objDesc.fields_by_name.get(snake_name)
|
field = objDesc.fields_by_name.get(snake_name)
|
||||||
@@ -125,9 +127,9 @@ def setPref(attributes, name, valStr):
|
|||||||
val = e.number
|
val = e.number
|
||||||
else:
|
else:
|
||||||
if Globals.getInstance().get_camel_case():
|
if Globals.getInstance().get_camel_case():
|
||||||
print(f"{snake_name} does not have an enum called {val}, so you can not set it.")
|
|
||||||
else:
|
|
||||||
print(f"{camel_name} does not have an enum called {val}, so you can not set it.")
|
print(f"{camel_name} does not have an enum called {val}, so you can not set it.")
|
||||||
|
else:
|
||||||
|
print(f"{snake_name} does not have an enum called {val}, so you can not set it.")
|
||||||
print(f"Choices in sorted order are:")
|
print(f"Choices in sorted order are:")
|
||||||
names = []
|
names = []
|
||||||
for f in enumType.values:
|
for f in enumType.values:
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from ..tcp_interface import TCPInterface
|
|||||||
from ..node import Node
|
from ..node import Node
|
||||||
from ..channel_pb2 import Channel
|
from ..channel_pb2 import Channel
|
||||||
from ..remote_hardware import onGPIOreceive
|
from ..remote_hardware import onGPIOreceive
|
||||||
|
from ..radioconfig_pb2 import RadioConfig
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.unit
|
@pytest.mark.unit
|
||||||
@@ -1908,6 +1909,74 @@ def test_main_setPref_valid_field_int_as_string(capsys):
|
|||||||
assert err == ''
|
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.unit
|
||||||
@pytest.mark.usefixtures("reset_globals")
|
@pytest.mark.usefixtures("reset_globals")
|
||||||
def test_main_setPref_invalid_field(capsys):
|
def test_main_setPref_invalid_field(capsys):
|
||||||
|
|||||||
Reference in New Issue
Block a user