Skip to content

Commit e90e92e

Browse files
committed
fix(dfn): restore dfn module and tests
1 parent aa99c56 commit e90e92e

5 files changed

Lines changed: 805 additions & 0 deletions

File tree

autotest/test_dfn.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
from modflow_devtools.dfn import Dfn, get_dfns
6+
from modflow_devtools.dfn2toml import convert
7+
from modflow_devtools.markers import requires_pkg
8+
9+
PROJ_ROOT = Path(__file__).parents[1]
10+
DFN_DIR = PROJ_ROOT / "autotest" / "temp" / "dfn"
11+
TOML_DIR = DFN_DIR / "toml"
12+
VERSIONS = {1: DFN_DIR, 2: TOML_DIR}
13+
MF6_OWNER = "MODFLOW-ORG"
14+
MF6_REPO = "modflow6"
15+
MF6_REF = "develop"
16+
17+
18+
def pytest_generate_tests(metafunc):
19+
if "dfn_name" in metafunc.fixturenames:
20+
if not any(DFN_DIR.glob("*.dfn")):
21+
get_dfns(MF6_OWNER, MF6_REPO, MF6_REF, DFN_DIR, verbose=True)
22+
dfn_names = [
23+
dfn.stem for dfn in DFN_DIR.glob("*.dfn") if dfn.stem not in ["common", "flopy"]
24+
]
25+
metafunc.parametrize("dfn_name", dfn_names, ids=dfn_names)
26+
27+
if "toml_name" in metafunc.fixturenames:
28+
# Only convert if TOML files don't exist yet (avoid repeated conversions)
29+
dfn_paths = [p for p in DFN_DIR.glob("*.dfn") if p.stem not in ["common", "flopy"]]
30+
if not TOML_DIR.exists() or not all(
31+
(TOML_DIR / f"{dfn.stem}.toml").is_file() for dfn in dfn_paths
32+
):
33+
convert(DFN_DIR, TOML_DIR)
34+
# Verify all expected TOML files were created
35+
assert all((TOML_DIR / f"{dfn.stem}.toml").is_file() for dfn in dfn_paths)
36+
toml_names = [toml.stem for toml in TOML_DIR.glob("*.toml")]
37+
metafunc.parametrize("toml_name", toml_names, ids=toml_names)
38+
39+
40+
@requires_pkg("boltons")
41+
def test_load_v1(dfn_name):
42+
with (
43+
(DFN_DIR / "common.dfn").open() as common_file,
44+
(DFN_DIR / f"{dfn_name}.dfn").open() as dfn_file,
45+
):
46+
common, _ = Dfn._load_v1_flat(common_file)
47+
dfn = Dfn.load(dfn_file, name=dfn_name, common=common)
48+
assert any(dfn)
49+
50+
51+
@requires_pkg("boltons")
52+
def test_load_v2(toml_name):
53+
with (TOML_DIR / f"{toml_name}.toml").open(mode="rb") as toml_file:
54+
toml = Dfn.load(toml_file, name=toml_name, version=2)
55+
assert any(toml)
56+
57+
58+
@requires_pkg("boltons")
59+
@pytest.mark.parametrize("version", list(VERSIONS.keys()))
60+
def test_load_all(version):
61+
dfns = Dfn.load_all(VERSIONS[version], version=version)
62+
assert any(dfns)

0 commit comments

Comments
 (0)