forked from MODFLOW-USGS/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.
fix(fixtures): fix model-loading fixtures and utilities (MODFLOW-USGS#12
) * rename modflow_devtools.misc.get_models to get_model_paths * fix get_model_paths filtering by package * sort paths returned by get_model_paths * refactor get_packages function * expand tests
- Loading branch information
Showing
5 changed files
with
125 additions
and
61 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
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
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
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
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 |
---|---|---|
@@ -1,2 +1,59 @@ | ||
def test_set_dir(): | ||
pass | ||
import os | ||
from os import environ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from modflow_devtools.misc import get_model_paths, get_packages, set_dir | ||
|
||
|
||
def test_set_dir(tmp_path): | ||
assert Path(os.getcwd()) != tmp_path | ||
with set_dir(tmp_path): | ||
assert Path(os.getcwd()) == tmp_path | ||
assert Path(os.getcwd()) != tmp_path | ||
|
||
|
||
_repos_path = Path(environ.get("REPOS_PATH")).expanduser().absolute() | ||
_examples_repo_path = _repos_path / "modflow6-examples" | ||
_examples_path = _examples_repo_path / "examples" | ||
_example_paths = ( | ||
sorted(list(_examples_path.glob("ex-*"))) | ||
if _examples_path.is_dir() | ||
else [] | ||
) | ||
|
||
|
||
@pytest.mark.skipif(not any(_example_paths), reason="examples not found") | ||
def test_has_packages(): | ||
example_path = _example_paths[0] | ||
packages = get_packages(example_path / "mfsim.nam") | ||
assert set(packages) == {"tdis", "gwf", "ims"} | ||
|
||
|
||
@pytest.mark.skipif(not any(_example_paths), reason="examples not found") | ||
def test_get_model_paths(): | ||
paths = get_model_paths(_examples_path) | ||
assert len(paths) == 127 | ||
|
||
paths = get_model_paths(_examples_path, namefile="*.nam") | ||
assert len(paths) == 339 | ||
|
||
|
||
def test_get_model_paths_exclude_patterns(): | ||
paths = get_model_paths(_examples_path, excluded=["gwt"]) | ||
assert len(paths) == 63 | ||
|
||
|
||
def test_get_model_paths_select_prefix(): | ||
paths = get_model_paths(_examples_path, prefix="ex2") | ||
assert not any(paths) | ||
|
||
|
||
def test_get_model_paths_select_patterns(): | ||
paths = get_model_paths(_examples_path, selected=["gwf"]) | ||
assert len(paths) == 70 | ||
|
||
|
||
def test_get_model_paths_select_packages(): | ||
paths = get_model_paths(_examples_path, namefile="*.nam", packages=["wel"]) | ||
assert len(paths) == 64 |