Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: require dev exes, warn/skip if download/rebuilt not found #1460

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: require dev exes, warn/skip if download/rebuilt not found
  • Loading branch information
wpbonelli committed Nov 21, 2023
commit 7d7e102418b61460741ba316a1536fcfa1346f3e
81 changes: 50 additions & 31 deletions autotest/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import platform
import sys
from pathlib import Path
from os import PathLike
from typing import Dict, Optional
from pathlib import Path
from typing import Optional
from warnings import warn

import pytest
from modflow_devtools.executables import Executables, get_suffixes
Expand Down Expand Up @@ -59,39 +60,57 @@ def targets(bin_path) -> Executables:
exe_ext, lib_ext = get_suffixes(sys.platform)
dl_bin = bin_path / "downloaded"
rb_bin = bin_path / "rebuilt"
tgts = dict()
targets = dict()

# local development binaries
development = [
("mf6", bin_path / f"mf6{exe_ext}"),
("libmf6", bin_path / f"libmf6{lib_ext}"),
("mf5to6", bin_path / f"mf5to6{exe_ext}"),
("zbud6", bin_path / f"zbud6{exe_ext}"),
]

# downloaded executables
tgts["mf2000"] = dl_bin / f"mf2000{exe_ext}"
tgts["mf2005"] = dl_bin / f"mf2005dbl{exe_ext}"
tgts["mfnwt"] = dl_bin / f"mfnwtdbl{exe_ext}"
tgts["mfusg"] = dl_bin / f"mfusgdbl{exe_ext}"
tgts["mflgr"] = dl_bin / f"mflgrdbl{exe_ext}"
tgts["mf2005s"] = dl_bin / f"mf2005{exe_ext}"
tgts["mt3dms"] = dl_bin / f"mt3dms{exe_ext}"
tgts["crt"] = dl_bin / f"crt{exe_ext}"
tgts["gridgen"] = dl_bin / f"gridgen{exe_ext}"
tgts["mp6"] = dl_bin / f"mp6{exe_ext}"
tgts["mp7"] = dl_bin / f"mp7{exe_ext}"
tgts["swtv4"] = dl_bin / f"swtv4{exe_ext}"
tgts["sutra"] = dl_bin / f"sutra{exe_ext}"
tgts["triangle"] = dl_bin / f"triangle{exe_ext}"
tgts["vs2dt"] = dl_bin / f"vs2dt{exe_ext}"
tgts["zonbudusg"] = dl_bin / f"zonbudusg{exe_ext}"
downloaded = [
("mf2000", dl_bin / f"mf2000{exe_ext}"),
("mf2005", dl_bin / f"mf2005dbl{exe_ext}"),
("mfnwt", dl_bin / f"mfnwtdbl{exe_ext}"),
("mfusg", dl_bin / f"mfusgdbl{exe_ext}"),
("mflgr", dl_bin / f"mflgrdbl{exe_ext}"),
("mf2005s", dl_bin / f"mf2005{exe_ext}"),
("mt3dms", dl_bin / f"mt3dms{exe_ext}"),
("crt", dl_bin / f"crt{exe_ext}"),
("gridgen", dl_bin / f"gridgen{exe_ext}"),
("mp6", dl_bin / f"mp6{exe_ext}"),
("mp7", dl_bin / f"mp7{exe_ext}"),
("swtv4", dl_bin / f"swtv4{exe_ext}"),
("sutra", dl_bin / f"sutra{exe_ext}"),
("triangle", dl_bin / f"triangle{exe_ext}"),
("vs2dt", dl_bin / f"vs2dt{exe_ext}"),
("zonbudusg", dl_bin / f"zonbudusg{exe_ext}"),
]

# binaries rebuilt from last release
tgts["mf6_regression"] = rb_bin / f"mf6{exe_ext}"
tgts["libmf6_regression"] = rb_bin / f"libmf6{lib_ext}"
tgts["mf5to6_regression"] = rb_bin / f"mf5to6{exe_ext}"
tgts["zbud6_regression"] = rb_bin / f"zbud6{exe_ext}"

# local development binaries
tgts["mf6"] = bin_path / f"mf6{exe_ext}"
tgts["libmf6"] = bin_path / f"libmf6{lib_ext}"
tgts["mf5to6"] = bin_path / f"mf5to6{exe_ext}"
tgts["zbud6"] = bin_path / f"zbud6{exe_ext}"

return Executables(**tgts)
rebuilt = [
("mf6_regression", rb_bin / f"mf6{exe_ext}"),
("libmf6_regression", rb_bin / f"libmf6{lib_ext}"),
("mf5to6_regression", rb_bin / f"mf5to6{exe_ext}"),
("zbud6_regression", rb_bin / f"zbud6{exe_ext}"),
]

# require development binaries
for k, v in development:
assert v.is_file(), f"Couldn't find binary '{k}' expected at: {v}"
targets[k] = v

# downloaded/rebuilt binaries are optional
for k, v in downloaded + rebuilt:
if v.is_file():
targets[k] = v
else:
warn(f"Couldn't find binary '{k}' expected at: {v}")

return Executables(**targets)


@pytest.fixture
Expand Down
116 changes: 66 additions & 50 deletions autotest/test_gwt_mt3dms_p01.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
"""

import os
from pathlib import Path
from typing import Tuple

import flopy
import numpy as np
import pytest

testgroup = "mt3dms_p01"

Expand Down Expand Up @@ -383,7 +386,6 @@ def p01mf6(
theta_immobile = prsity2
porosity_immobile = theta_immobile / volfrac_immobile
porosity_mobile = prsity / volfrac_mobile


first_order_decay = True
if zero_order_decay:
Expand Down Expand Up @@ -470,6 +472,20 @@ def p01mf6(
return sim, conc


def get_binaries(targets) -> Tuple[Path, Path]:
mf6 = targets["mf6"]
mf2005 = targets.get("mf2005s")
mt3dms = targets.get("mt3dms")

assert mf6, f"Couldn't find binary 'mf6'"
if not mf2005:
pytest.skip(f"Couldn't find binary 'mf2005s'")
if not mt3dms:
pytest.skip(f"Couldn't find binary 'mt3dms'")

return mf6, mf2005, mt3dms


def test_mt3dmsp01a(function_tmpdir, targets):
longitudinal_dispersivity = 0.0
retardation = 1.0
Expand All @@ -478,8 +494,10 @@ def test_mt3dmsp01a(function_tmpdir, targets):
zeta = None
prsity2 = None

mf6 = targets["mf6"]
mf6_ws = str(function_tmpdir / (testgroup + "a"))
mf6, mf2005, mt3dms = get_binaries(targets)
mf6_ws = function_tmpdir / f"{testgroup}a"
mt3d_ws = mf6_ws / "mt3d"

sim, conc_mf6 = p01mf6(
mf6_ws,
longitudinal_dispersivity,
Expand All @@ -491,9 +509,6 @@ def test_mt3dmsp01a(function_tmpdir, targets):
exe=mf6,
)

mf2005 = targets["mf2005s"]
mt3dms = targets["mt3dms"]
mt3d_ws = os.path.join(mf6_ws, "mt3d")
mf, mt, conc_mt3d, cvt, mvt = p01mt3d(
mt3d_ws,
longitudinal_dispersivity,
Expand All @@ -506,8 +521,9 @@ def test_mt3dmsp01a(function_tmpdir, targets):
mt3dms=mt3dms,
)

msg = f"concentrations not equal {conc_mt3d} {conc_mf6}"
assert np.allclose(conc_mt3d, conc_mf6, atol=1e-4), msg
assert np.allclose(
conc_mt3d, conc_mf6, atol=1e-4
), f"concentrations not equal {conc_mt3d} {conc_mf6}"

# load transport budget
# budget text:
Expand Down Expand Up @@ -543,8 +559,10 @@ def test_mt3dmsp01b(function_tmpdir, targets):
zeta = None
prsity2 = None

mf6 = targets["mf6"]
mf6_ws = str(function_tmpdir / (testgroup + "b"))
mf6, mf2005, mt3dms = get_binaries(targets)
mf6_ws = function_tmpdir / f"{testgroup}b"
mt3d_ws = mf6_ws / "mt3d"

sim, conc_mf6 = p01mf6(
mf6_ws,
longitudinal_dispersivity,
Expand All @@ -556,9 +574,6 @@ def test_mt3dmsp01b(function_tmpdir, targets):
exe=mf6,
)

mf2005 = targets["mf2005s"]
mt3dms = targets["mt3dms"]
mt3d_ws = os.path.join(mf6_ws, "mt3d")
mf, mt, conc_mt3d, cvt, mvt = p01mt3d(
mt3d_ws,
longitudinal_dispersivity,
Expand All @@ -571,8 +586,9 @@ def test_mt3dmsp01b(function_tmpdir, targets):
mt3dms=mt3dms,
)

msg = f"concentrations not equal {conc_mt3d} {conc_mf6}"
assert np.allclose(conc_mt3d, conc_mf6, atol=1e-4), msg
assert np.allclose(
conc_mt3d, conc_mf6, atol=1e-4
), f"concentrations not equal {conc_mt3d} {conc_mf6}"


def test_mt3dmsp01c(function_tmpdir, targets):
Expand All @@ -583,8 +599,10 @@ def test_mt3dmsp01c(function_tmpdir, targets):
zeta = None
prsity2 = None

mf6 = targets["mf6"]
mf6_ws = str(function_tmpdir / (testgroup + "c"))
mf6, mf2005, mt3dms = get_binaries(targets)
mf6_ws = function_tmpdir / f"{testgroup}c"
mt3d_ws = mf6_ws / "mt3d"

sim, conc_mf6 = p01mf6(
mf6_ws,
longitudinal_dispersivity,
Expand All @@ -596,9 +614,6 @@ def test_mt3dmsp01c(function_tmpdir, targets):
exe=mf6,
)

mf2005 = targets["mf2005s"]
mt3dms = targets["mt3dms"]
mt3d_ws = os.path.join(mf6_ws, "mt3d")
mf, mt, conc_mt3d, cvt, mvt = p01mt3d(
mt3d_ws,
longitudinal_dispersivity,
Expand All @@ -611,8 +626,9 @@ def test_mt3dmsp01c(function_tmpdir, targets):
mt3dms=mt3dms,
)

msg = f"concentrations not equal {conc_mt3d} {conc_mf6}"
assert np.allclose(conc_mt3d, conc_mf6, atol=1e-4), msg
assert np.allclose(
conc_mt3d, conc_mf6, atol=1e-4
), f"concentrations not equal {conc_mt3d} {conc_mf6}"


def test_mt3dmsp01d(function_tmpdir, targets):
Expand All @@ -623,8 +639,10 @@ def test_mt3dmsp01d(function_tmpdir, targets):
zeta = None
prsity2 = None

mf6 = targets["mf6"]
mf6_ws = str(function_tmpdir / (testgroup + "d"))
mf6, mf2005, mt3dms = get_binaries(targets)
mf6_ws = function_tmpdir / f"{testgroup}d"
mt3d_ws = mf6_ws / "mt3d"

sim, conc_mf6 = p01mf6(
mf6_ws,
longitudinal_dispersivity,
Expand All @@ -636,9 +654,6 @@ def test_mt3dmsp01d(function_tmpdir, targets):
exe=mf6,
)

mf2005 = targets["mf2005s"]
mt3dms = targets["mt3dms"]
mt3d_ws = os.path.join(mf6_ws, "mt3d")
mf, mt, conc_mt3d, cvt, mvt = p01mt3d(
mt3d_ws,
longitudinal_dispersivity,
Expand All @@ -651,8 +666,9 @@ def test_mt3dmsp01d(function_tmpdir, targets):
mt3dms=mt3dms,
)

msg = f"concentrations not equal {conc_mt3d} {conc_mf6}"
assert np.allclose(conc_mt3d, conc_mf6, atol=1e-4), msg
assert np.allclose(
conc_mt3d, conc_mf6, atol=1e-4
), f"concentrations not equal {conc_mt3d} {conc_mf6}"


def test_mt3dmsp01e(function_tmpdir, targets):
Expand All @@ -663,8 +679,10 @@ def test_mt3dmsp01e(function_tmpdir, targets):
zeta = 0.1
prsity2 = 0.05

mf6 = targets["mf6"]
mf6_ws = str(function_tmpdir / (testgroup + "e"))
mf6, mf2005, mt3dms = get_binaries(targets)
mf6_ws = function_tmpdir / f"{testgroup}e"
mt3d_ws = mf6_ws / "mt3d"

sim, conc_mf6 = p01mf6(
mf6_ws,
longitudinal_dispersivity,
Expand All @@ -676,9 +694,6 @@ def test_mt3dmsp01e(function_tmpdir, targets):
exe=mf6,
)

mf2005 = targets["mf2005s"]
mt3dms = targets["mt3dms"]
mt3d_ws = os.path.join(mf6_ws, "mt3d")
mf, mt, conc_mt3d, cvt, mvt = p01mt3d(
mt3d_ws,
longitudinal_dispersivity,
Expand All @@ -691,8 +706,9 @@ def test_mt3dmsp01e(function_tmpdir, targets):
mt3dms=mt3dms,
)

msg = f"concentrations not equal {conc_mt3d} {conc_mf6}"
assert np.allclose(conc_mt3d, conc_mf6, atol=1e-1), msg
assert np.allclose(
conc_mt3d, conc_mf6, atol=1e-1
), f"concentrations not equal {conc_mt3d} {conc_mf6}"


def test_mt3dmsp01f(function_tmpdir, targets):
Expand All @@ -703,8 +719,10 @@ def test_mt3dmsp01f(function_tmpdir, targets):
zeta = 0.1
prsity2 = 0.05

mf6 = targets["mf6"]
mf6_ws = str(function_tmpdir / (testgroup + "f"))
mf6, mf2005, mt3dms = get_binaries(targets)
mf6_ws = function_tmpdir / f"{testgroup}f"
mt3d_ws = mf6_ws / "mt3d"

sim, conc_mf6 = p01mf6(
mf6_ws,
longitudinal_dispersivity,
Expand All @@ -717,9 +735,6 @@ def test_mt3dmsp01f(function_tmpdir, targets):
exe=mf6,
)

mf2005 = targets["mf2005s"]
mt3dms = targets["mt3dms"]
mt3d_ws = os.path.join(mf6_ws, "mt3d")
mf, mt, conc_mt3d, cvt, mvt = p01mt3d(
mt3d_ws,
longitudinal_dispersivity,
Expand All @@ -732,8 +747,9 @@ def test_mt3dmsp01f(function_tmpdir, targets):
mt3dms=mt3dms,
)

msg = f"concentrations not equal {conc_mt3d} {conc_mf6}"
assert np.allclose(conc_mt3d, conc_mf6, atol=1e-1), msg
assert np.allclose(
conc_mt3d, conc_mf6, atol=1e-1
), f"concentrations not equal {conc_mt3d} {conc_mf6}"


def test_mt3dmsp01g(function_tmpdir, targets):
Expand All @@ -744,8 +760,10 @@ def test_mt3dmsp01g(function_tmpdir, targets):
zeta = None
prsity2 = None

mf6 = targets["mf6"]
mf6_ws = str(function_tmpdir / (testgroup + "g"))
mf6, mf2005, mt3dms = get_binaries(targets)
mf6_ws = function_tmpdir / f"{testgroup}g"
mt3d_ws = mf6_ws / "mt3d"

sim, conc_mf6 = p01mf6(
mf6_ws,
longitudinal_dispersivity,
Expand All @@ -758,9 +776,6 @@ def test_mt3dmsp01g(function_tmpdir, targets):
exe=mf6,
)

mf2005 = targets["mf2005s"]
mt3dms = targets["mt3dms"]
mt3d_ws = os.path.join(mf6_ws, "mt3d")
mf, mt, conc_mt3d, cvt, mvt = p01mt3d(
mt3d_ws,
longitudinal_dispersivity,
Expand All @@ -775,5 +790,6 @@ def test_mt3dmsp01g(function_tmpdir, targets):
mt3dms=mt3dms,
)

msg = f"concentrations not equal {conc_mt3d} {conc_mf6}"
assert np.allclose(conc_mt3d, conc_mf6, atol=1.0e-4), msg
assert np.allclose(
conc_mt3d, conc_mf6, atol=1.0e-4
), f"concentrations not equal {conc_mt3d} {conc_mf6}"