Skip to content

Commit

Permalink
reorg into codegen module, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Oct 7, 2024
1 parent 5e46278 commit 01bdab2
Show file tree
Hide file tree
Showing 13 changed files with 1,512 additions and 1,668 deletions.
24 changes: 18 additions & 6 deletions autotest/test_createpackages.py → autotest/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from modflow_devtools.misc import run_cmd

from autotest.conftest import get_project_root_path
from flopy.mf6.utils.createpackages import (
from flopy.mf6.utils.codegen.context import get_contexts
from flopy.mf6.utils.codegen.make import (
DfnName,
load_dfn,
make_all,
make_context,
make_contexts,
make_targets,
)

Expand All @@ -36,7 +38,7 @@ def test_load_dfn(dfn_name):


@pytest.mark.parametrize(
"dfn_name, n_flat, n_params", [("gwf-ic", 2, 6), ("prt-prp", 40, 22)]
"dfn_name, n_flat, n_params", [("gwf-ic", 2, 2), ("prt-prp", 40, 18)]
)
def test_make_context(dfn_name, n_flat, n_params):
with open(DFN_PATH / "common.dfn") as f:
Expand All @@ -46,13 +48,23 @@ def test_make_context(dfn_name, n_flat, n_params):
dfn_name = DfnName(*dfn_name.split("-"))
dfn = load_dfn(f, name=dfn_name)

ctx_name = dfn_name.contexts[0]
context = make_context(ctx_name, dfn, common=common)
assert len(dfn_name.contexts) == 1
context_names = get_contexts(dfn_name)
context_name = context_names[0]
context = make_context(context_name, dfn, common=common)
assert len(context_names) == 1
assert len(context.variables) == n_params
assert len(context.metadata) == n_flat + 1 # +1 for metadata


@pytest.mark.skip(reason="TODO")
@pytest.mark.parametrize("dfn_name", ["gwf-ic", "prt-prp", "gwf-nam"])
def test_make_contexts(dfn_name):
with open(DFN_PATH / "common.dfn") as f:
common = load_dfn(f)

# TODO


@pytest.mark.parametrize("dfn_name", DFN_NAMES)
def test_make_targets(dfn_name, function_tmpdir):
with open(DFN_PATH / "common.dfn") as f:
Expand All @@ -63,7 +75,7 @@ def test_make_targets(dfn_name, function_tmpdir):
dfn = load_dfn(f, name=dfn_name)

make_targets(dfn, function_tmpdir, common=common)
for ctx_name in dfn_name.contexts:
for ctx_name in get_contexts(dfn_name):
run_cmd("ruff", "format", function_tmpdir, verbose=True)
run_cmd("ruff", "check", "--fix", function_tmpdir, verbose=True)
assert (function_tmpdir / ctx_name.target).is_file()
Expand Down
Loading

0 comments on commit 01bdab2

Please sign in to comment.