Skip to content

Commit

Permalink
tests: add basic Powered Up tests
Browse files Browse the repository at this point in the history
These are a few generic tests that can be run on all Powered Up hubs.
  • Loading branch information
dlech committed Apr 21, 2021
1 parent c3a76f1 commit 8f61ad2
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/REAMDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Pybricks MicroPython tests

Currently, the tests in the `ev3dev` folder are automated while the remaining
folders contain tests that must be run manually.

Use `./test-ev3dev.sh` in the top-level directory to run the automated tests
(requires Linux).
17 changes: 17 additions & 0 deletions tests/basic/count_forever.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Should be able to print forever in a tight loop.

# Used to reproduce bug on https://github.com/pybricks/support/issues/163
# and https://github.com/pybricks/support/issues/36

# If it gets to at least 100000, things are looking good.


def count():
n = 0
while True:
yield n
n += 1


for n in count():
print("count:", n)
1 change: 1 addition & 0 deletions tests/basic/empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Should be able to handle an empty program.
2 changes: 2 additions & 0 deletions tests/basic/hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Should be able to do a simple hello world.
print("Hello world!")
14 changes: 14 additions & 0 deletions tests/basic/system_exit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Should be able to catch SystemExit from the stop button.

from pybricks.tools import wait

for i in range(3):
print("press stop button...")
try:
while True:
wait(10)
except SystemExit:
print("caught SystemExit", i)

# Should print this after pressing the stop button 3 times.
print("...done")
23 changes: 23 additions & 0 deletions tests/pup/hub/status_light.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Should be able to display each color (note: colors without 100% saturation
# will not appear correctly due to physics).

# Press the stop button to advance to the next color

from pybricks.hubs import *
from pybricks.parameters import Color
from pybricks.tools import wait

# sneaky way to get XyzHub class without knowning which hub
hub = next(v for k, v in globals().items() if k.endswith("Hub"))()

for c in Color:
print("Color:", c)
hub.light.on(Color[c])
try:
while True:
wait(10)
except SystemExit:
continue

hub.light.off()
print("...done")
17 changes: 17 additions & 0 deletions tests/pup/hub/status_light_animatinon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Should be able to smoothly transition between all colors.

from pybricks.hubs import *
from pybricks.parameters import Color
from pybricks.tools import wait

# sneaky way to get XyzHub class without knowning which hub
hub = next(v for k, v in globals().items() if k.endswith("Hub"))()

# Every possible hue with 100% saturation, 100% brightness.
# Note: In real programs, use every 2 or 3 degrees to save memory.
rainbow = [Color.BLUE >> d for d in range(360)]

hub.light.animate(rainbow, 100)

while True:
wait(10)

0 comments on commit 8f61ad2

Please sign in to comment.