Skip to content

Commit 7a8cc92

Browse files
Fix unit tests
1 parent e94c8ab commit 7a8cc92

File tree

2 files changed

+27
-47
lines changed

2 files changed

+27
-47
lines changed

internal_filesystem/builtin/apps/com.micropythonos.settings/assets/check_imu_calibration.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def onCreate(self):
4242

4343
def onResume(self, screen):
4444
super().onResume(screen)
45-
print(f"[CheckIMU] onResume called, is_desktop={self.is_desktop}")
4645

4746
# Clear the screen and recreate UI (to avoid stale widget references)
4847
screen.clean()
@@ -132,16 +131,13 @@ def onResume(self, screen):
132131

133132
# Check if IMU is available
134133
if not self.is_desktop and not SensorManager.is_available():
135-
print("[CheckIMU] IMU not available, stopping")
136134
self.status_label.set_text("IMU not available on this device")
137135
self.quality_score_label.set_text("N/A")
138136
return
139137

140138
# Start real-time updates
141-
print("[CheckIMU] Starting real-time updates")
142139
self.updating = True
143140
self.update_timer = lv.timer_create(self.update_display, self.UPDATE_INTERVAL, None)
144-
print(f"[CheckIMU] Timer created: {self.update_timer}")
145141

146142
def onPause(self, screen):
147143
# Stop updates
@@ -206,16 +202,7 @@ def update_display(self, timer=None):
206202

207203
self.status_label.set_text("Real-time monitoring (place on flat surface)")
208204
except Exception as e:
209-
# Log the actual error for debugging
210-
print(f"[CheckIMU] Error in update_display: {e}")
211-
import sys
212-
sys.print_exception(e)
213-
# If widgets were deleted (activity closed), stop updating
214-
try:
215-
self.status_label.set_text(f"Error: {str(e)}")
216-
except:
217-
# Widgets really were deleted
218-
pass
205+
# If widgets were deleted (activity closed), stop updating silently
219206
self.updating = False
220207

221208
def get_mock_quality(self):

tests/test_graphical_imu_calibration.py

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -130,56 +130,42 @@ def test_calibrate_activity_flow(self):
130130
simulate_click(coords['center_x'], coords['center_y'])
131131
wait_for_render(30)
132132

133-
# Verify activity loaded
133+
# Verify activity loaded and shows instructions
134134
screen = lv.screen_active()
135+
print_screen_labels(screen)
135136
self.assertTrue(verify_text_present(screen, "IMU Calibration"),
136137
"CalibrateIMUActivity title not found")
138+
self.assertTrue(verify_text_present(screen, "Place device on flat"),
139+
"Instructions not shown")
137140

138141
# Capture initial state
139142
screenshot_path = f"{self.screenshot_dir}/calibrate_imu_01_initial.raw"
140143
capture_screenshot(screenshot_path)
141144

142-
# Step 1: Click "Check Quality" button
143-
check_btn = find_button_with_text(screen, "Check Quality")
144-
self.assertIsNotNone(check_btn, "Could not find 'Check Quality' button")
145-
coords = get_widget_coords(check_btn)
146-
simulate_click(coords['center_x'], coords['center_y'])
147-
wait_for_render(10)
148-
149-
# Wait for quality check to complete (mock is fast)
150-
time.sleep(2.5) # Allow thread to complete
151-
wait_for_render(15)
152-
153-
# Verify quality check completed
154-
screen = lv.screen_active()
155-
print_screen_labels(screen)
156-
self.assertTrue(verify_text_present(screen, "Current calibration:"),
157-
"Quality check results not shown")
158-
159-
# Capture after quality check
160-
screenshot_path = f"{self.screenshot_dir}/calibrate_imu_02_quality.raw"
161-
capture_screenshot(screenshot_path)
162-
163-
# Step 2: Click "Calibrate Now" button
145+
# Click "Calibrate Now" button to start calibration
164146
calibrate_btn = find_button_with_text(screen, "Calibrate Now")
165147
self.assertIsNotNone(calibrate_btn, "Could not find 'Calibrate Now' button")
166148
coords = get_widget_coords(calibrate_btn)
167149
simulate_click(coords['center_x'], coords['center_y'])
168150
wait_for_render(10)
169151

170152
# Wait for calibration to complete (mock takes ~3 seconds)
171-
time.sleep(4.0)
172-
wait_for_render(15)
153+
time.sleep(3.5)
154+
wait_for_render(20)
173155

174156
# Verify calibration completed
175157
screen = lv.screen_active()
176158
print_screen_labels(screen)
177-
self.assertTrue(verify_text_present(screen, "Calibration successful!") or
178-
verify_text_present(screen, "Calibration complete!"),
159+
self.assertTrue(verify_text_present(screen, "Calibration successful!"),
179160
"Calibration completion message not found")
180161

162+
# Verify offsets are shown
163+
self.assertTrue(verify_text_present(screen, "Accel offsets") or
164+
verify_text_present(screen, "offsets"),
165+
"Calibration offsets not shown")
166+
181167
# Capture completion state
182-
screenshot_path = f"{self.screenshot_dir}/calibrate_imu_03_complete.raw"
168+
screenshot_path = f"{self.screenshot_dir}/calibrate_imu_02_complete.raw"
183169
capture_screenshot(screenshot_path)
184170

185171
print("=== CalibrateIMUActivity flow test complete ===")
@@ -203,18 +189,25 @@ def test_navigation_from_check_to_calibrate(self):
203189
simulate_click(coords['center_x'], coords['center_y'])
204190
wait_for_render(30) # Wait for real-time updates
205191

206-
# Click "Calibrate" button
192+
# Verify Check activity loaded
207193
screen = lv.screen_active()
194+
self.assertTrue(verify_text_present(screen, "IMU Calibration Check"),
195+
"Check activity did not load")
196+
197+
# Click "Calibrate" button to navigate to Calibrate activity
208198
calibrate_btn = find_button_with_text(screen, "Calibrate")
209199
self.assertIsNotNone(calibrate_btn, "Could not find 'Calibrate' button")
210200

211-
coords = get_widget_coords(calibrate_btn)
212-
simulate_click(coords['center_x'], coords['center_y'])
213-
wait_for_render(15)
201+
# Use send_event instead of simulate_click (more reliable for navigation)
202+
calibrate_btn.send_event(lv.EVENT.CLICKED, None)
203+
wait_for_render(30)
214204

215205
# Verify CalibrateIMUActivity loaded
216206
screen = lv.screen_active()
217-
self.assertTrue(verify_text_present(screen, "Check Quality"),
207+
print_screen_labels(screen)
208+
self.assertTrue(verify_text_present(screen, "Calibrate Now"),
218209
"Did not navigate to CalibrateIMUActivity")
210+
self.assertTrue(verify_text_present(screen, "Place device on flat"),
211+
"CalibrateIMUActivity instructions not shown")
219212

220213
print("=== Navigation test complete ===")

0 commit comments

Comments
 (0)