Skip to content

Commit de39c98

Browse files
authored
Merge pull request #236 from mkinney/fix_enum_listing
fix enum listing; add tests for pref values
2 parents aff3bdd + 51378bb commit de39c98

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

example_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ user_prefs:
1414
send_owner_interval: 2
1515
screen_on_secs: 31536000
1616
wait_bluetooth_secs: 31536000
17+
location_share: 'LocEnabled'

meshtastic/__main__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ def setPref(attributes, name, valStr):
134134
print(f"Choices in sorted order are:")
135135
names = []
136136
for f in enumType.values:
137-
tmp_name = f'{f.name}'
138-
if Globals.getInstance().get_camel_case():
139-
tmp_name = meshtastic.util.snake_to_camel(tmp_name)
140-
names.append(name)
137+
# Note: We must use the value of the enum (regardless if camel or snake case)
138+
names.append(f'{f.name}')
141139
for temp_name in sorted(names):
142140
print(f" {temp_name}")
143141
return

meshtastic/tests/test_main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ def test_main_configure_with_snake_case(capsys):
893893
assert re.search(r'Fixing altitude', out, re.MULTILINE)
894894
assert re.search(r'Fixing latitude', out, re.MULTILINE)
895895
assert re.search(r'Fixing longitude', out, re.MULTILINE)
896+
assert re.search(r'Set location_share to LocEnabled', out, re.MULTILINE)
896897
assert re.search(r'Writing modified preferences', out, re.MULTILINE)
897898
assert err == ''
898899
mo.assert_called()
@@ -1963,6 +1964,27 @@ def test_main_setPref_valid_field_invalid_enum(capsys, caplog):
19631964
setPref(prefs, 'charge_current', 'foo')
19641965
out, err = capsys.readouterr()
19651966
assert re.search(r'charge_current does not have an enum called foo', out, re.MULTILINE)
1967+
assert re.search(r'Choices in sorted order are', out, re.MULTILINE)
1968+
assert re.search(r'MA100', out, re.MULTILINE)
1969+
assert re.search(r'MA280', out, re.MULTILINE)
1970+
assert err == ''
1971+
1972+
1973+
@pytest.mark.unit
1974+
@pytest.mark.usefixtures("reset_globals")
1975+
def test_main_setPref_valid_field_invalid_enum_where_enums_are_camel_cased_values(capsys, caplog):
1976+
"""Test setPref() with a valid field but invalid enum value"""
1977+
1978+
radioConfig = RadioConfig()
1979+
prefs = radioConfig.preferences
1980+
1981+
with caplog.at_level(logging.DEBUG):
1982+
setPref(prefs, 'location_share', 'foo')
1983+
out, err = capsys.readouterr()
1984+
assert re.search(r'location_share does not have an enum called foo', out, re.MULTILINE)
1985+
assert re.search(r'Choices in sorted order are', out, re.MULTILINE)
1986+
assert re.search(r'LocDisabled', out, re.MULTILINE)
1987+
assert re.search(r'LocEnabled', out, re.MULTILINE)
19661988
assert err == ''
19671989

19681990

0 commit comments

Comments
 (0)