forked from MODFLOW-ORG/modflow-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
12,651 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,5 +149,3 @@ autotest/temp/ | |
|
||
# uv lockfile | ||
uv.lock | ||
|
||
modflow_devtools/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.