Skip to content

Commit

Permalink
feat: models api
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Mar 5, 2025
1 parent e64ce4c commit 3f3b217
Show file tree
Hide file tree
Showing 7 changed files with 12,651 additions and 34 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,3 @@ autotest/temp/

# uv lockfile
uv.lock

modflow_devtools/data
55 changes: 55 additions & 0 deletions autotest/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from pathlib import Path

import pytest
import tomli

import modflow_devtools.models as models

MODELS_TOML_PATH = Path(models.DATA_PATH) / models.MODELMAP_NAME


@pytest.fixture
def models_toml():
with MODELS_TOML_PATH.open("rb") as f:
return tomli.load(f)


@pytest.fixture
def temp_cache_dir(tmpdir, monkeypatch):
temp_dir = tmpdir.mkdir("pooch_cache")
monkeypatch.setenv("MF_DATA_DIR", str(temp_dir))
models.FETCHER.path = temp_dir # Update the fetcher path
return temp_dir


def test_registry_loaded():
assert models.FETCHER.registry is not None, "Registry was not loaded"
assert len(models.FETCHER.registry) > 0, "Registry is empty"


def test_generated_functions_exist(models_toml):
for model_name in models_toml.keys():
assert hasattr(models, model_name), (
f"Function {model_name} not found in models module"
)


def test_generated_functions_return_files(models_toml, temp_cache_dir):
for model_name, files in models_toml.items():
model_function = getattr(models, model_name)
fetched_files = model_function()
cached_files = temp_cache_dir.listdir()
assert isinstance(fetched_files, list), (
f"Function {model_name} did not return a list"
)
assert len(fetched_files) == len(files), (
f"Function {model_name} did not return the correct number of files"
)
for fetched_file in fetched_files:
assert Path(fetched_file).exists(), (
f"Fetched file {fetched_file} does not exist"
)
assert Path(temp_cache_dir) / Path(fetched_file).name in cached_files, (
f"Fetched file {fetched_file} is not in the temp cache directory"
)
break # just the first one so we dont ddos github
Loading

0 comments on commit 3f3b217

Please sign in to comment.