Skip to content

Commit 4bbcab9

Browse files
Fix --ondevice
1 parent aea7244 commit 4bbcab9

File tree

4 files changed

+90
-48
lines changed

4 files changed

+90
-48
lines changed

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Tests are in the `tests/` directory. There are two types: unit tests and manual
175175
./tests/unittest.sh tests/test_shared_preferences.py
176176
./tests/unittest.sh tests/test_intent.py
177177
./tests/unittest.sh tests/test_package_manager.py
178-
./tests/unittest.sh tests/test_start_app.py
178+
./tests/unittest.sh tests/test_graphical_start_app.py
179179

180180
# Run a specific test on connected device (via mpremote)
181181
./tests/unittest.sh tests/test_shared_preferences.py --ondevice
@@ -196,7 +196,7 @@ The `unittest.sh` script:
196196
- `test_shared_preferences.py`: Tests for `mpos.config.SharedPreferences` (configuration storage)
197197
- `test_intent.py`: Tests for `mpos.content.intent.Intent` (intent creation, extras, flags)
198198
- `test_package_manager.py`: Tests for `PackageManager` (version comparison, app discovery)
199-
- `test_start_app.py`: Tests for app launching (requires SDL display initialization)
199+
- `test_graphical_start_app.py`: Tests for app launching (graphical test with proper boot/main initialization)
200200
- `test_graphical_about_app.py`: Graphical test that verifies About app UI and captures screenshots
201201

202202
**Graphical tests** (UI verification with screenshots):

tests/test_graphical_start_app.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""
2+
Test for app launching functionality.
3+
4+
This test verifies that the app starting system works correctly,
5+
including launching existing apps and handling non-existent apps.
6+
7+
Works on both desktop and ESP32 by using the standard boot/main
8+
initialization pattern.
9+
10+
Usage:
11+
Desktop: ./tests/unittest.sh tests/test_graphical_start_app.py
12+
Device: ./tests/unittest.sh tests/test_graphical_start_app.py --ondevice
13+
"""
14+
15+
import unittest
16+
import mpos.apps
17+
import mpos.ui
18+
from graphical_test_helper import wait_for_render
19+
20+
21+
class TestStartApp(unittest.TestCase):
22+
"""Test suite for app launching functionality."""
23+
24+
def setUp(self):
25+
"""Set up test fixtures before each test method."""
26+
print("\n=== Test Setup ===")
27+
# No custom initialization needed - boot.py/main.py already ran
28+
29+
def tearDown(self):
30+
"""Clean up after each test method."""
31+
# Navigate back to launcher to close any opened apps
32+
try:
33+
mpos.ui.back_screen()
34+
wait_for_render(5) # Allow navigation to complete
35+
except:
36+
pass # Already on launcher or error
37+
38+
print("=== Test Cleanup Complete ===\n")
39+
40+
def test_normal(self):
41+
"""Test that launching an existing app succeeds."""
42+
print("Testing normal app launch...")
43+
44+
result = mpos.apps.start_app("com.micropythonos.launcher")
45+
wait_for_render(10) # Wait for app to load
46+
47+
self.assertTrue(result, "com.micropythonos.launcher should start")
48+
print("Normal app launch successful")
49+
50+
def test_nonexistent(self):
51+
"""Test that launching a non-existent app fails gracefully."""
52+
print("Testing non-existent app launch...")
53+
54+
result = mpos.apps.start_app("com.micropythonos.nonexistent")
55+
56+
self.assertFalse(result, "com.micropythonos.nonexistent should not start")
57+
print("Non-existent app handled correctly")
58+
59+
def test_restart_launcher(self):
60+
"""Test that restarting the launcher succeeds."""
61+
print("Testing launcher restart...")
62+
63+
result = mpos.apps.restart_launcher()
64+
wait_for_render(10) # Wait for launcher to load
65+
66+
self.assertTrue(result, "restart_launcher() should succeed")
67+
print("Launcher restart successful")
68+
69+
70+
if __name__ == "__main__":
71+
unittest.main()

tests/test_start_app.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/unittest.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ fs="$mydir"/../internal_filesystem/
1010
ondevice=""
1111
onetest=""
1212

13-
for arg in "$@"; do
14-
if [ "$arg" = "--ondevice" ]; then
15-
ondevice="yes"
16-
else
17-
onetest="$arg"
18-
fi
13+
while [ $# -gt 0 ]; do
14+
case "$1" in
15+
--ondevice)
16+
ondevice="yes"
17+
;;
18+
*)
19+
onetest="$1"
20+
;;
21+
esac
22+
shift
1923
done
2024

2125

@@ -68,7 +72,7 @@ result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) "
6872
fi
6973
result=$?
7074
else
71-
# Device execution
75+
echo "Device execution"
7276
# NOTE: On device, the OS is already running with boot.py and main.py executed,
7377
# so we don't need to (and shouldn't) re-run them. The system is already initialized.
7478
cleanname=$(echo "$file" | sed "s#/#_#g")
@@ -103,6 +107,7 @@ else:
103107
}
104108

105109
failed=0
110+
ran=0
106111

107112
if [ -z "$onetest" ]; then
108113
echo "Usage: $0 [one_test_to_run.py] [--ondevice]"
@@ -120,19 +125,22 @@ if [ -z "$onetest" ]; then
120125
echo "\n\n\nWARNING: test $file got error $result !!!\n\n\n"
121126
failed=$(expr $failed \+ 1)
122127
exit 1
128+
else
129+
ran=$(expr $ran \+ 1)
123130
fi
124131
done < <( find "$testdir" -iname "test_*.py" )
125132
else
133+
echo "doing $onetest"
126134
one_test $(readlink -f "$onetest")
127135
[ $? -ne 0 ] && failed=1
128136
fi
129137

130138

131139
if [ $failed -ne 0 ]; then
132-
echo "ERROR: $failed .py files have failing unit tests"
140+
echo "ERROR: $failed of the $ran tests failed"
133141
exit 1
134142
else
135-
echo "GOOD: no .py files have failing unit tests"
143+
echo "GOOD: none of the $ran tests failed"
136144
exit 0
137145
fi
138146

0 commit comments

Comments
 (0)