Compare commits

...

6 Commits

Author SHA1 Message Date
mkinney
4955ab8df2 Update setup.py 2022-01-16 12:48:35 -08:00
mkinney
de39c98e50 Merge pull request #236 from mkinney/fix_enum_listing
fix enum listing; add tests for pref values
2022-01-16 12:47:49 -08:00
Mike Kinney
51378bb0eb fix enum listing; add tests for pref values 2022-01-16 12:45:28 -08:00
mkinney
aff3bdd78e Update setup.py 2022-01-15 14:19:36 -08:00
mkinney
e9a8e26e76 Merge pull request #235 from mkinney/fix_for_setPref
looks like we needed some of that dead code after all
2022-01-15 14:19:07 -08:00
Mike Kinney
83439679c1 looks like we needed some of that dead code after all 2022-01-15 14:15:55 -08:00
5 changed files with 54 additions and 7 deletions

View File

@@ -14,3 +14,4 @@ user_prefs:
send_owner_interval: 2 send_owner_interval: 2
screen_on_secs: 31536000 screen_on_secs: 31536000
wait_bluetooth_secs: 31536000 wait_bluetooth_secs: 31536000
location_share: 'LocEnabled'

View File

@@ -117,6 +117,7 @@ def setPref(attributes, name, valStr):
return return
val = meshtastic.util.fromStr(valStr) val = meshtastic.util.fromStr(valStr)
logging.debug(f'valStr:{valStr} val:{val}')
enumType = field.enum_type enumType = field.enum_type
# pylint: disable=C0123 # pylint: disable=C0123
@@ -133,15 +134,16 @@ def setPref(attributes, name, valStr):
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:
tmp_name = f'{f.name}' # Note: We must use the value of the enum (regardless if camel or snake case)
if Globals.getInstance().get_camel_case(): names.append(f'{f.name}')
tmp_name = meshtastic.util.snake_to_camel(tmp_name)
names.append(name)
for temp_name in sorted(names): for temp_name in sorted(names):
print(f" {temp_name}") print(f" {temp_name}")
return return
try:
setattr(attributes, snake_name, val) setattr(attributes, snake_name, val)
except TypeError:
# The setter didn't like our arg type guess try again as a string
setattr(attributes, snake_name, valStr)
if Globals.getInstance().get_camel_case(): if Globals.getInstance().get_camel_case():
print(f"Set {camel_name} to {valStr}") print(f"Set {camel_name} to {valStr}")

View File

@@ -803,6 +803,27 @@ def test_main_set_valid(capsys):
mo.assert_called() mo.assert_called()
@pytest.mark.unit
@pytest.mark.usefixtures("reset_globals")
def test_main_set_valid_wifi_passwd(capsys):
"""Test --set with valid field"""
sys.argv = ['', '--set', 'wifi_password', '123456789']
Globals.getInstance().set_args(sys.argv)
mocked_node = MagicMock(autospec=Node)
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()
assert re.search(r'Connected to radio', out, re.MULTILINE)
assert re.search(r'Set wifi_password to 123456789', out, re.MULTILINE)
assert err == ''
mo.assert_called()
@pytest.mark.unit @pytest.mark.unit
@pytest.mark.usefixtures("reset_globals") @pytest.mark.usefixtures("reset_globals")
def test_main_set_valid_camel_case(capsys): def test_main_set_valid_camel_case(capsys):
@@ -872,6 +893,7 @@ def test_main_configure_with_snake_case(capsys):
assert re.search(r'Fixing altitude', out, re.MULTILINE) assert re.search(r'Fixing altitude', out, re.MULTILINE)
assert re.search(r'Fixing latitude', out, re.MULTILINE) assert re.search(r'Fixing latitude', out, re.MULTILINE)
assert re.search(r'Fixing longitude', out, re.MULTILINE) assert re.search(r'Fixing longitude', out, re.MULTILINE)
assert re.search(r'Set location_share to LocEnabled', out, re.MULTILINE)
assert re.search(r'Writing modified preferences', out, re.MULTILINE) assert re.search(r'Writing modified preferences', out, re.MULTILINE)
assert err == '' assert err == ''
mo.assert_called() mo.assert_called()
@@ -1942,6 +1964,27 @@ def test_main_setPref_valid_field_invalid_enum(capsys, caplog):
setPref(prefs, 'charge_current', 'foo') setPref(prefs, 'charge_current', 'foo')
out, err = capsys.readouterr() out, err = capsys.readouterr()
assert re.search(r'charge_current does not have an enum called foo', out, re.MULTILINE) assert re.search(r'charge_current does not have an enum called foo', out, re.MULTILINE)
assert re.search(r'Choices in sorted order are', out, re.MULTILINE)
assert re.search(r'MA100', out, re.MULTILINE)
assert re.search(r'MA280', out, re.MULTILINE)
assert err == ''
@pytest.mark.unit
@pytest.mark.usefixtures("reset_globals")
def test_main_setPref_valid_field_invalid_enum_where_enums_are_camel_cased_values(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, 'location_share', 'foo')
out, err = capsys.readouterr()
assert re.search(r'location_share does not have an enum called foo', out, re.MULTILINE)
assert re.search(r'Choices in sorted order are', out, re.MULTILINE)
assert re.search(r'LocDisabled', out, re.MULTILINE)
assert re.search(r'LocEnabled', out, re.MULTILINE)
assert err == '' assert err == ''

View File

@@ -40,6 +40,7 @@ def test_fromStr():
assert fromStr('100.01') == 100.01 assert fromStr('100.01') == 100.01
assert fromStr('123') == 123 assert fromStr('123') == 123
assert fromStr('abc') == 'abc' assert fromStr('abc') == 'abc'
assert fromStr('123456789') == 123456789
@pytest.mark.unitslow @pytest.mark.unitslow

View File

@@ -12,7 +12,7 @@ with open("README.md", "r") as fh:
# This call to setup() does all the work # This call to setup() does all the work
setup( setup(
name="meshtastic", name="meshtastic",
version="1.2.55", version="1.2.57",
description="Python API & client shell for talking to Meshtastic devices", description="Python API & client shell for talking to Meshtastic devices",
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",