Skip to content

Commit 122b8e3

Browse files
tests/test_graphical_about_app.py: retry-based checks
...for About app labels and text to reduce timing sensitivity, including a helper to wait for the Hardware ID label and version text
1 parent 71e3ed3 commit 122b8e3

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

tests/test_graphical_about_app.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616

1717
import unittest
18+
import time
1819
import lvgl as lv
1920
import mpos.ui
2021
from mpos import (
@@ -31,6 +32,29 @@
3132
class TestGraphicalAboutApp(unittest.TestCase):
3233
"""Test suite for About app graphical verification."""
3334

35+
def _wait_for_text(self, text, attempts=6, render_iterations=30):
36+
for attempt in range(1, attempts + 1):
37+
screen = lv.screen_active()
38+
print(f"\nText check attempt {attempt}/{attempts}:")
39+
print_screen_labels(screen)
40+
if verify_text_present(screen, text):
41+
return True
42+
wait_for_render(iterations=render_iterations)
43+
time.sleep(0.2)
44+
return False
45+
46+
def _wait_for_label_with_text(self, text, attempts=6, render_iterations=30):
47+
for attempt in range(1, attempts + 1):
48+
screen = lv.screen_active()
49+
label = find_label_with_text(screen, text)
50+
if label is not None:
51+
return label
52+
print(f"\nLabel '{text}' not found (attempt {attempt}/{attempts}).")
53+
print_screen_labels(screen)
54+
wait_for_render(iterations=render_iterations)
55+
time.sleep(0.2)
56+
return None
57+
3458
def setUp(self):
3559
"""Set up test fixtures before each test method."""
3660
# Store hardware ID for verification
@@ -73,7 +97,7 @@ def test_about_app_shows_correct_hardware_id(self):
7397
print_screen_labels(screen)
7498

7599
# Verify that Hardware ID text is present
76-
hardware_id_label = find_label_with_text(screen, "Hardware ID:")
100+
hardware_id_label = self._wait_for_label_with_text("Hardware ID:")
77101
self.assertIsNotNone(
78102
hardware_id_label,
79103
"Could not find 'Hardware ID:' label on screen"
@@ -93,7 +117,7 @@ def test_about_app_shows_correct_hardware_id(self):
93117

94118
# Also verify using the helper function
95119
self.assertTrue(
96-
verify_text_present(screen, self.hardware_id),
120+
self._wait_for_text(self.hardware_id),
97121
f"Hardware ID '{self.hardware_id}' not found on screen"
98122
)
99123

@@ -119,14 +143,14 @@ def test_about_app_shows_os_version(self):
119143

120144
# Verify that MicroPythonOS version text is present
121145
self.assertTrue(
122-
verify_text_present(screen, "Release version:"),
146+
self._wait_for_text("Release version:"),
123147
"Could not find 'Release version:' on screen"
124148
)
125149

126150
# Verify the actual version string is present
127151
os_version = BuildInfo.version.release
128152
self.assertTrue(
129-
verify_text_present(screen, os_version),
153+
self._wait_for_text(os_version),
130154
f"OS version '{os_version}' not found on screen"
131155
)
132156

0 commit comments

Comments
 (0)