Files

154 lines
5.7 KiB
Python
Raw Permalink Normal View History

"""
Graphical test for IMU calibration activities.
Tests both CheckIMUCalibrationActivity and CalibrateIMUActivity
with mock data on desktop.
Usage:
Desktop: ./tests/unittest.sh tests/test_graphical_imu_calibration.py
Device: ./tests/unittest.sh tests/test_graphical_imu_calibration.py --ondevice
"""
import unittest
import lvgl as lv
import mpos.ui
import time
2026-01-13 00:38:17 +01:00
from mpos import (
wait_for_render,
find_label_with_text,
verify_text_present,
print_screen_labels,
simulate_click,
get_widget_coords,
2025-12-08 11:52:27 +01:00
find_button_with_text,
click_label,
click_button,
find_text_on_screen,
2026-01-25 00:19:38 +01:00
AppManager
)
class TestIMUCalibration(unittest.TestCase):
"""Test suite for IMU calibration activities."""
def tearDown(self):
"""Clean up after test."""
# Navigate back to launcher
try:
for _ in range(3): # May need multiple backs
mpos.ui.back_screen()
wait_for_render(5)
except:
pass
def test_check_calibration_activity_loads(self):
"""Test that CheckIMUCalibrationActivity loads and displays."""
print("\n=== Testing CheckIMUCalibrationActivity ===")
# Navigate: Launcher -> Settings -> Check IMU Calibration
2026-01-25 00:19:38 +01:00
result = AppManager.start_app("com.micropythonos.settings")
self.assertTrue(result, "Failed to start Settings app")
wait_for_render(15)
# Initialize touch device with dummy click
simulate_click(10, 10)
wait_for_render(10)
2025-12-08 11:52:27 +01:00
print("Clicking 'Check IMU Calibration' menu item...")
self.assertTrue(click_label("Check IMU Calibration"), "Could not find Check IMU Calibration menu item")
wait_for_render(iterations=20)
# Verify key elements are present
2025-12-07 15:11:47 +01:00
screen = lv.screen_active()
print_screen_labels(screen)
2025-12-07 15:11:47 +01:00
self.assertTrue(verify_text_present(screen, "Quality:"), "Quality label not found")
self.assertTrue(verify_text_present(screen, "Accel."), "Accel. label not found")
self.assertTrue(verify_text_present(screen, "Gyro"), "Gyro label not found")
print("=== CheckIMUCalibrationActivity test complete ===")
def test_calibrate_activity_flow(self):
"""Test CalibrateIMUActivity full calibration flow."""
print("\n=== Testing CalibrateIMUActivity Flow ===")
# Navigate: Launcher -> Settings -> Calibrate IMU
2026-01-25 00:19:38 +01:00
result = AppManager.start_app("com.micropythonos.settings")
self.assertTrue(result, "Failed to start Settings app")
wait_for_render(15)
# Initialize touch device with dummy click
simulate_click(10, 10)
wait_for_render(10)
2025-12-08 11:52:27 +01:00
print("Clicking 'Calibrate IMU' menu item...")
self.assertTrue(click_label("Calibrate IMU"), "Could not find Calibrate IMU item")
wait_for_render(iterations=20)
2025-12-07 09:17:24 +01:00
# Verify activity loaded and shows instructions
screen = lv.screen_active()
2025-12-07 09:17:24 +01:00
print_screen_labels(screen)
self.assertTrue(verify_text_present(screen, "IMU Calibration"),
"CalibrateIMUActivity title not found")
2025-12-07 09:17:24 +01:00
self.assertTrue(verify_text_present(screen, "Place device on flat"),
"Instructions not shown")
2025-12-07 09:17:24 +01:00
# Click "Calibrate Now" button to start calibration
calibrate_btn = find_button_with_text(screen, "Calibrate Now")
self.assertIsNotNone(calibrate_btn, "Could not find 'Calibrate Now' button")
2025-12-19 11:30:31 +01:00
# Use send_event instead of simulate_click (more reliable)
calibrate_btn.send_event(lv.EVENT.CLICKED, None)
wait_for_render(10)
# Wait for calibration to complete (mock takes ~3 seconds)
time.sleep(4)
wait_for_render(40)
# Verify calibration completed
screen = lv.screen_active()
print_screen_labels(screen)
2025-12-07 09:17:24 +01:00
self.assertTrue(verify_text_present(screen, "Calibration successful!"),
"Calibration completion message not found")
2025-12-07 09:17:24 +01:00
# Verify offsets are shown
self.assertTrue(verify_text_present(screen, "Accel offsets") or
verify_text_present(screen, "offsets"),
"Calibration offsets not shown")
print("=== CalibrateIMUActivity flow test complete ===")
def test_navigation_from_check_to_calibrate(self):
"""Test navigation from Check to Calibrate activity via button."""
print("\n=== Testing Check -> Calibrate Navigation ===")
# Navigate to Check activity
2026-01-25 00:19:38 +01:00
result = AppManager.start_app("com.micropythonos.settings")
self.assertTrue(result)
wait_for_render(15)
# Initialize touch device with dummy click
simulate_click(10, 10)
wait_for_render(10)
2025-12-08 11:52:27 +01:00
print("Clicking 'Check IMU Calibration' menu item...")
self.assertTrue(click_label("Check IMU Calibration"), "Could not find Check IMU Calibration menu item")
wait_for_render(iterations=20)
2025-12-07 09:17:24 +01:00
# Click "Calibrate" button to navigate to Calibrate activity
2025-12-08 11:52:27 +01:00
screen = lv.screen_active()
calibrate_btn = find_button_with_text(screen, "Calibrate")
self.assertIsNotNone(calibrate_btn, "Could not find 'Calibrate' button")
2025-12-07 09:17:24 +01:00
# Use send_event instead of simulate_click (more reliable for navigation)
calibrate_btn.send_event(lv.EVENT.CLICKED, None)
wait_for_render(30)
# Verify CalibrateIMUActivity loaded
screen = lv.screen_active()
2025-12-07 09:17:24 +01:00
print_screen_labels(screen)
self.assertTrue(verify_text_present(screen, "Calibrate Now"),
"Did not navigate to CalibrateIMUActivity")
2025-12-07 09:17:24 +01:00
self.assertTrue(verify_text_present(screen, "Place device on flat"),
"CalibrateIMUActivity instructions not shown")
print("=== Navigation test complete ===")