Skip to content

Commit

Permalink
fix subpackage access, drop top-level 'blocks' section, sort var attr…
Browse files Browse the repository at this point in the history
…s, drop unnecessary attrs
  • Loading branch information
wpbonelli committed Jan 26, 2025
1 parent d9a4212 commit 29d5055
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 169 deletions.
42 changes: 20 additions & 22 deletions autotest/test_dfn.py
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
Loading

0 comments on commit 29d5055

Please sign in to comment.