diff --git a/distribution/check_dist.py b/distribution/check_dist.py index 17c0198e4e2..bfd237e7e81 100644 --- a/distribution/check_dist.py +++ b/distribution/check_dist.py @@ -3,10 +3,12 @@ from os import environ from pathlib import Path from pprint import pprint +from random import shuffle import pytest from modflow_devtools.markers import no_parallel +from modflow_devtools.misc import run_cmd # OS-specific extensions @@ -175,20 +177,34 @@ def test_examples(dist_dir_path, full): if not full: pytest.skip(reason="examples not included in minimal distribution") + # check examples directory examples_path = dist_dir_path / "examples" assert examples_path.is_dir() - assert (examples_path / f"runall{_scext}").is_file() + + # print examples found example_paths = [ p for p in examples_path.glob("*") if p.is_dir() and p.stem.startswith("ex") ] + assert any(example_paths) print(f"{len(example_paths)} example models found:") pprint(example_paths) - for p in example_paths: - script_path = p / f"run{_scext}" - if not script_path.is_file(): - continue - pprint(subprocess.check_output([str(script_path)], cwd=p).decode().split()) - break + + # pick some examples at random to test run individually + n = 3 + shuffle(example_paths) + script_paths = [next(iter(p.rglob(f"*run{_scext}"))) for p in example_paths[:n]] + print(f"Testing {n} randomly selected example model scripts:") + pprint(script_paths) + for script_path in script_paths: + out, err, ret = run_cmd(str(script_path), cwd=script_path.parent) + assert not ret, out + err + + # check comprehensive examples script and give it a test run + script_path = examples_path / f"runall{_scext}" + print(f"Testing comprehensive examples script: {script_path}") + assert script_path.is_file() + out, err, ret = run_cmd(str(script_path), cwd=script_path.parent) + assert not ret, out + err @no_parallel