|
3 | 3 | from os import environ |
4 | 4 | from pathlib import Path |
5 | 5 | from pprint import pprint |
| 6 | +from random import shuffle |
6 | 7 |
|
7 | 8 | import pytest |
8 | 9 |
|
9 | 10 | from modflow_devtools.markers import no_parallel |
| 11 | +from modflow_devtools.misc import run_cmd |
10 | 12 |
|
11 | 13 |
|
12 | 14 | # OS-specific extensions |
@@ -175,20 +177,34 @@ def test_examples(dist_dir_path, full): |
175 | 177 | if not full: |
176 | 178 | pytest.skip(reason="examples not included in minimal distribution") |
177 | 179 |
|
| 180 | + # check examples directory |
178 | 181 | examples_path = dist_dir_path / "examples" |
179 | 182 | assert examples_path.is_dir() |
180 | | - assert (examples_path / f"runall{_scext}").is_file() |
| 183 | + |
| 184 | + # print examples found |
181 | 185 | example_paths = [ |
182 | 186 | p for p in examples_path.glob("*") if p.is_dir() and p.stem.startswith("ex") |
183 | 187 | ] |
| 188 | + assert any(example_paths) |
184 | 189 | print(f"{len(example_paths)} example models found:") |
185 | 190 | pprint(example_paths) |
186 | | - for p in example_paths: |
187 | | - script_path = p / f"run{_scext}" |
188 | | - if not script_path.is_file(): |
189 | | - continue |
190 | | - pprint(subprocess.check_output([str(script_path)], cwd=p).decode().split()) |
191 | | - break |
| 191 | + |
| 192 | + # pick some examples at random to test run individually |
| 193 | + n = 3 |
| 194 | + shuffle(example_paths) |
| 195 | + script_paths = [next(iter(p.rglob(f"*run{_scext}"))) for p in example_paths[:n]] |
| 196 | + print(f"Testing {n} randomly selected example model scripts:") |
| 197 | + pprint(script_paths) |
| 198 | + for script_path in script_paths: |
| 199 | + out, err, ret = run_cmd(str(script_path), cwd=script_path.parent) |
| 200 | + assert not ret, out + err |
| 201 | + |
| 202 | + # check comprehensive examples script and give it a test run |
| 203 | + script_path = examples_path / f"runall{_scext}" |
| 204 | + print(f"Testing comprehensive examples script: {script_path}") |
| 205 | + assert script_path.is_file() |
| 206 | + out, err, ret = run_cmd(str(script_path), cwd=script_path.parent) |
| 207 | + assert not ret, out + err |
192 | 208 |
|
193 | 209 |
|
194 | 210 | @no_parallel |
|
0 commit comments