Skip to content

Commit 8f61ad2

Browse files
committed
tests: add basic Powered Up tests
These are a few generic tests that can be run on all Powered Up hubs.
1 parent c3a76f1 commit 8f61ad2

File tree

7 files changed

+81
-0
lines changed

7 files changed

+81
-0
lines changed

tests/REAMDE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Pybricks MicroPython tests
2+
3+
Currently, the tests in the `ev3dev` folder are automated while the remaining
4+
folders contain tests that must be run manually.
5+
6+
Use `./test-ev3dev.sh` in the top-level directory to run the automated tests
7+
(requires Linux).

tests/basic/count_forever.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Should be able to print forever in a tight loop.
2+
3+
# Used to reproduce bug on https://github.com/pybricks/support/issues/163
4+
# and https://github.com/pybricks/support/issues/36
5+
6+
# If it gets to at least 100000, things are looking good.
7+
8+
9+
def count():
10+
n = 0
11+
while True:
12+
yield n
13+
n += 1
14+
15+
16+
for n in count():
17+
print("count:", n)

tests/basic/empty.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Should be able to handle an empty program.

tests/basic/hello_world.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Should be able to do a simple hello world.
2+
print("Hello world!")

tests/basic/system_exit.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Should be able to catch SystemExit from the stop button.
2+
3+
from pybricks.tools import wait
4+
5+
for i in range(3):
6+
print("press stop button...")
7+
try:
8+
while True:
9+
wait(10)
10+
except SystemExit:
11+
print("caught SystemExit", i)
12+
13+
# Should print this after pressing the stop button 3 times.
14+
print("...done")

tests/pup/hub/status_light.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Should be able to display each color (note: colors without 100% saturation
2+
# will not appear correctly due to physics).
3+
4+
# Press the stop button to advance to the next color
5+
6+
from pybricks.hubs import *
7+
from pybricks.parameters import Color
8+
from pybricks.tools import wait
9+
10+
# sneaky way to get XyzHub class without knowning which hub
11+
hub = next(v for k, v in globals().items() if k.endswith("Hub"))()
12+
13+
for c in Color:
14+
print("Color:", c)
15+
hub.light.on(Color[c])
16+
try:
17+
while True:
18+
wait(10)
19+
except SystemExit:
20+
continue
21+
22+
hub.light.off()
23+
print("...done")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Should be able to smoothly transition between all colors.
2+
3+
from pybricks.hubs import *
4+
from pybricks.parameters import Color
5+
from pybricks.tools import wait
6+
7+
# sneaky way to get XyzHub class without knowning which hub
8+
hub = next(v for k, v in globals().items() if k.endswith("Hub"))()
9+
10+
# Every possible hue with 100% saturation, 100% brightness.
11+
# Note: In real programs, use every 2 or 3 degrees to save memory.
12+
rainbow = [Color.BLUE >> d for d in range(360)]
13+
14+
hub.light.animate(rainbow, 100)
15+
16+
while True:
17+
wait(10)

0 commit comments

Comments
 (0)