Skip to content

Commit

Permalink
test(release): fix distribution example script check (#1841)
Browse files Browse the repository at this point in the history
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-USGS/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.
  • Loading branch information
wpbonelli authored May 22, 2024
1 parent 0c9953f commit d36faa6
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions distribution/check_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d36faa6

Please sign in to comment.