From 9356e067ea813aeeeda2582cf7ec174c11d80159 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Thu, 25 Jan 2024 18:17:01 -0500 Subject: [PATCH] refactor: remove executables module/class (#136) * unused by any consuming projects * of questionable utility, just use dict --- .github/workflows/ci.yml | 4 ++-- autotest/test_executables.py | 31 ---------------------------- docs/index.rst | 1 - docs/md/executables.md | 33 ------------------------------ docs/md/fixtures.md | 2 +- docs/md/install.md | 6 +++--- modflow_devtools/executables.py | 36 --------------------------------- 7 files changed, 6 insertions(+), 107 deletions(-) delete mode 100644 autotest/test_executables.py delete mode 100644 docs/md/executables.md delete mode 100644 modflow_devtools/executables.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd5a40c..f2becf3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -150,8 +150,8 @@ jobs: - name: Build modflow6 example models if: steps.cache-examples.outputs.cache-hit != 'true' - working-directory: modflow6-examples/etc - run: python ci_build_files.py + working-directory: modflow6-examples/autotest + run: pytest -v -n auto test_scripts.py --init - name: Run local tests working-directory: modflow-devtools/autotest diff --git a/autotest/test_executables.py b/autotest/test_executables.py deleted file mode 100644 index 7f9f330..0000000 --- a/autotest/test_executables.py +++ /dev/null @@ -1,31 +0,0 @@ -import sys -from pathlib import Path -from shutil import which - -import pytest - -from modflow_devtools.executables import Executables -from modflow_devtools.misc import add_sys_path, get_suffixes - -ext, _ = get_suffixes(sys.platform) -exe_stem = "pytest" -exe_path = Path(which(exe_stem)) -bin_path = exe_path.parent -exe = f"{exe_stem}{ext}" - - -@pytest.fixture -def exes(): - with add_sys_path(bin_path): - yield Executables(**{exe_stem: bin_path / exe}) - - -def test_access(exes): - # support both attribute and dictionary style access - assert exes.pytest == exes["pytest"] == exe_path - # .get() works too - assert exes.get("not a target") is None - assert exes.get("not a target", exes["pytest"]) == exes["pytest"] - # membership test - assert "not a target" not in exes - assert "pytest" in exes diff --git a/docs/index.rst b/docs/index.rst index b02faca..7e97db0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -19,7 +19,6 @@ The `modflow-devtools` package provides a set of tools for developing and testin :maxdepth: 2 :caption: Test fixtures - md/executables.md md/fixtures.md md/markers.md diff --git a/docs/md/executables.md b/docs/md/executables.md deleted file mode 100644 index ef1085f..0000000 --- a/docs/md/executables.md +++ /dev/null @@ -1,33 +0,0 @@ -# Executables - -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 development binaries live in `bin` relative to the project root (as is currently the convention for `modflow6`), the following `pytest` fixtures could be defined: - -```python -from modflow_devtools.executables import Executables - -@pytest.fixture(scope="session") -def bin_path() -> Path: - return project_root_path / "bin" - - -@pytest.fixture(scope="session") -def targets(bin_path) -> Executables: - exes = { - # ...map names to paths - } - return Executables(**exes) -``` - -The `targets` fixture can then be injected into test functions: - -```python -def test_targets(targets): - # attribute- and dictionary-style access is supported - assert targets["mf6"] == targets.mf6 - # .get() works too - assert targets.get("not a target") is None -``` diff --git a/docs/md/fixtures.md b/docs/md/fixtures.md index ff1b2f5..750e7fd 100644 --- a/docs/md/fixtures.md +++ b/docs/md/fixtures.md @@ -123,7 +123,7 @@ def test_example_scenario(tmp_path, example_scenario): # ... ``` -**Note**: example models must first be built by running the `ci_build_files.py` script in `modflow6-examples/etc` before running tests using the `example_scenario` fixture. See the [install docs](https://modflow-devtools.readthedocs.io/en/latest/md/install.html) for more info. +**Note**: example models must first be built by running `pytest -v -n auto test_scripts.py --init` in `modflow6-examples/autotest` before running tests using the `example_scenario` fixture. See the [install docs](https://modflow-devtools.readthedocs.io/en/latest/md/install.html) for more info. ### Filtering diff --git a/docs/md/install.md b/docs/md/install.md index 473bc1e..f56c81a 100644 --- a/docs/md/install.md +++ b/docs/md/install.md @@ -67,10 +67,10 @@ cd modflow6-examples/etc pip install -r requirements.pip.txt ``` -Then, still from the `etc` folder, run: +Then, from the `autotest` folder, run: ```shell -python ci_build_files.py +pytest -v -n auto test_scripts.py --init ``` -This will build the examples for subsequent use by the tests. +This will build the examples for subsequent use by the tests. To save time, models will not be run — to run the models too, omit `--init`. diff --git a/modflow_devtools/executables.py b/modflow_devtools/executables.py deleted file mode 100644 index 59408ae..0000000 --- a/modflow_devtools/executables.py +++ /dev/null @@ -1,36 +0,0 @@ -from pathlib import Path -from types import SimpleNamespace -from typing import Dict - -from modflow_devtools.misc import get_suffixes - -# re-export for backwards-compatibility (used to be here) -get_suffixes = get_suffixes - - -class Executables(SimpleNamespace): - """ - Container mapping executable names to their paths. - """ - - def __init__(self, **kwargs): - super().__init__(**kwargs) - - def __contains__(self, item): - return item in self.__dict__ - - def __setitem__(self, key, item): - self.__dict__[key] = item - - def __getitem__(self, key): - return self.__dict__[key] - - def get(self, key, default=None): - return self.as_dict().get(key, default) - - def as_dict(self) -> Dict[str, Path]: - """ - Returns a dictionary mapping executable names to paths. - """ - - return self.__dict__.copy()