-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from MisterBourbaki/tests
Add a simple test suite
- Loading branch information
Showing
4 changed files
with
123 additions
and
45 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,19 @@ | ||
name: Tests the examples in README | ||
on: push | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Python | ||
uses: actions/setup-python@v4 | ||
- name: Install the latest version of rye | ||
uses: eifinger/setup-rye@v2 | ||
- name: Use UV instead of pip | ||
run: rye config --set-bool behavior.use-uv=true | ||
- name: Install dependencies | ||
run: | | ||
rye sync | ||
- name: Run pytest | ||
run: rye run pytest --cov=. tests/test_examples_readme.py |
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
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,27 @@ | ||
import pytest | ||
from pytest_examples import find_examples, CodeExample, EvalExample | ||
|
||
|
||
@pytest.mark.parametrize('example', find_examples('README.md'), ids=str) | ||
def test_docstrings(example: CodeExample, eval_example: EvalExample): | ||
"""Test all examples (automatically) found in README. | ||
Usage, in an activated virtual env: | ||
```py | ||
(.venv) pytest tests/test_examples_readme.py | ||
``` | ||
for a simple check on running the examples, and | ||
```py | ||
(.venv) pytest tests/test_examples_readme.py --update-examples | ||
``` | ||
to lint and format the code in the README. | ||
""" | ||
if eval_example.update_examples: | ||
eval_example.format(example) | ||
eval_example.lint(example) | ||
eval_example.run_print_check(example) | ||
else: | ||
eval_example.run_print_check(example) |