Skip to content

Commit c58bb59

Browse files
committed
simon template for examples testing
1 parent 6167dd9 commit c58bb59

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

docs/examples/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# First we store the absolute directory of this script,
3434
# then two directories above this,with the directory
3535
# 'data' appended
36-
PWD = Path(__file__).parent.absolute()
36+
PWD = Path(__file__).parent.resolve()
3737
DPATH = PWD.parent.parent / "data"
3838

3939
# 3: Give an identifying name for the refinement, similar

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
import json
2+
3+
# tests/conftest.py
4+
import shutil
25
from pathlib import Path
36

47
import pytest
58

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

726
@pytest.fixture
827
def user_filesystem(tmp_path):

tests/test_examples.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import runpy
2+
3+
4+
def test_all_examples(tmp_examples):
5+
scripts = list(tmp_examples.rglob("**/solutions/diffpy-cmi/*.py"))
6+
for script_path in scripts:
7+
print(f"Testing {script_path.relative_to(tmp_examples)}")
8+
runpy.run_path(str(script_path), run_name="__main__")

0 commit comments

Comments
 (0)