diff --git a/docs/examples/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py b/docs/examples/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py index 5ff8f65..ce58d9d 100644 --- a/docs/examples/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py +++ b/docs/examples/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py @@ -33,7 +33,7 @@ # First we store the absolute directory of this script, # then two directories above this,with the directory # 'data' appended -PWD = Path(__file__).parent.absolute() +PWD = Path(__file__).parent.resolve() DPATH = PWD.parent.parent / "data" # 3: Give an identifying name for the refinement, similar diff --git a/tests/conftest.py b/tests/conftest.py index e3b6313..cf27678 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,27 @@ import json + +# tests/conftest.py +import shutil from pathlib import Path import pytest +PROJECT_ROOT = Path(__file__).resolve().parents[1] +EXAMPLES_ROOT = PROJECT_ROOT / "docs" / "examples" + + +@pytest.fixture(scope="session") +def tmp_examples(tmp_path_factory): + """Copy the entire examples/ tree into a temp directory once per + test session. + + Returns the path to that copy. + """ + tmpdir = tmp_path_factory.mktemp("examples") + tmp_examples = tmpdir / "examples" + shutil.copytree(EXAMPLES_ROOT, tmp_examples) + yield tmp_examples + @pytest.fixture def user_filesystem(tmp_path): diff --git a/tests/test_examples.py b/tests/test_examples.py new file mode 100644 index 0000000..00907fd --- /dev/null +++ b/tests/test_examples.py @@ -0,0 +1,8 @@ +import runpy + + +def test_all_examples(tmp_examples): + scripts = list(tmp_examples.rglob("**/solutions/diffpy-cmi/*.py")) + for script_path in scripts: + print(f"Testing {script_path.relative_to(tmp_examples)}") + runpy.run_path(str(script_path), run_name="__main__")