Skip to content

Commit 8dc85e5

Browse files
committed
mv temp dir to validators, create validators dir
1 parent d73618b commit 8dc85e5

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

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="session")
269
def example_cases(tmp_path_factory):

tests/validate_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)