-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github action to run unit tests on every PR (#19)
Fixes #5
- Loading branch information
1 parent
8b9b5cf
commit 88fc553
Showing
6 changed files
with
111 additions
and
31 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: "Pull Request Docs Check" | ||
name: "Check Docs" | ||
|
||
on: | ||
- workflow_dispatch | ||
|
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2024-present Unital Software <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from pathlib import Path | ||
import subprocess | ||
|
||
|
@@ -6,6 +10,7 @@ | |
|
||
@click.command() | ||
def deploy(): | ||
"""Deploy files to a device via mpremote""" | ||
try: | ||
deploy_py_files(Path("docs/source/examples"), ":") | ||
deploy_py_files(Path("docs/source/examples/devices"), ":/devices") | ||
|
@@ -17,7 +22,6 @@ def deploy(): | |
print(exc.stderr) | ||
raise | ||
|
||
|
||
def deploy_py_files(path: Path, destination): | ||
try: | ||
mpremote("mkdir", destination) | ||
|
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/ultimo") | ||
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: | ||
subprocess.run(["micropython", path], capture_output=True, check=True) | ||
except subprocess.CalledProcessError as exc: | ||
return (path, exc.stdout, exc.stderr) | ||
|
||
if __name__ == "__main__": | ||
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
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