forked from MODFLOW-USGS/modflow-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
79 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,63 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from modflow_devtools.dfn import Dfn, get_dfns | ||
from modflow_devtools.dfn2toml import convert | ||
from modflow_devtools.markers import requires_pkg | ||
|
||
PROJ_ROOT = Path(__file__).parents[1] | ||
DFN_PATH = PROJ_ROOT / "autotest" / "temp" / "dfn" | ||
TOML_PATH = DFN_PATH / "toml" | ||
DFN_DIR = PROJ_ROOT / "autotest" / "temp" / "dfn" | ||
TOML_DIR = DFN_DIR / "toml" | ||
VERSIONS = {1: DFN_DIR, 2: TOML_DIR} | ||
DFN_PATHS = list(DFN_DIR.glob("*.dfn")) | ||
MF6_OWNER = "MODFLOW-USGS" | ||
MF6_REPO = "modflow6" | ||
MF6_REF = "develop" | ||
|
||
|
||
def pytest_generate_tests(metafunc): | ||
if "dfn_name" in metafunc.fixturenames: | ||
if not any(DFN_PATH.glob("*.dfn")): | ||
get_dfns(MF6_OWNER, MF6_REPO, MF6_REF, DFN_PATH, verbose=True) | ||
if not any(DFN_DIR.glob("*.dfn")): | ||
get_dfns(MF6_OWNER, MF6_REPO, MF6_REF, DFN_DIR, verbose=True) | ||
dfn_names = [ | ||
dfn.stem | ||
for dfn in DFN_PATH.glob("*.dfn") | ||
for dfn in DFN_DIR.glob("*.dfn") | ||
if dfn.stem not in ["common", "flopy"] | ||
] | ||
metafunc.parametrize("dfn_name", dfn_names, ids=dfn_names) | ||
|
||
if "toml_name" in metafunc.fixturenames: | ||
convert(DFN_PATH, TOML_PATH) | ||
dfns = list(DFN_PATH.glob("*.dfn")) | ||
convert(DFN_DIR, TOML_DIR) | ||
assert all( | ||
(TOML_PATH / f"{dfn.stem}.toml").is_file() | ||
for dfn in dfns | ||
(TOML_DIR / f"{dfn.stem}.toml").is_file() | ||
for dfn in DFN_PATHS | ||
if "common" not in dfn.stem | ||
) | ||
toml_names = [toml.stem for toml in TOML_PATH.glob("*.toml")] | ||
toml_names = [toml.stem for toml in TOML_DIR.glob("*.toml")] | ||
metafunc.parametrize("toml_name", toml_names, ids=toml_names) | ||
|
||
|
||
@requires_pkg("boltons") | ||
def test_load_v1(dfn_name): | ||
with ( | ||
(DFN_PATH / "common.dfn").open() as common_file, | ||
(DFN_PATH / f"{dfn_name}.dfn").open() as dfn_file, | ||
(DFN_DIR / "common.dfn").open() as common_file, | ||
(DFN_DIR / f"{dfn_name}.dfn").open() as dfn_file, | ||
): | ||
common, _ = Dfn._load_v1_flat(common_file) | ||
dfn = Dfn.load(dfn_file, name=dfn_name, common=common) | ||
assert any(dfn) | ||
|
||
|
||
@requires_pkg("boltons") | ||
def test_load_all_v1(): | ||
dfns = Dfn.load_all(DFN_PATH) | ||
assert any(dfns) | ||
|
||
|
||
@requires_pkg("boltons") | ||
def test_load_v2(toml_name): | ||
with (TOML_PATH / f"{toml_name}.toml").open(mode="rb") as toml_file: | ||
with (TOML_DIR / f"{toml_name}.toml").open(mode="rb") as toml_file: | ||
toml = Dfn.load(toml_file, name=toml_name, version=2) | ||
assert any(toml) | ||
|
||
|
||
@requires_pkg("boltons") | ||
def test_load_all_v2(): | ||
toml = Dfn.load_all(TOML_PATH, version=2) | ||
assert any(toml) | ||
@pytest.mark.parametrize("version", list(VERSIONS.keys())) | ||
def test_load_all(version): | ||
dfns = Dfn.load_all(VERSIONS[version], version=version) | ||
assert len(dfns) == len(DFN_PATHS) - 1 # ignore common.dfn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters