Skip to content

Commit d36faa6

Browse files
authored
test(release): fix distribution example script check (#1841)
Remove break statement likely leftover from development/debugging, which caused only the first example model to get a test run. This is why the examples script issue addressed by MODFLOW-ORG/modflow-devtools#156, where models were written to runall.[sh/bat] in an order which did not respect flow model dependencies, was not caught before. After this PR, the runall.[sh/bat] script will be tested, as well as 3 of the separate example scripts picked at random.
1 parent 0c9953f commit d36faa6

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

distribution/check_dist.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from os import environ
44
from pathlib import Path
55
from pprint import pprint
6+
from random import shuffle
67

78
import pytest
89

910
from modflow_devtools.markers import no_parallel
11+
from modflow_devtools.misc import run_cmd
1012

1113

1214
# OS-specific extensions
@@ -175,20 +177,34 @@ def test_examples(dist_dir_path, full):
175177
if not full:
176178
pytest.skip(reason="examples not included in minimal distribution")
177179

180+
# check examples directory
178181
examples_path = dist_dir_path / "examples"
179182
assert examples_path.is_dir()
180-
assert (examples_path / f"runall{_scext}").is_file()
183+
184+
# print examples found
181185
example_paths = [
182186
p for p in examples_path.glob("*") if p.is_dir() and p.stem.startswith("ex")
183187
]
188+
assert any(example_paths)
184189
print(f"{len(example_paths)} example models found:")
185190
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
192208

193209

194210
@no_parallel

0 commit comments

Comments
 (0)