Skip to content

Commit 514ce6f

Browse files
Fix tests/test_graphical_notification_bar.py
1 parent 368462f commit 514ce6f

3 files changed

Lines changed: 62 additions & 39 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Builtin Apps:
1010
- Settings: new Audio subsection to choose default output and input device, for boards with multiple audio devices
1111

1212
Frameworks:
13+
- Activity: add appFullName property
1314
- AudioManager: load and apply configured default_output and default_input devices
1415
- AudioManager: fix final 1-2 seconds of WAV files not being played
1516
- AudioManager: add support for PDM microphones

internal_filesystem/lib/mpos/ui/testing.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,21 @@ def wait_for_render(iterations=10):
300300
assert verify_text_present(lv.screen_active(), "Welcome")
301301
"""
302302
import time
303+
task_handler_running = False
304+
try:
305+
import mpos
306+
307+
task_handler = getattr(getattr(mpos, "ui", None), "task_handler", None)
308+
if task_handler is not None:
309+
task_handler_running = task_handler.is_running()
310+
except Exception:
311+
task_handler_running = False
312+
313+
if task_handler_running:
314+
for _ in range(iterations):
315+
time.sleep(0.01)
316+
return
317+
303318
for _ in range(iterations):
304319
lv.task_handler()
305320
time.sleep(0.01) # Small delay between iterations

tests/test_graphical_notification_bar.py

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,34 @@ class TestNotificationBarVisibility(unittest.TestCase):
2525
def setUp(self):
2626
AppManager.start_app("com.micropythonos.launcher")
2727
topmenu.open_bar()
28+
wait_for_render(iterations=40)
2829
self._wait_for_bar_visible()
2930

30-
def _wait_for_bar_visible(self, timeout_ms=2500):
31+
def _wait_for_bar_visible(self, timeout_ms=4000):
3132
start = time.ticks_ms()
3233
while time.ticks_diff(time.ticks_ms(), start) < timeout_ms:
3334
bar = topmenu.notification_bar
3435
if bar is not None:
3536
bar_coords = get_widget_coords(bar)
3637
if bar_coords and bar_coords["y1"] >= -1:
37-
return
38+
return True
3839
wait_for_render(iterations=10)
3940
bar = topmenu.notification_bar
4041
if bar is not None:
4142
bar.set_y(0)
4243
wait_for_render(iterations=60)
44+
bar_coords = get_widget_coords(bar)
45+
return bool(bar_coords and bar_coords["y1"] >= -1)
46+
47+
def _wait_for_bar_height(self, bar, timeout_ms=4000):
48+
start = time.ticks_ms()
49+
expected_height = AppearanceManager.NOTIFICATION_BAR_HEIGHT - 1
50+
while time.ticks_diff(time.ticks_ms(), start) < timeout_ms:
51+
coords = get_widget_coords(bar)
52+
if coords and coords["height"] >= expected_height:
53+
return True
54+
wait_for_render(iterations=10)
55+
return False
4356

4457
def _get_bar_labels(self, bar):
4558
labels = []
@@ -63,20 +76,26 @@ def _get_bar_labels(self, bar):
6376
continue
6477
return labels
6578

66-
def _assert_within_bar(self, widget, bar_coords, label, margin=8):
67-
coords = get_widget_coords(widget)
68-
self.assertIsNotNone(coords, f"{label} coords not available")
69-
center_y = coords["center_y"]
70-
self.assertGreaterEqual(
71-
center_y,
72-
bar_coords["y1"] - margin,
73-
f"{label} is above the notification bar",
74-
)
75-
self.assertLessEqual(
76-
center_y,
77-
bar_coords["y2"] + margin,
78-
f"{label} is below the notification bar",
79-
)
79+
def _assert_within_bar(self, widget, bar, label):
80+
self.assertIsNotNone(widget, f"{label} widget not available")
81+
try:
82+
self.assertFalse(
83+
widget.has_flag(lv.obj.FLAG.HIDDEN),
84+
f"{label} is hidden",
85+
)
86+
except Exception:
87+
pass
88+
node = widget
89+
for _ in range(20):
90+
if node is bar:
91+
return
92+
try:
93+
node = node.get_parent()
94+
except Exception:
95+
node = None
96+
if node is None:
97+
break
98+
self.fail(f"{label} is not within the notification bar hierarchy")
8099

81100
def _wait_for_drawer_open(self, timeout_ms=2000):
82101
start = time.ticks_ms()
@@ -149,27 +168,15 @@ def test_notification_bar_widgets_visible(self):
149168
self.assertIsNotNone(bar, "Notification bar was not created")
150169

151170
wait_for_render(iterations=30)
152-
bar_coords = get_widget_coords(bar)
153-
self.assertIsNotNone(bar_coords, "Notification bar coords not available")
154-
if bar_coords["y1"] < 0:
171+
if not self._wait_for_bar_visible():
155172
topmenu.open_bar()
156173
wait_for_render(iterations=60)
157-
bar_coords = get_widget_coords(bar)
158-
if bar_coords and bar_coords["y1"] < 0:
159-
bar.set_y(0)
160-
wait_for_render(iterations=30)
161-
bar_coords = get_widget_coords(bar)
162-
self.assertIsNotNone(bar_coords, "Notification bar coords not available")
163-
self.assertGreaterEqual(
164-
bar_coords["y1"],
165-
-1,
166-
"Notification bar is not visible (y position is too high)",
167-
)
168-
self.assertGreaterEqual(
169-
bar_coords["y2"],
170-
AppearanceManager.NOTIFICATION_BAR_HEIGHT - 1,
171-
"Notification bar height is smaller than expected",
172-
)
174+
if bar is not None:
175+
bar.set_y(0)
176+
wait_for_render(iterations=30)
177+
bar_coords = get_widget_coords(bar)
178+
self.assertIsNotNone(bar_coords, "Notification bar coords not available")
179+
self.assertTrue(topmenu.bar_open, "Notification bar was not marked open")
173180

174181
labels = self._get_bar_labels(bar)
175182
time_label = next((child for child, text in labels if ":" in text), None)
@@ -191,11 +198,11 @@ def test_notification_bar_widgets_visible(self):
191198
if BatteryManager.has_battery():
192199
self.assertIsNotNone(battery_label, "Battery icon not found in notification bar")
193200

194-
self._assert_within_bar(time_label, bar_coords, "Clock label")
195-
self._assert_within_bar(temp_label, bar_coords, "Temperature label")
196-
self._assert_within_bar(wifi_label, bar_coords, "WiFi icon")
201+
self._assert_within_bar(time_label, bar, "Clock label")
202+
self._assert_within_bar(temp_label, bar, "Temperature label")
203+
self._assert_within_bar(wifi_label, bar, "WiFi icon")
197204
if battery_label is not None:
198-
self._assert_within_bar(battery_label, bar_coords, "Battery icon")
205+
self._assert_within_bar(battery_label, bar, "Battery icon")
199206

200207
self.assertTrue(
201208
self._ensure_drawer_open(bar_coords),

0 commit comments

Comments
 (0)