Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
toruseo committed Mar 5, 2024
2 parents 297af68 + d4b18f4 commit 427560b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/run-examples.yml
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
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,18 @@ First, install UXsim package using pip:
```
pip install uxsim
```
or download the `uxsim` directory from this Github repo and place it to your local directory.
The former is required if you want to customize UXsim’s internal logic.

You can also use `pip` to install the GitHub version:

```
pip install -U -e git+https://github.com/toruseo/uxsim@main#egg=uxsim
```

Or any other (development) branch on this repo or your own fork:

```
pip install -U -e git+https://github.com/YOUR_FORK/uxsim@YOUR_BRANCH#egg=uxsim
```

Then import the module using:
```python
Expand Down
23 changes: 23 additions & 0 deletions demos_and_examples/test_examples.py
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}"

0 comments on commit 427560b

Please sign in to comment.