Skip to content

Commit b4d20a5

Browse files
committed
better dfn access pattern for tests
1 parent 239b045 commit b4d20a5

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

test/conftest.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import os
12
from pathlib import Path
23
from platform import system
34

45
import pytest
6+
from modflow_devtools.download import download_and_unzip
57
from modflow_devtools.misc import is_in_ci
68

79
pytest_plugins = ["modflow_devtools.fixtures"]
@@ -12,6 +14,44 @@
1214
EXCLUDED_EXAMPLES = []
1315

1416

17+
def _get_dfn_path(tmp_path_factory):
18+
"""Get path to MF6 DFN files, checking local repos or downloading if needed."""
19+
20+
# Check REPOS_PATH environment variable (modflow-devtools convention)
21+
repos_path = os.environ.get("REPOS_PATH")
22+
if repos_path:
23+
dfn_path = Path(repos_path) / "modflow6" / "doc" / "mf6io" / "mf6ivar" / "dfn"
24+
if dfn_path.exists():
25+
return dfn_path
26+
27+
# Check if modflow6 repo exists as sibling to this project
28+
sibling_path = PROJ_ROOT_PATH.parent / "modflow6" / "doc" / "mf6io" / "mf6ivar" / "dfn"
29+
if sibling_path.exists():
30+
return sibling_path
31+
32+
# Download from GitHub if not found locally
33+
tmp_dir = tmp_path_factory.mktemp("mf6_dfn")
34+
url = "https://github.com/MODFLOW-USGS/modflow6/archive/refs/heads/develop.zip"
35+
download_and_unzip(url, tmp_dir, verbose=False)
36+
37+
# Find the extracted directory (will have a prefix like 'modflow6-develop')
38+
extracted_dirs = [d for d in tmp_dir.iterdir() if d.is_dir() and d.name.startswith("modflow6")]
39+
if not extracted_dirs:
40+
pytest.fail(f"Failed to extract modflow6 from {url}")
41+
42+
dfn_path = extracted_dirs[0] / "doc" / "mf6io" / "mf6ivar" / "dfn"
43+
if not dfn_path.exists():
44+
pytest.fail("DFN directory not found in downloaded modflow6 repo")
45+
46+
return dfn_path
47+
48+
49+
@pytest.fixture(scope="session")
50+
def dfn_path(tmp_path_factory):
51+
"""Get the path to MF6 DFN files."""
52+
return _get_dfn_path(tmp_path_factory)
53+
54+
1555
@pytest.fixture(scope="session", autouse=True)
1656
def patch_macos_ci_matplotlib():
1757
# use noninteractive matplotlib backend if in Mac OS CI to avoid pytest-xdist node failure

test/test_mf6_reader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,11 @@ def test_parse_gwf_wel_file(model_workspace):
288288

289289

290290
@pytest.mark.parametrize("model_workspace", ["mf6/example/ex-gwf-csub-p01"], indirect=True)
291-
def test_transform_gwf_ic_file(model_workspace):
291+
def test_transform_gwf_ic_file(model_workspace, dfn_path):
292292
"""Test transforming a parsed GWF IC file into structured data."""
293293

294294
# Load the DFN for IC
295-
dfns = load_flat("../modflow-devtools/autotest/temp/dfn/toml")
295+
dfns = load_flat(dfn_path)
296296
ic_dfn = dfns["gwf-ic"]
297297

298298
# Find the IC file
@@ -317,11 +317,11 @@ def test_transform_gwf_ic_file(model_workspace):
317317

318318

319319
@pytest.mark.parametrize("model_workspace", ["mf6/example/ex-gwf-bcf2ss-p01a"], indirect=True)
320-
def test_transform_gwf_wel_file(model_workspace):
320+
def test_transform_gwf_wel_file(model_workspace, dfn_path):
321321
"""Test transforming a parsed GWF WEL file into structured data."""
322322

323323
# Load the DFN for WEL
324-
dfns = load_flat("../modflow-devtools/autotest/temp/dfn/toml")
324+
dfns = load_flat(dfn_path)
325325
wel_dfn = dfns["gwf-wel"]
326326

327327
# Find the WEL file

0 commit comments

Comments
 (0)