-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
2 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,24 @@ | ||
name: Run Python examples | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 6 * * 1' | ||
|
||
jobs: | ||
run-examples: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python 3.12 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
- name: Install uxsim and dependencies | ||
run: pip install . | ||
- name: Install pytest other dependencies | ||
run: pip install pytest setuptools gymnasium torch | ||
- name: Run examples with pytest | ||
run: pytest demos_and_examples/test_examples.py --durations=0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
import subprocess | ||
import os | ||
|
||
# Directory containing example scripts | ||
examples_dir = 'demos_and_examples' | ||
|
||
# Dynamically generate test cases for each example script | ||
def pytest_generate_tests(metafunc): | ||
# List all .py files in the examples_dir | ||
example_scripts = [f for f in os.listdir(examples_dir) if f.endswith('.py')] | ||
# If the test function expects an "example_script" argument, parametrize it | ||
if 'example_script' in metafunc.fixturenames: | ||
metafunc.parametrize('example_script', example_scripts) | ||
|
||
def test_example_runs(example_script): | ||
"""Test that a Python example script runs successfully.""" | ||
# Build the script path | ||
script_path = os.path.join(examples_dir, example_script) | ||
# Run the script as a separate process | ||
result = subprocess.run(['python', script_path], capture_output=True, text=True) | ||
# Assert that the script ran successfully | ||
assert result.returncode == 0, f"Script {example_script} failed with output:\n{result.stdout}\n{result.stderr}" |