Move mpos.apps functionality to PackageManager

This commit is contained in:
Thomas Farstrike
2026-01-25 00:08:01 +01:00
parent ffdabf1342
commit 31dcfba683
24 changed files with 211 additions and 185 deletions
-1
View File
@@ -6,7 +6,6 @@ import time
import unittest
from mpos import App, PackageManager
import mpos.apps
from nostr.relay_manager import RelayManager
from nostr.message_type import ClientMessageType
-2
View File
@@ -8,7 +8,6 @@ from mpos.testing import (
MockPWM,
MockPin,
MockThread,
MockApps,
inject_mocks,
)
@@ -16,7 +15,6 @@ from mpos.testing import (
inject_mocks({
'machine': MockMachine(),
'_thread': MockThread,
'mpos.apps': MockApps,
})
# Now import the module to test
+4 -4
View File
@@ -17,7 +17,6 @@ Usage:
import unittest
import lvgl as lv
import mpos.apps
import mpos.ui
import os
from mpos import (
@@ -27,7 +26,8 @@ from mpos import (
verify_text_present,
print_screen_labels,
DeviceInfo,
BuildInfo
BuildInfo,
PackageManager
)
@@ -78,7 +78,7 @@ class TestGraphicalAboutApp(unittest.TestCase):
print("\n=== Starting About app test ===")
# Start the About app
result = mpos.apps.start_app("com.micropythonos.about")
result = PackageManager.start_app("com.micropythonos.about")
self.assertTrue(result, "Failed to start About app")
# Wait for UI to fully render
@@ -146,7 +146,7 @@ class TestGraphicalAboutApp(unittest.TestCase):
print("\n=== Starting About app OS version test ===")
# Start the About app
result = mpos.apps.start_app("com.micropythonos.about")
result = PackageManager.start_app("com.micropythonos.about")
self.assertTrue(result, "Failed to start About app")
# Wait for UI to render
+4 -4
View File
@@ -19,7 +19,6 @@ Usage:
import unittest
import lvgl as lv
import mpos.apps
import mpos.ui
import os
import sys
@@ -31,7 +30,8 @@ from mpos import (
verify_text_present,
print_screen_labels,
simulate_click,
get_widget_coords
get_widget_coords,
PackageManager
)
@unittest.skipIf(sys.platform == 'darwin', "Camera tests not supported on macOS (no camera available)")
@@ -117,7 +117,7 @@ class TestGraphicalCameraSettings(unittest.TestCase):
print("\n=== Testing settings button click (no crash) ===")
# Start the Camera app
result = mpos.apps.start_app("com.micropythonos.camera")
result = PackageManager.start_app("com.micropythonos.camera")
self.assertTrue(result, "Failed to start Camera app")
# Wait for camera to initialize and first frame to render
@@ -251,7 +251,7 @@ class TestGraphicalCameraSettings(unittest.TestCase):
print("\n=== Testing resolution change (no crash) ===")
# Start the Camera app
result = mpos.apps.start_app("com.micropythonos.camera")
result = PackageManager.start_app("com.micropythonos.camera")
self.assertTrue(result, "Failed to start Camera app")
# Wait for camera to initialize
+5 -5
View File
@@ -11,7 +11,6 @@ Usage:
import unittest
import lvgl as lv
import mpos.apps
import mpos.ui
import os
import sys
@@ -27,7 +26,8 @@ from mpos import (
find_button_with_text,
click_label,
click_button,
find_text_on_screen
find_text_on_screen,
PackageManager
)
@@ -63,7 +63,7 @@ class TestIMUCalibration(unittest.TestCase):
print("\n=== Testing CheckIMUCalibrationActivity ===")
# Navigate: Launcher -> Settings -> Check IMU Calibration
result = mpos.apps.start_app("com.micropythonos.settings")
result = PackageManager.start_app("com.micropythonos.settings")
self.assertTrue(result, "Failed to start Settings app")
wait_for_render(15)
@@ -98,7 +98,7 @@ class TestIMUCalibration(unittest.TestCase):
print("\n=== Testing CalibrateIMUActivity Flow ===")
# Navigate: Launcher -> Settings -> Calibrate IMU
result = mpos.apps.start_app("com.micropythonos.settings")
result = PackageManager.start_app("com.micropythonos.settings")
self.assertTrue(result, "Failed to start Settings app")
wait_for_render(15)
@@ -155,7 +155,7 @@ class TestIMUCalibration(unittest.TestCase):
print("\n=== Testing Check -> Calibrate Navigation ===")
# Navigate to Check activity
result = mpos.apps.start_app("com.micropythonos.settings")
result = PackageManager.start_app("com.micropythonos.settings")
self.assertTrue(result)
wait_for_render(15)
@@ -26,7 +26,8 @@ from mpos import (
capture_screenshot,
click_label,
click_button,
find_text_on_screen
find_text_on_screen,
PackageManager
)
@@ -43,10 +44,9 @@ class TestIMUCalibrationUI(unittest.TestCase):
# Step 2: Open Settings app
print("Step 2: Opening Settings app...")
import mpos.apps
# Start Settings app by name
mpos.apps.start_app("com.micropythonos.settings")
PackageManager.start_app("com.micropythonos.settings")
wait_for_render(iterations=30)
print("Settings app opened\n")
+3 -3
View File
@@ -13,7 +13,7 @@ import time
# This is a graphical test - needs boot and main to run first
# Add tests directory to path for helpers
from mpos import wait_for_render, apps, ui, PackageManager
from mpos import wait_for_render, ui, PackageManager
class TestLaunchAllApps(unittest.TestCase):
@@ -64,7 +64,7 @@ class TestLaunchAllApps(unittest.TestCase):
try:
# Launch the app by package name
result = mpos.apps.start_app(package_name)
result = PackageManager.start_app(package_name)
# Wait for UI to render
wait_for_render(iterations=5)
@@ -188,7 +188,7 @@ class TestLaunchSpecificApps(unittest.TestCase):
try:
# Launch the app by package name
result = mpos.apps.start_app(package_name)
result = PackageManager.start_app(package_name)
wait_for_render(iterations=5)
# Check if start_app returned False (indicates error)
+13 -12
View File
@@ -13,7 +13,8 @@ from mpos import (
verify_text_present,
print_screen_labels,
DeviceInfo,
BuildInfo
BuildInfo,
PackageManager
)
@@ -28,7 +29,7 @@ class TestOSUpdateGraphicalUI(unittest.TestCase):
def test_app_launches_successfully(self):
"""Test that OSUpdate app launches without errors."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result, "Failed to start OSUpdate app")
wait_for_render(10)
@@ -39,7 +40,7 @@ class TestOSUpdateGraphicalUI(unittest.TestCase):
def test_ui_elements_exist(self):
"""Test that all required UI elements are created."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(15)
@@ -59,7 +60,7 @@ class TestOSUpdateGraphicalUI(unittest.TestCase):
def test_force_checkbox_initially_unchecked(self):
"""Test that force update checkbox starts unchecked."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(15)
@@ -102,7 +103,7 @@ class TestOSUpdateGraphicalUI(unittest.TestCase):
def test_install_button_initially_disabled(self):
"""Test that install button starts in disabled state."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(15)
@@ -138,7 +139,7 @@ class TestOSUpdateGraphicalUI(unittest.TestCase):
def test_current_version_displayed(self):
"""Test that current OS version is displayed correctly."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(15)
@@ -158,7 +159,7 @@ class TestOSUpdateGraphicalUI(unittest.TestCase):
"""Test status message when wifi is not connected."""
# This test assumes desktop mode where wifi check returns True
# On actual hardware without wifi, it would show error
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(15)
@@ -173,7 +174,7 @@ class TestOSUpdateGraphicalUI(unittest.TestCase):
def test_screenshot_initial_state(self):
"""Capture screenshot of initial app state."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(20)
@@ -206,7 +207,7 @@ class TestOSUpdateGraphicalStatusMessages(unittest.TestCase):
def test_status_label_exists(self):
"""Test that status label is created and visible."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(15)
@@ -225,7 +226,7 @@ class TestOSUpdateGraphicalStatusMessages(unittest.TestCase):
def test_all_labels_readable(self):
"""Test that all labels are readable (no truncation issues)."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(15)
@@ -263,14 +264,14 @@ class TestOSUpdateGraphicalScreenshots(unittest.TestCase):
def test_capture_main_screen(self):
"""Capture screenshot of main OSUpdate screen."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(20)
def test_capture_with_labels_visible(self):
"""Capture screenshot ensuring all text is visible."""
result = mpos.apps.start_app("com.micropythonos.osupdate")
result = PackageManager.start_app("com.micropythonos.osupdate")
self.assertTrue(result)
wait_for_render(20)
+4 -5
View File
@@ -13,8 +13,7 @@ Usage:
"""
import unittest
import mpos.apps
from mpos import ui, wait_for_render
from mpos import ui, wait_for_render, PackageManager
class TestStartApp(unittest.TestCase):
@@ -40,7 +39,7 @@ class TestStartApp(unittest.TestCase):
"""Test that launching an existing app succeeds."""
print("Testing normal app launch...")
result = mpos.apps.start_app("com.micropythonos.launcher")
result = PackageManager.start_app("com.micropythonos.launcher")
wait_for_render(10) # Wait for app to load
self.assertTrue(result, "com.micropythonos.launcher should start")
@@ -50,7 +49,7 @@ class TestStartApp(unittest.TestCase):
"""Test that launching a non-existent app fails gracefully."""
print("Testing non-existent app launch...")
result = mpos.apps.start_app("com.micropythonos.nonexistent")
result = PackageManager.start_app("com.micropythonos.nonexistent")
self.assertFalse(result, "com.micropythonos.nonexistent should not start")
print("Non-existent app handled correctly")
@@ -59,7 +58,7 @@ class TestStartApp(unittest.TestCase):
"""Test that restarting the launcher succeeds."""
print("Testing launcher restart...")
result = mpos.apps.restart_launcher()
result = PackageManager.restart_launcher()
wait_for_render(10) # Wait for launcher to load
self.assertTrue(result, "restart_launcher() should succeed")
+8 -8
View File
@@ -8,7 +8,7 @@ class TestSysPathRestore(unittest.TestCase):
def test_syspath_restored_after_execute_script(self):
"""Test that sys.path is restored to original state after script execution"""
# Import here to ensure we're in the right context
import mpos.apps
from mpos import PackageManager
# Capture original sys.path
original_path = sys.path[:]
@@ -31,11 +31,11 @@ x = 42
# Call execute_script with cwd parameter
# Note: This will fail because there's no Activity to start,
# but that's fine - we're testing the sys.path restoration
result = mpos.apps.execute_script(
result = PackageManager.execute_script(
test_script,
is_file=False,
cwd=test_cwd,
classname="NonExistentClass"
classname="NonExistentClass",
cwd=test_cwd
)
# After execution, sys.path should be restored
@@ -56,7 +56,7 @@ x = 42
def test_syspath_not_affected_when_no_cwd(self):
"""Test that sys.path is unchanged when cwd is None"""
import mpos.apps
from mpos import PackageManager
# Capture original sys.path
original_path = sys.path[:]
@@ -66,11 +66,11 @@ x = 42
'''
# Call without cwd parameter
result = mpos.apps.execute_script(
result = PackageManager.execute_script(
test_script,
is_file=False,
cwd=None,
classname="NonExistentClass"
classname="NonExistentClass",
cwd=None
)
# sys.path should be unchanged
-1
View File
@@ -5,7 +5,6 @@ import time
from mpos import App, PackageManager
from mpos import TaskManager
import mpos.apps
from websocket import WebSocketApp
+1 -1
View File
@@ -64,7 +64,7 @@ one_test() {
# Desktop execution
if [ $is_graphical -eq 1 ]; then
echo "Graphical test: include main.py"
"$binary" -X heapsize=8M -c "import sys ; sys.path.insert(0, 'lib') ; import mpos ; mpos.TaskManager.disable() ; $(cat main.py) ; import mpos.apps; sys.path.append(\"$tests_abs_path\")
"$binary" -X heapsize=8M -c "import sys ; sys.path.insert(0, 'lib') ; import mpos ; mpos.TaskManager.disable() ; $(cat main.py) ; sys.path.append(\"$tests_abs_path\")
$(cat $file)
result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) "
result=$?