-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing infrastructure and test for shapes example (#14)
Add a basic byte-checked test for examples.
- Loading branch information
1 parent
87761fd
commit 9035351
Showing
6 changed files
with
475 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,23 @@ | ||
name: "Run Tests" | ||
|
||
on: | ||
- workflow_dispatch | ||
- pull_request | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
- name: Install dependencies and local packages | ||
run: python -m pip install mpremote click | ||
- name: Install MicroPython | ||
uses: BrianPugh/install-micropython@v2 | ||
- name: Install Micropython dependencies | ||
run: micropython -m mip install unittest | ||
- name: Run tests | ||
run: python -m ci.test |
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,38 @@ | ||
import array | ||
from pathlib import Path | ||
|
||
from PIL import Image | ||
|
||
def read_rgb565(path): | ||
with open(path, 'rb') as fp: | ||
buffer = fp.read() | ||
|
||
rgb565 = array.array('H', buffer) | ||
rgb565.byteswap() | ||
return rgb565 | ||
|
||
def rgb565_to_rgb24(rgb565): | ||
rgb24 = array.array('B', bytearray(3*len(rgb565))) | ||
for i, pixel in enumerate(rgb565): | ||
r = (pixel & 0b1111100000000000) >> 11 | ||
g = (pixel & 0b0000011111100000) >> 5 | ||
b = (pixel & 0b0000000000011111) | ||
rgb24[3 * i] = int((r / 31) * 255) | ||
rgb24[3 * i + 1] = int(round((g / 63) * 255)) | ||
rgb24[3 * i + 2] = int(round((b / 31) * 255)) | ||
return rgb24 | ||
|
||
|
||
def rgb565_to_png(size, in_path, out_path=None): | ||
if out_path is None: | ||
out_path = Path(in_path.stem + '.png') | ||
|
||
rgb565 = read_rgb565(in_path) | ||
rgb24 = rgb565_to_rgb24(rgb565) | ||
image = Image.frombuffer("RGB", size, rgb24) | ||
image.save(out_path) | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
|
||
rgb565_to_png((320, 240), Path(sys.argv[1])) |
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,53 @@ | ||
# SPDX-FileCopyrightText: 2024-present Unital Software <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from pathlib import Path | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
import click | ||
|
||
|
||
|
||
@click.command() | ||
def test(): | ||
"""Run unit tests in micropython""" | ||
print("Running Tests") | ||
failures = [] | ||
test_dir = Path("tests/tempe") | ||
os.environ["MICROPYPATH"] = "src:" + os.environ.get('MICROPYPATH', ":.frozen:~/.micropython/lib:/usr/lib/micropython") | ||
for path in sorted(test_dir.glob("*.py")): | ||
print(path.name, "... ", end="", flush=True) | ||
result = run_test(path) | ||
if result: | ||
failures.append(result) | ||
print('FAILED') | ||
else: | ||
print('OK') | ||
print() | ||
|
||
for path, stdout, stderr in failures: | ||
print("FAILURE: ", path.name) | ||
print("STDOUT ", "="*70) | ||
print(stdout.decode('utf-8')) | ||
print() | ||
print("STDERR ", "="*70) | ||
print(stderr.decode('utf-8')) | ||
print() | ||
|
||
if failures: | ||
sys.exit(1) | ||
else: | ||
print("PASSED") | ||
|
||
|
||
def run_test(path): | ||
try: | ||
result = subprocess.run(["micropython", path], capture_output=True, check=True) | ||
except subprocess.CalledProcessError as exc: | ||
return (path, exc.stdout, exc.stderr) | ||
|
||
if __name__ == "__main__": | ||
test() |
Oops, something went wrong.