-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from MODFLOW-USGS/v0.1.3
* ci(release): update to development version 0.1.3 * docs: update/expand docs (#47) * refactor(fixtures): update defaults for model-finding fixtures (#48) * fix(fixtures): fix test_model_mf6 fixture node id (#49) * ci(release): set version to 0.1.3, update changelog Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: w-bonelli <[email protected]>
- Loading branch information
Showing
15 changed files
with
221 additions
and
78 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
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,31 +1,64 @@ | ||
# Executables | ||
|
||
The `Executables` class is just a mapping between executable names and paths on the filesystem. This can be useful to test multiple versions of the same program, and is easily injected into test functions as a fixture: | ||
The `Executables` class maps executable names to paths on the filesystem. This is useful mainly for testing multiple versions of the same program. | ||
|
||
## Usage | ||
|
||
For example, assuming you have some development binaries in `bin` relative to your current working directory, and an official installation of the same programs in `~/.local.bin`: | ||
|
||
```python | ||
from os import environ | ||
from pathlib import Path | ||
import subprocess | ||
import sys | ||
from modflow_devtools.executables import Executables | ||
|
||
import pytest | ||
bindir_path = Path("~/.local/bin").expanduser() | ||
executables = Executables(mf6=bindir_path / "mf6", mf6_dev=Path("mf6")) | ||
|
||
from modflow_devtools.misc import get_suffixes | ||
from modflow_devtools.executables import Executables | ||
# constructor also supports kwargs | ||
executables = Executables(**{"mf6": bindir_path / "mf6", "mf6_dev": Path("mf6")}) | ||
|
||
_bin_path = Path("~/.local/bin/modflow").expanduser() | ||
_dev_path = Path(environ.get("BIN_PATH")).absolute() | ||
_ext, _ = get_suffixes(sys.platform) | ||
def test_executables(): | ||
assert executables.mf6.is_file() | ||
assert executables.mf6_dev.is_file() | ||
|
||
assert executables.mf6 == bindir_path / "mf6" | ||
assert executables.mf6_dev == Path("mf6") | ||
``` | ||
|
||
The class is easily injected into test functions as a fixture: | ||
|
||
```python | ||
import pytest | ||
|
||
@pytest.fixture | ||
@pytest.mark.skipif(not (_bin_path.is_dir() and _dev_path.is_dir())) | ||
@pytest.mark.skipif(not bindir_path.is_dir()) | ||
def exes(): | ||
return Executables( | ||
mf6_rel=_bin_path / f"mf6{_ext}", | ||
mf6_dev=_dev_path / f"mf6{_ext}" | ||
) | ||
|
||
def test_exes(exes): | ||
print(subprocess.check_output([f"{exes.mf6_rel}", "-v"]).decode('utf-8')) | ||
print(subprocess.check_output([f"{exes.mf6_dev}", "-v"]).decode('utf-8')) | ||
return executables | ||
``` | ||
|
||
Dictionary-style access is also supported: | ||
|
||
```python | ||
def test_executables_access(executables): | ||
assert executables["mf6"] == executables.mf6 == Path("mf6") | ||
``` | ||
|
||
There is a convenience function for getting a program's version string. The function will automatically strip the program name from the output (assumed delimited with `:`). | ||
|
||
```python | ||
import subprocess | ||
|
||
def test_executables_version(exes): | ||
# e.g. '6.4.1 Release 12/09/2022' | ||
assert exes.get_version(exes.mf6) == \ | ||
subprocess.check_output([f"{exes.mf6}", "-v"]).decode('utf-8').strip().split(":")[1].strip() | ||
``` | ||
|
||
## Default mapping | ||
|
||
A utility function is provided to create the default executable mapping used by MODFLOW 6 autotests: | ||
|
||
```python | ||
from modflow_devtools.executables import build_default_exe_dict, Executables | ||
|
||
exes = Executables(**build_default_exe_dict()) | ||
``` |
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,6 +1,6 @@ | ||
__author__ = "Joseph D. Hughes" | ||
__date__ = "Jan 04, 2023" | ||
__version__ = "0.1.2" | ||
__date__ = "Jan 07, 2023" | ||
__version__ = "0.1.3" | ||
__maintainer__ = "Joseph D. Hughes" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
Oops, something went wrong.