-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These are a few generic tests that can be run on all Powered Up hubs.
- Loading branch information
Showing
7 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Should be able to handle an empty program. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |