Skip to content

Commit

Permalink
test(framework): fix binary target selection, require known targets (M…
Browse files Browse the repository at this point in the history
…ODFLOW-USGS#1530)

* remove util function for resolving executable paths
* previously framework could test an erroneous mf6
* locate programs explicitly, don't discover on the PATH
* require all target binaries to be registered with framework
  • Loading branch information
wpbonelli authored Dec 29, 2023
1 parent 2ae4129 commit 6bb6eb0
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions autotest/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,18 +587,6 @@ def _compare_budget_files(self, extension, fpth0, fpth1) -> bool:
fcmp.close()
return success

def _try_resolve(
self,
target: Union[str, os.PathLike],
default: Optional[Union[str, os.PathLike]] = None,
) -> Optional[Path]:
if not target:
return None
tgt = shutil.which(target)
if tgt:
return Path(tgt)
return self.targets.as_dict().get(target, default)

# public

def setup(self, src, dst):
Expand Down Expand Up @@ -626,15 +614,15 @@ def setup(self, src, dst):
def run_sim_or_model(
self,
workspace: Union[str, os.PathLike],
target: Union[str, os.PathLike] = "mf6",
target: Union[str, os.PathLike],
xfail: bool = False,
) -> Tuple[bool, List[str]]:
"""
Run a simulation or model with FloPy.
workspace : str or path-like
The simulation or model workspace
exe : str or path-like
target : str or path-like
The target executable to use
xfail : bool
Whether to expect failure
Expand All @@ -644,9 +632,12 @@ def run_sim_or_model(
workspace = Path(workspace).expanduser().absolute()
assert workspace.is_dir(), f"Workspace not found: {workspace}"

# make sure executable exists
target = self._try_resolve(target)
assert target, f"Target executable not found: {target}"
# make sure executable exists and framework knows about it
tgt = Path(shutil.which(target))
assert tgt.is_file(), f"Target executable not found: {target}"
assert (
tgt in self.targets.as_dict().values()
), f"Targets must be explicitly registered with the test framework"

if self.verbose:
print(f"Running {target} in {workspace}")
Expand Down Expand Up @@ -809,8 +800,18 @@ def run(self):

# run models/simulations
for i, sim_or_model in enumerate(self.sims):
tgts = self.targets.as_dict()
workspace = get_workspace(sim_or_model)
target = self._try_resolve(sim_or_model.exe_name, self.targets.mf6)
exe_path = (
Path(sim_or_model.exe_name)
if sim_or_model.exe_name
else tgts["mf6"]
)
target = (
exe_path
if exe_path in tgts.values()
else tgts.get(exe_path.stem, tgts["mf6"])
)
xfail = self.xfail[i]
success, buff = self.run_sim_or_model(workspace, target, xfail)
self.buffs[i] = buff # store model output for assertions later
Expand Down Expand Up @@ -859,7 +860,9 @@ def run(self):
workspace = self.workspace / self.compare
success, _ = self.run_sim_or_model(
workspace,
self.targets.get(self.compare, self.targets.mf6),
self.targets.as_dict().get(
self.compare, self.targets.mf6
),
)
assert success, f"Comparison model failed: {workspace}"

Expand Down

0 comments on commit 6bb6eb0

Please sign in to comment.