Skip to content

Commit a893e67

Browse files
authored
Merge pull request #68 from cadenmyers13/run-ex-on-releases
CI: Run `test_examples.py` only on releases
2 parents 5f7f605 + ca07824 commit a893e67

File tree

6 files changed

+111
-29
lines changed

6 files changed

+111
-29
lines changed

.github/ISSUE_TEMPLATE/release_checklist.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ labels: "release"
66
assignees: ""
77
---
88

9+
### Run diffpy.cmi example scripts
10+
11+
- [ ] Manually trigger the `validate-examples.yml` workflow to run all example scripts.
12+
913
### PyPI/GitHub rc-release preparation checklist:
1014

1115
- [ ] All PRs/issues attached to the release are merged.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Validate Examples
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
validate-examples:
8+
defaults:
9+
run:
10+
shell: bash -l {0}
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v4
17+
18+
- name: Initialize miniconda
19+
uses: conda-incubator/setup-miniconda@v3
20+
with:
21+
activate-environment: test
22+
channels: conda-forge
23+
auto-update-conda: true
24+
auto-activate-base: false
25+
python-version: 3.13
26+
27+
- name: Conda config
28+
run: >-
29+
conda config --set always_yes yes
30+
--set changeps1 no
31+
32+
- name: Install dependencies
33+
run: |
34+
conda install --file requirements/conda.txt
35+
conda install --file requirements/tests.txt
36+
37+
if [ -d requirements/packs ]; then
38+
for f in requirements/packs/*.txt; do
39+
if [ -f "$f" ]; then
40+
echo "Installing dependencies from $f"
41+
conda install --file "$f"
42+
fi
43+
done
44+
fi
45+
46+
python -m pip install . --no-deps
47+
48+
- name: Run example scripts
49+
run: |
50+
set -Eeuo pipefail
51+
echo "Running example scripts"
52+
pytest validators/validate_examples.py --cov

news/run-ex-on-releases.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Add workflow to run ``examples/validate_examples.py`` manually.
4+
5+
**Changed:**
6+
7+
* Changed workflow so that ``validate_examples.py`` is ran only on manual triggers.
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

tests/conftest.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
import json
2-
import shutil
32
from pathlib import Path
43

54
import matplotlib
65
import pytest
76

8-
PROJECT_ROOT = Path(__file__).resolve().parents[1]
9-
EXAMPLES_ROOT = PROJECT_ROOT / "docs" / "examples"
10-
11-
12-
@pytest.fixture(scope="session")
13-
def tmp_examples(tmp_path_factory):
14-
"""Copy the entire examples/ tree into a temp directory once per
15-
test session.
16-
17-
Returns the path to that copy.
18-
"""
19-
tmpdir = tmp_path_factory.mktemp("examples")
20-
tmp_examples = tmpdir / "examples"
21-
shutil.copytree(EXAMPLES_ROOT, tmp_examples)
22-
yield tmp_examples
23-
247

258
@pytest.fixture(scope="function")
269
def example_cases(tmp_path_factory):

tests/test_examples.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

validators/validate_examples.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import runpy
2+
import shutil
3+
from pathlib import Path
4+
5+
import pytest
6+
7+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
8+
EXAMPLES_ROOT = PROJECT_ROOT / "docs" / "examples"
9+
10+
11+
@pytest.fixture(scope="session")
12+
def tmp_examples(tmp_path_factory):
13+
"""Copy the entire examples/ tree into a temp directory once per
14+
test session.
15+
16+
Returns the path to that copy.
17+
"""
18+
tmpdir = tmp_path_factory.mktemp("examples")
19+
tmp_examples = tmpdir / "examples"
20+
shutil.copytree(EXAMPLES_ROOT, tmp_examples)
21+
yield tmp_examples
22+
23+
24+
def test_all_examples(tmp_examples):
25+
"""Run all example scripts to ensure they execute without error."""
26+
scripts = list(tmp_examples.rglob("**/solutions/diffpy-cmi/*.py"))
27+
# sort list so that fitBulkNi.py runs first
28+
scripts.sort(key=lambda s: 0 if s.name == "fitBulkNi.py" else 1)
29+
for script in scripts:
30+
script_relative_path = script.relative_to(tmp_examples)
31+
print(f"Testing {script_relative_path}")
32+
runpy.run_path(str(script), run_name="__main__")

0 commit comments

Comments
 (0)