Skip to content

Commit c3c5ce6

Browse files
committed
Copilot had a few suggestions on code review, implemented them.
1 parent 683dd23 commit c3c5ce6

File tree

1 file changed

+69
-8
lines changed

1 file changed

+69
-8
lines changed

meshtastic/tests/test_showNodes_favorite.py

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Meshtastic unit tests for showNodes favorite column feature"""
1+
"""Meshtastic unit tests for showNodes favorite column feature"""
22

33
from unittest.mock import MagicMock
44

@@ -37,6 +37,19 @@ def _iface_with_favorite_nodes():
3737
"lastHeard": 1640204999,
3838
"isFavorite": False,
3939
},
40+
"!abcdef00": {
41+
"num": 2882400000,
42+
"user": {
43+
"id": "!abcdef00",
44+
"longName": "Legacy Node",
45+
"shortName": "LEG1",
46+
"macaddr": "XYZABC00",
47+
"hwModel": "HELTEC_V3",
48+
},
49+
"position": {},
50+
"lastHeard": 1640205000,
51+
# Note: No isFavorite field - testing backward compatibility
52+
},
4053
}
4154

4255
nodesByNum = {
@@ -66,6 +79,19 @@ def _iface_with_favorite_nodes():
6679
"lastHeard": 1640206200,
6780
"isFavorite": False,
6881
},
82+
2882400000: {
83+
"num": 2882400000,
84+
"user": {
85+
"id": "!abcdef00",
86+
"longName": "Legacy Node",
87+
"shortName": "LEG1",
88+
"macaddr": "XYZABC00",
89+
"hwModel": "HELTEC_V3",
90+
},
91+
"position": {"time": 1640206100},
92+
"lastHeard": 1640206100,
93+
# Note: No isFavorite field - testing backward compatibility
94+
},
6995
}
7096

7197
iface = MeshInterface(noProto=True)
@@ -97,22 +123,33 @@ def test_showNodes_favorite_asterisk_display(capsys, _iface_with_favorite_nodes)
97123
# Check that the output contains the "Fav" column
98124
assert "Fav" in out
99125

100-
# The favorite node should have an asterisk in the output
101-
# We can't easily check the exact table cell, but we can verify
102-
# the asterisk appears somewhere in the output
103-
lines = out.split('\n')
104-
105126
# Find lines containing our nodes
127+
lines = out.split('\n')
106128
favorite_line = None
107129
regular_line = None
130+
legacy_line = None
108131
for line in lines:
109132
if "Favorite Node" in line or "FAV1" in line:
110133
favorite_line = line
111134
if "Regular Node" in line or "REG1" in line:
112135
regular_line = line
136+
if "Legacy Node" in line or "LEG1" in line:
137+
legacy_line = line
138+
139+
# Verify all nodes are present in the output
140+
assert favorite_line is not None, "Favorite node should be in output"
141+
assert regular_line is not None, "Regular node should be in output"
142+
assert legacy_line is not None, "Legacy node should be in output"
143+
144+
# Verify the favorite node has an asterisk in its row
145+
assert "*" in favorite_line, "Favorite node should have an asterisk"
146+
147+
# Verify the regular (non-favorite) node does NOT have an asterisk
148+
assert regular_line.count("*") == 0, "Non-favorite node should not have an asterisk"
149+
150+
# Verify the legacy node (without isFavorite field) does NOT have an asterisk
151+
assert legacy_line.count("*") == 0, "Legacy node without isFavorite field should not have an asterisk"
113152

114-
# Basic sanity check - if we found the lines, they should be present
115-
assert favorite_line is not None or regular_line is not None
116153
assert err == ""
117154

118155

@@ -158,3 +195,27 @@ def test_showNodes_default_fields_includes_favorite(_iface_with_favorite_nodes):
158195

159196
# The result should contain the formatted table as a string
160197
assert "Fav" in result
198+
199+
200+
@pytest.mark.unit
201+
def test_showNodes_backward_compatibility_missing_field(capsys, _iface_with_favorite_nodes):
202+
"""Test that nodes without isFavorite field are handled gracefully"""
203+
iface = _iface_with_favorite_nodes
204+
iface.showNodes()
205+
out, err = capsys.readouterr()
206+
207+
# Find the legacy node line
208+
lines = out.split('\n')
209+
legacy_line = None
210+
for line in lines:
211+
if "Legacy Node" in line or "LEG1" in line:
212+
legacy_line = line
213+
break
214+
215+
# Verify the legacy node appears in output
216+
assert legacy_line is not None, "Legacy node without isFavorite field should appear in output"
217+
218+
# Verify it doesn't have an asterisk (should be treated as non-favorite)
219+
assert legacy_line.count("*") == 0, "Legacy node should not have asterisk (treated as non-favorite)"
220+
221+
assert err == ""

0 commit comments

Comments
 (0)