From c1ca09c83e2742ab463a589f51e6335fa20cd51d Mon Sep 17 00:00:00 2001 From: w-bonelli Date: Tue, 15 Nov 2022 11:23:49 -0500 Subject: [PATCH] refactor(tests): import fixtures/utils from modflow-devtools --- .gitignore | 3 + DEVELOPER.md | 172 +------------ autotest/conftest.py | 312 ++--------------------- autotest/generate_classes.py | 11 +- autotest/pytest.ini | 2 + autotest/regression/test_lgr.py | 8 +- autotest/regression/test_mf6.py | 248 +++++++++--------- autotest/regression/test_mf6_examples.py | 21 +- autotest/regression/test_mfnwt.py | 17 +- autotest/regression/test_modflow.py | 57 +++-- autotest/regression/test_str.py | 16 +- autotest/regression/test_swi2.py | 6 +- autotest/regression/test_wel.py | 18 +- autotest/test_binaryfile.py | 22 +- autotest/test_cbc_full3D.py | 13 +- autotest/test_conftest.py | 279 +------------------- autotest/test_example_notebooks.py | 3 +- autotest/test_example_scripts.py | 3 +- autotest/test_export.py | 304 ++++++++++++---------- autotest/test_flopy_module.py | 12 +- autotest/test_formattedfile.py | 14 +- autotest/test_gage.py | 24 +- autotest/test_geospatial_util.py | 2 +- autotest/test_get_modflow.py | 33 ++- autotest/test_grid.py | 20 +- autotest/test_grid_cases.py | 24 +- autotest/test_gridgen.py | 69 ++--- autotest/test_gridintersect.py | 3 +- autotest/test_gridutil.py | 58 +++-- autotest/test_headufile.py | 2 +- autotest/test_hydmodfile.py | 13 +- autotest/test_lake_connections.py | 20 +- autotest/test_lgr.py | 10 +- autotest/test_listbudget.py | 3 +- autotest/test_mf6.py | 60 +++-- autotest/test_mfnwt.py | 29 ++- autotest/test_mfreadnam.py | 25 +- autotest/test_mnw.py | 26 +- autotest/test_modflow.py | 117 ++++----- autotest/test_modpathfile.py | 16 +- autotest/test_mp5.py | 6 +- autotest/test_mp6.py | 87 +++---- autotest/test_mp6_cases.py | 12 +- autotest/test_mp7.py | 125 +++++---- autotest/test_mp7_cases.py | 16 +- autotest/test_mt3d.py | 115 +++++---- autotest/test_nwt_ag.py | 18 +- autotest/test_obs.py | 18 +- autotest/test_plot.py | 32 +-- autotest/test_postprocessing.py | 30 ++- autotest/test_seawat.py | 23 +- autotest/test_sfr.py | 93 +++---- autotest/test_specific_discharge.py | 65 ++--- autotest/test_str.py | 8 +- autotest/test_subwt.py | 16 +- autotest/test_swr_binaryread.py | 2 +- autotest/test_template_writer.py | 18 +- autotest/test_usg.py | 73 +++--- autotest/test_util_2d_and_3d.py | 73 +++--- autotest/test_util_array.py | 4 +- autotest/test_uzf.py | 92 ++++--- autotest/test_zonbud_utility.py | 40 +-- etc/environment.yml | 2 + flopy/utils/mfreadnam.py | 6 +- setup.cfg | 2 + 65 files changed, 1286 insertions(+), 1785 deletions(-) diff --git a/.gitignore b/.gitignore index f49509acda..36684434cb 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,6 @@ autotest/.noseids .docs/_notebooks *.bak + +# environment files +**.env \ No newline at end of file diff --git a/DEVELOPER.md b/DEVELOPER.md index 00fd693e9d..4682486ec8 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -161,10 +161,14 @@ Like the scripts and tutorials, each notebook is configured to create and (attem ## Tests -To run the tests you will need `pytest` and a few plugins, including [`pytest-xdist`](https://pytest-xdist.readthedocs.io/en/latest/) and [`pytest-benchmark`](https://pytest-benchmark.readthedocs.io/en/latest/index.html). Test dependencies are specified in the `test` extras group in `setup.cfg` (with pip, use `pip install ".[test]"`). Test dependencies are included in the Conda environment `etc/environment`. +To run the tests you will need `pytest` and a few plugins, including [`pytest-xdist`](https://pytest-xdist.readthedocs.io/en/latest/), [`pytest-dotenv`](https://github.com/quiqua/pytest-dotenv), and [`pytest-benchmark`](https://pytest-benchmark.readthedocs.io/en/latest/index.html). Test dependencies are specified in the `test` extras group in `setup.cfg` (with pip, use `pip install ".[test]"`). Test dependencies are included in the Conda environment `etc/environment`. **Note:** to prepare your code for a pull request, you will need a few more packages specified in the `lint` extras group in `setup.cfg` (also included by default for Conda). See the docs on [submitting a pull request](CONTRIBUTING.md) for more info. +### Configuring tests + +Some of the tests (namely those for the [`get-modflow`](docs/get_modflow.md) utility) invoke the GitHub API. + ### Running tests Tests must be run from the `autotest` directory. To run a single test script in verbose mode: @@ -209,15 +213,19 @@ This should complete in under a minute on most machines. Smoke testing aims to c **Note:** most the `regression` and `example` tests are `slow`, but there are some other slow tests, e.g. in `test_export.py`, and some regression tests and examples are fast. +### Writing tests + +Test functions and files should be named informatively, with related tests grouped in the same file. The test suite runs on GitHub Actions in parallel, so tests should not access the working space of other tests, example scripts, tutorials or notebooks. A number of shared test fixtures are [imported](conftest.py) from [`modflow-devtools`](https://github.com/MODFLOW-USGS/modflow-devtools). These include keepable temporary directory fixtures and miscellanous utilities (see `modflow-devtools` repository README for more information on fixture usage). New tests should use these facilities where possible. See also the [contribution guidelines](CONTRIBUTING.md) before submitting a pull request. + ### Debugging tests -To debug a failed test it can be helpful to inspect its output, which is cleaned up automatically by default. To run a failing test and keep its output, use the `--keep` option to provide a save location: +To debug a failed test it can be helpful to inspect its output, which is cleaned up automatically by default. `modflow-devtools` provides temporary directory fixtures that allow optionally keeping test outputs in a specified location. To run a test and keep its output, use the `--keep` option to provide a save location: pytest test_export.py --keep exports_scratch -This will retain the test directories created by the test, which allows files to be evaluated for errors. Any tests using the function-scoped `tmpdir` and related fixtures (e.g. `class_tmpdir`, `module_tmpdir`) defined in `conftest.py` are compatible with this mechanism. +This will retain any files created by the test in `exports_scratch` in the current working directory. Any tests using the function-scoped `function_tmpdir` and related fixtures (e.g. `class_tmpdir`, `module_tmpdir`) defined in `modflow_devtools/fixtures` are compatible with this mechanism. -There is also a `--keep-failed ` option which preserves the outputs of failed tests in the given location, however this option is only compatible with function-scoped temporary directories (the `tmpdir` fixture defined in `conftest.py`). +There is also a `--keep-failed ` option which preserves the outputs of failed tests in the given location, however this option is only compatible with function-scoped temporary directories (the `function_tmpdir` fixture). ### Performance testing @@ -281,159 +289,3 @@ Benchmark results are only printed to `stdout` by default. To save results to a Profiling is [distinct](https://stackoverflow.com/a/39381805/6514033) from benchmarking in evaluating a program's call stack in detail, while benchmarking just invokes a function repeatedly and computes summary statistics. Profiling is also accomplished with `pytest-benchmark`: use the `--benchmark-cprofile` option when running tests which use the `benchmark` fixture described above. The option's value is the column to sort results by. For instance, to sort by total time, use `--benchmark-cprofile="tottime"`. See the `pytest-benchmark` [docs](https://pytest-benchmark.readthedocs.io/en/stable/usage.html#commandline-options) for more information. By default, `pytest-benchmark` will only print profiling results to `stdout`. If the `--benchmark-autosave` flag is provided, performance profile data will be included in the JSON files written to the `.benchmarks` save directory as described in the benchmarking section above. - -### Writing tests - -Test functions and files should be named informatively, with related tests grouped in the same file. The test suite runs on GitHub Actions in parallel, so tests must not pollute the working space of other tests, example scripts, tutorials or notebooks. A number of shared test fixtures are provided in `autotest/conftest.py`. New tests should use these facilities where possible, to standardize conventions, help keep maintenance minimal, and prevent shared test state and proliferation of untracked files. See also the [contribution guidelines](CONTRIBUTING.md) before submitting a pull request. - -#### Keepable temporary directories - -The `tmpdir` fixtures defined in `conftest.py` provide a path to a temporary directory which is automatically created before test code runs and automatically removed afterwards. (The builtin `pytest` `temp_path` fixture can also be used, but is not compatible with the `--keep` command line argument detailed above.) - -For instance, using temporary directory fixtures for various scopes: - -```python -from pathlib import Path -import inspect - -def test_tmpdirs(tmpdir, module_tmpdir): - # function-scoped temporary directory - assert isinstance(tmpdir, Path) - assert tmpdir.is_dir() - assert inspect.currentframe().f_code.co_name in tmpdir.stem - - # module-scoped temp dir (accessible to other tests in the script) - assert module_tmpdir.is_dir() - assert "autotest" in module_tmpdir.stem -``` - -These fixtures can be substituted transparently for `pytest`'s built-in `tmp_path`, with the additional benefit that when `pytest` is invoked with the `--keep` argument, e.g. `pytest --keep temp`, outputs will automatically be saved to subdirectories of `temp` named according to the test case, class or module. (As described above, this is useful for debugging a failed test by inspecting its outputs, which would otherwise be cleaned up.) - -#### Locating example data - -Shared fixtures and utility functions are also provided for locating example data on disk. The `example_data_path` fixture resolves to `examples/data` relative to the project root, regardless of the location of the test script (as long as it's somewhere in the `autotest` directory). - -```python -def test_with_data(tmpdir, example_data_path): - model_path = example_data_path / "freyberg" - # load model... -``` - -This is preferable to manually handling relative paths as if the location of the example data changes in the future, only a single fixture in `conftest.py` will need to be updated rather than every test case individually. - -An equivalent function `get_example_data_path()` is also provided in `conftest.py`. This is useful to dynamically generate data for test parametrization. (Due to a [longstanding `pytest` limitation](https://github.com/pytest-dev/pytest/issues/349), fixtures cannot be used to generate test parameters.) - -#### Locating the project root - -A similar `get_project_root_path()` function is also provided, doing what it says on the tin: - -```python -from autotest.conftest import get_project_root_path, get_example_data_path - -def test_get_paths(): - example_data = get_example_data_path() - project_root = get_project_root_path() - - assert example_data.parent.parent == project_root -``` - -Note that this function expects tests to be run from the `autotest` directory, as mentioned above. - -#### Conditionally skipping tests - -Several `pytest` markers are provided to conditionally skip tests based on executable availability, Python package environment or operating system. - -To skip tests if one or more executables are not available on the path: - -```python -from shutil import which -from autotest.conftest import requires_exe - -@requires_exe("mf6") -def test_mf6(): - assert which("mf6") - -@requires_exe("mf6", "mp7") -def test_mf6_and_mp7(): - assert which("mf6") - assert which("mp7") -``` - -To skip tests if one or more Python packages are not available: - -```python -from autotest.conftest import requires_pkg - -@requires_pkg("pandas") -def test_needs_pandas(): - import pandas as pd - -@requires_pkg("pandas", "shapefile") -def test_needs_pandas(): - import pandas as pd - from shapefile import Reader -``` - -To mark tests requiring or incompatible with particular operating systems: - -```python -import os -import platform -from autotest.conftest import requires_platform, excludes_platform - -@requires_platform("Windows") -def test_needs_windows(): - assert platform.system() == "Windows" - -@excludes_platform("Darwin", ci_only=True) -def test_breaks_osx_ci(): - if "CI" in os.environ: - assert platform.system() != "Darwin" -``` - -Platforms must be specified as returned by `platform.system()`. - -Both these markers accept a `ci_only` flag, which indicates whether the policy should only apply when the test is running on GitHub Actions CI. - -There is also a `@requires_github` marker, which will skip decorated tests if the GitHub API is unreachable. - -### Miscellaneous - -A few other useful tools for FloPy development include: - -- [`doctoc`](https://www.npmjs.com/package/doctoc): automatically generate table of contents sections for markdown files -- [`act`](https://github.com/nektos/act): test GitHub Actions workflows locally (requires Docker) - -#### Generating TOCs with `doctoc` - -The [`doctoc`](https://www.npmjs.com/package/doctoc) tool can be used to automatically generate table of contents sections for markdown files. `doctoc` is distributed with the [Node Package Manager](https://docs.npmjs.com/cli/v7/configuring-npm/install). With Node installed use `npm install -g doctoc` to install `doctoc` globally. Then just run `doctoc `, e.g.: - -```shell -doctoc DEVELOPER.md -``` - -This will insert HTML comments surrounding an automatically edited region, scanning for headers and creating an appropriately indented TOC tree. Subsequent runs are idempotent, updating if the file has changed or leaving it untouched if not. - -To run `doctoc` for all markdown files in a particular directory (recursive), use `doctoc some/path`. - -#### Testing CI workflows with `act` - -The [`act`](https://github.com/nektos/act) tool uses Docker to run containerized CI workflows in a simulated GitHub Actions environment. [Docker Desktop](https://www.docker.com/products/docker-desktop/) is required for Mac or Windows and [Docker Engine](https://docs.docker.com/engine/) on Linux. - -With Docker installed and running, run `act -l` from the project root to see available CI workflows. To run all workflows and jobs, just run `act`. To run a particular workflow use `-W`: - -```shell -act -W .github/workflows/commit.yml -``` - -To run a particular job within a workflow, add the `-j` option: - -```shell -act -W .github/workflows/commit.yml -j build -``` - -**Note:** GitHub API rate limits are easy to exceed, especially with job matrices. Authenticated GitHub users have a much higher rate limit: use `-s GITHUB_TOKEN=` when invoking `act` to provide a personal access token. Note that this will log your token in shell history — leave the value blank for a prompt to enter it more securely. - -The `-n` flag can be used to execute a dry run, which doesn't run anything, just evaluates workflow, job and step definitions. See the [docs](https://github.com/nektos/act#example-commands) for more. - -**Note:** `act` can only run Linux-based container definitions, so Mac or Windows workflows or matrix OS entries will be skipped. diff --git a/autotest/conftest.py b/autotest/conftest.py index 3339751545..f8b721b72e 100644 --- a/autotest/conftest.py +++ b/autotest/conftest.py @@ -15,6 +15,12 @@ import matplotlib.pyplot as plt import pkg_resources import pytest +from modflow_devtools.misc import is_in_ci + +# import modflow-devtools fixtures + +pytest_plugins = ["modflow_devtools.fixtures"] + # constants @@ -36,149 +42,7 @@ def get_flopy_data_path() -> Path: return get_project_root_path() / "flopy" / "data" -def get_current_branch() -> str: - # check if on GitHub Actions CI - ref = environ.get("GITHUB_REF") - if ref is not None: - return basename(normpath(ref)).lower() - - # otherwise ask git about it - if not which("git"): - raise RuntimeError("'git' required to determine current branch") - stdout, stderr, code = run_cmd("git", "rev-parse", "--abbrev-ref", "HEAD") - if code == 0 and stdout: - return stdout.strip().lower() - raise ValueError(f"Could not determine current branch: {stderr}") - - -def is_connected(hostname): - """See https://stackoverflow.com/a/20913928/ to test hostname.""" - try: - host = socket.gethostbyname(hostname) - s = socket.create_connection((host, 80), 2) - s.close() - return True - except Exception: - pass - return False - - -def is_in_ci(): - # if running in GitHub Actions CI, "CI" variable always set to true - # https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables - return bool(os.environ.get("CI", None)) - - -def is_github_rate_limited() -> Optional[bool]: - """ - Determines if a GitHub API rate limit is applied to the current IP. - Note that running this function will consume an API request! - - Returns - ------- - True if rate-limiting is applied, otherwise False (or None if the connection fails). - """ - try: - with request.urlopen( - "https://api.github.com/users/octocat" - ) as response: - remaining = int(response.headers["x-ratelimit-remaining"]) - if remaining < 10: - warn( - f"Only {remaining} GitHub API requests remaining before rate-limiting" - ) - return remaining > 0 - except: - return None - - -_has_exe_cache = {} -_has_pkg_cache = {} - - -def has_exe(exe): - if exe not in _has_exe_cache: - _has_exe_cache[exe] = bool(which(exe)) - return _has_exe_cache[exe] - - -def has_pkg(pkg): - if pkg not in _has_pkg_cache: - - # for some dependencies, package name and import name are different - # (e.g. pyshp/shapefile, mfpymake/pymake, python-dateutil/dateutil) - # pkg_resources expects package name, importlib expects import name - try: - _has_pkg_cache[pkg] = bool(importlib.import_module(pkg)) - except (ImportError, ModuleNotFoundError): - try: - _has_pkg_cache[pkg] = bool(pkg_resources.get_distribution(pkg)) - except pkg_resources.DistributionNotFound: - _has_pkg_cache[pkg] = False - - return _has_pkg_cache[pkg] - - -def requires_exe(*exes): - missing = {exe for exe in exes if not has_exe(exe)} - return pytest.mark.skipif( - missing, - reason=f"missing executable{'s' if len(missing) != 1 else ''}: " - + ", ".join(missing), - ) - - -def requires_pkg(*pkgs): - missing = {pkg for pkg in pkgs if not has_pkg(pkg)} - return pytest.mark.skipif( - missing, - reason=f"missing package{'s' if len(missing) != 1 else ''}: " - + ", ".join(missing), - ) - - -def requires_platform(platform, ci_only=False): - return pytest.mark.skipif( - system().lower() != platform.lower() - and (is_in_ci() if ci_only else True), - reason=f"only compatible with platform: {platform.lower()}", - ) - - -def excludes_platform(platform, ci_only=False): - return pytest.mark.skipif( - system().lower() == platform.lower() - and (is_in_ci() if ci_only else True), - reason=f"not compatible with platform: {platform.lower()}", - ) - - -def requires_branch(branch): - current = get_current_branch() - return pytest.mark.skipif( - current != branch, reason=f"must run on branch: {branch}" - ) - - -def excludes_branch(branch): - current = get_current_branch() - return pytest.mark.skipif( - current == branch, reason=f"can't run on branch: {branch}" - ) - - -requires_github = pytest.mark.skipif( - not is_connected("github.com"), reason="github.com is required." -) - - -requires_spatial_reference = pytest.mark.skipif( - not is_connected("spatialreference.org"), - reason="spatialreference.org is required.", -) - - -# example data fixtures +# path fixtures @pytest.fixture(scope="session") @@ -201,61 +65,6 @@ def example_shapefiles(example_data_path) -> List[Path]: return [f.resolve() for f in (example_data_path / "prj_test").glob("*")] -# keepable temporary directory fixtures for various scopes - - -@pytest.fixture(scope="function") -def tmpdir(tmpdir_factory, request) -> Path: - node = ( - request.node.name.replace("/", "_") - .replace("\\", "_") - .replace(":", "_") - ) - temp = Path(tmpdir_factory.mktemp(node)) - yield Path(temp) - - keep = request.config.getoption("--keep") - if keep: - copytree(temp, Path(keep) / temp.name) - - keep_failed = request.config.getoption("--keep-failed") - if keep_failed and request.node.rep_call.failed: - copytree(temp, Path(keep_failed) / temp.name) - - -@pytest.fixture(scope="class") -def class_tmpdir(tmpdir_factory, request) -> Path: - assert ( - request.cls is not None - ), "Class-scoped temp dir fixture must be used on class" - temp = Path(tmpdir_factory.mktemp(request.cls.__name__)) - yield temp - - keep = request.config.getoption("--keep") - if keep: - copytree(temp, Path(keep) / temp.name) - - -@pytest.fixture(scope="module") -def module_tmpdir(tmpdir_factory, request) -> Path: - temp = Path(tmpdir_factory.mktemp(request.module.__name__)) - yield temp - - keep = request.config.getoption("--keep") - if keep: - copytree(temp, Path(keep) / temp.name) - - -@pytest.fixture(scope="session") -def session_tmpdir(tmpdir_factory, request) -> Path: - temp = Path(tmpdir_factory.mktemp(request.session.name)) - yield temp - - keep = request.config.getoption("--keep") - if keep: - copytree(temp, Path(keep) / temp.name) - - # fixture to automatically close any plots (or optionally show them) @@ -272,6 +81,16 @@ def close_plot(request): plt.close("all") +@pytest.fixture(scope="session", autouse=True) +def patch_macos_ci_matplotlib(): + # use noninteractive matplotlib backend if in Mac OS CI to avoid pytest-xdist node failure + # e.g. https://github.com/modflowpy/flopy/runs/7748574375?check_suite_focus=true#step:9:57 + if is_in_ci() and system().lower() == "darwin": + import matplotlib + + matplotlib.use("agg") + + # pytest configuration hooks @@ -290,43 +109,6 @@ def pytest_runtest_makereport(item, call): def pytest_addoption(parser): - parser.addoption( - "-K", - "--keep", - action="store", - default=None, - help="Move the contents of temporary test directories to correspondingly named subdirectories at the given " - "location after tests complete. This option can be used to exclude test results from automatic cleanup, " - "e.g. for manual inspection. The provided path is created if it does not already exist. An error is " - "thrown if any matching files already exist.", - ) - - parser.addoption( - "--keep-failed", - action="store", - default=None, - help="Move the contents of temporary test directories to correspondingly named subdirectories at the given " - "location if the test case fails. This option automatically saves the outputs of failed tests in the " - "given location. The path is created if it doesn't already exist. An error is thrown if files with the " - "same names already exist in the given location.", - ) - - parser.addoption( - "-M", - "--meta", - action="store", - metavar="NAME", - help="Marker indicating a test is only run by other tests (e.g., the test framework testing itself).", - ) - - parser.addoption( - "-S", - "--smoke", - action="store_true", - default=False, - help="Run only smoke tests (should complete in <1 minute).", - ) - parser.addoption( "--show-plots", action="store_true", @@ -336,29 +118,6 @@ def pytest_addoption(parser): ) -def pytest_configure(config): - config.addinivalue_line( - "markers", - "meta(name): mark test to run only inside other groups of tests.", - ) - - -def pytest_runtest_setup(item): - # apply meta-test option - meta = item.config.getoption("--meta") - metagroups = [mark.args[0] for mark in item.iter_markers(name="meta")] - if metagroups and meta not in metagroups: - pytest.skip() - - # smoke tests are \ {slow U example U regression} - smoke = item.config.getoption("--smoke") - slow = list(item.iter_markers(name="slow")) - example = list(item.iter_markers(name="example")) - regression = list(item.iter_markers(name="regression")) - if smoke and (slow or example or regression): - pytest.skip() - - def pytest_report_header(config): """Header for pytest to show versions of packages.""" @@ -396,40 +155,3 @@ def pytest_report_header(config): if not_found: lines.append("optional packages not found: " + ", ".join(not_found)) return "\n".join(lines) - - -# functions to run commands and scripts - - -def run_cmd(*args, verbose=False, **kwargs): - """Run any command, return tuple (stdout, stderr, returncode).""" - args = [str(g) for g in args] - if verbose: - print("running: " + " ".join(args)) - p = Popen(args, stdout=PIPE, stderr=PIPE, **kwargs) - stdout, stderr = p.communicate() - stdout = stdout.decode() - stderr = stderr.decode() - returncode = p.returncode - if verbose: - print(f"stdout:\n{stdout}") - print(f"stderr:\n{stderr}") - print(f"returncode: {returncode}") - return stdout, stderr, returncode - - -def run_py_script(script, *args, verbose=False): - """Run a Python script, return tuple (stdout, stderr, returncode).""" - return run_cmd( - sys.executable, script, *args, verbose=verbose, cwd=Path(script).parent - ) - - -# use noninteractive matplotlib backend if in Mac OS CI to avoid pytest-xdist node failure -# e.g. https://github.com/modflowpy/flopy/runs/7748574375?check_suite_focus=true#step:9:57 -@pytest.fixture(scope="session", autouse=True) -def patch_macos_ci_matplotlib(): - if is_in_ci() and system().lower() == "darwin": - import matplotlib - - matplotlib.use("agg") diff --git a/autotest/generate_classes.py b/autotest/generate_classes.py index d291a06be2..eb46c97097 100644 --- a/autotest/generate_classes.py +++ b/autotest/generate_classes.py @@ -1,25 +1,28 @@ import os import pytest -from autotest.conftest import excludes_branch, get_project_root_path +from autotest.conftest import get_project_root_path +from modflow_devtools.markers import excludes_branch from flopy.mf6.utils import generate_classes - _project_root_path = get_project_root_path() _using_xdist = bool(os.environ.get("PYTEST_XDIST_WORKER", None)) @excludes_branch("master") @pytest.mark.mf6 -@pytest.mark.skipif(_using_xdist, reason="modifies and reverts repository files, can't be run in parallel") +@pytest.mark.skipif( + _using_xdist, + reason="modifies and reverts repository files, can't be run in parallel", +) def test_generate_classes_from_dfn(): try: generate_classes(branch="develop", backup=False) finally: paths = [ _project_root_path / "flopy" / "mf6" / "data" / "dfn", - _project_root_path / "flopy" / "mf6" / "modflow" + _project_root_path / "flopy" / "mf6" / "modflow", ] # restoring might lose work if these files have been modified for path in paths: diff --git a/autotest/pytest.ini b/autotest/pytest.ini index a6f89519fb..97931bb22a 100644 --- a/autotest/pytest.ini +++ b/autotest/pytest.ini @@ -7,6 +7,8 @@ python_files = *_test*.py *_profile*.py *_benchmark*.py +env_files = + .env markers = slow: tests that don't complete in a few seconds example: exercise scripts, tutorials and notebooks diff --git a/autotest/regression/test_lgr.py b/autotest/regression/test_lgr.py index 965a4f247b..45d20fcad5 100644 --- a/autotest/regression/test_lgr.py +++ b/autotest/regression/test_lgr.py @@ -2,9 +2,9 @@ from os.path import dirname, join from pathlib import Path -from flaky import flaky import pytest -from autotest.conftest import requires_exe, requires_pkg +from flaky import flaky +from modflow_devtools.markers import requires_exe, requires_pkg import flopy @@ -13,13 +13,13 @@ @requires_exe("mflgr") @requires_pkg("pymake") @pytest.mark.regression -def test_simplelgr(tmpdir, example_data_path): +def test_simplelgr(function_tmpdir, example_data_path): """Test load and write of distributed MODFLOW-LGR example problem.""" import pymake mflgr_v2_ex3_path = example_data_path / "mflgr_v2" / "ex3" - ws = tmpdir / mflgr_v2_ex3_path.stem + ws = function_tmpdir / mflgr_v2_ex3_path.stem shutil.copytree(mflgr_v2_ex3_path, ws) # load the lgr model diff --git a/autotest/regression/test_mf6.py b/autotest/regression/test_mf6.py index 72e54f20c3..de8805cabb 100644 --- a/autotest/regression/test_mf6.py +++ b/autotest/regression/test_mf6.py @@ -6,7 +6,7 @@ import numpy as np import pytest -from autotest.conftest import requires_exe, requires_pkg +from modflow_devtools.markers import requires_exe, requires_pkg import flopy from flopy.mf6 import ( @@ -56,14 +56,14 @@ @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test_np001(tmpdir, example_data_path): +def test_np001(function_tmpdir, example_data_path): import pymake # init paths test_ex_name = "np001" model_name = "np001_mod" data_path = example_data_path / "mf6" / "create_tests" / test_ex_name - ws = str(tmpdir / "ws") + ws = str(function_tmpdir / "ws") # copy example data into working directory shutil.copytree(data_path, ws) @@ -397,7 +397,7 @@ def test_np001(tmpdir, example_data_path): # inspect cells cell_list = [(0, 0, 0), (0, 0, 4), (0, 0, 9)] - out_file = str(tmpdir / "inspect_test_np001.csv") + out_file = str(function_tmpdir / "inspect_test_np001.csv") model.inspect_cells(cell_list, output_file_path=out_file, stress_period=0) # get expected results @@ -426,14 +426,16 @@ def test_np001(tmpdir, example_data_path): model.set_model_relative_path(md_folder) run_folder_new = os.path.join(ws, md_folder) # set all data external - sim.set_all_data_external(external_data_folder=tmpdir / "data") + sim.set_all_data_external(external_data_folder=function_tmpdir / "data") sim.write_simulation() # test file with relative path to model relative path wel_path = os.path.join(ws, md_folder, "well_folder", f"{model_name}.wel") assert os.path.exists(wel_path) # test data file was recreated by set_all_data_external - riv_path = str(tmpdir / "data" / "np001_mod.riv_stress_period_data_1.txt") + riv_path = str( + function_tmpdir / "data" / "np001_mod.riv_stress_period_data_1.txt" + ) assert os.path.exists(riv_path) assert ( @@ -626,14 +628,14 @@ def test_np001(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test_np002(tmpdir, example_data_path): +def test_np002(function_tmpdir, example_data_path): import pymake # init paths test_ex_name = "np002" model_name = "np002_mod" data_folder = example_data_path / "mf6" / "create_tests" / test_ex_name - ws = str(tmpdir / "ws") + ws = str(function_tmpdir / "ws") # copy example data into working directory shutil.copytree(data_folder, ws) expected_output_folder = data_folder / "expected_output" @@ -798,7 +800,7 @@ def test_np002(tmpdir, example_data_path): sim.run_simulation() cell_list = [(0, 0, 0), (0, 0, 3), (0, 0, 4), (0, 0, 9)] - out_file = str(tmpdir / "inspect_test_np002.csv") + out_file = str(function_tmpdir / "inspect_test_np002.csv") model.inspect_cells(cell_list, output_file_path=out_file) sim2 = MFSimulation.load(sim_ws=ws) @@ -903,7 +905,7 @@ def test_np002(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test021_twri(tmpdir, example_data_path): +def test021_twri(function_tmpdir, example_data_path): import pymake # init paths @@ -912,7 +914,7 @@ def test021_twri(tmpdir, example_data_path): data_folder = str( example_data_path / "mf6" / "create_tests" / test_ex_name ) - ws = str(tmpdir / "ws") + ws = str(function_tmpdir / "ws") # copy example data into working directory shutil.copytree(data_folder, ws) @@ -927,7 +929,7 @@ def test021_twri(tmpdir, example_data_path): exe_name="mf6", sim_ws=data_folder, ) - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) tdis_rc = [(86400.0, 1, 1.0)] tdis_package = ModflowTdis( sim, time_units="SECONDS", nper=1, perioddata=tdis_rc @@ -1130,7 +1132,7 @@ def test021_twri(tmpdir, example_data_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test005_create_tests_advgw_tidal(tmpdir, example_data_path): +def test005_create_tests_advgw_tidal(function_tmpdir, example_data_path): import pymake # init paths @@ -1651,14 +1653,14 @@ def test005_create_tests_advgw_tidal(tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.set_all_data_external() sim.write_simulation() # test time series data file with relative path to simulation path - ts_path = str(tmpdir / "well-rates" / "well-rates.ts") + ts_path = str(function_tmpdir / "well-rates" / "well-rates.ts") assert os.path.exists(ts_path) # run simulation @@ -1666,12 +1668,12 @@ def test005_create_tests_advgw_tidal(tmpdir, example_data_path): # inspect cells cell_list = [(2, 3, 2), (0, 4, 2), (0, 2, 4), (0, 5, 5), (0, 9, 9)] - out_file = str(tmpdir / "inspect_AdvGW_tidal.csv") + out_file = str(function_tmpdir / "inspect_AdvGW_tidal.csv") model.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results - head_new = str(tmpdir / "AdvGW_tidal.hds") - outfile = str(tmpdir / "head_compare.dat") + head_new = str(function_tmpdir / "AdvGW_tidal.hds") + outfile = str(function_tmpdir / "head_compare.dat") assert pymake.compare_heads( None, None, @@ -1690,12 +1692,12 @@ def test005_create_tests_advgw_tidal(tmpdir, example_data_path): assert filename == f"new_name.{package.package_type}" package_type_dict[package.package_type] = 1 sim.write_simulation() - name_file = str(tmpdir / "new_name.nam") + name_file = str(function_tmpdir / "new_name.nam") assert os.path.exists(name_file) - dis_file = str(tmpdir / "new_name.dis") + dis_file = str(function_tmpdir / "new_name.dis") assert os.path.exists(dis_file) # test time series data file with relative path to simulation path - ts_path = str(tmpdir / "well-rates" / "new_name.ts") + ts_path = str(function_tmpdir / "well-rates" / "new_name.ts") assert os.path.exists(ts_path) sim.rename_all_packages("all_files_same_name") @@ -1709,14 +1711,14 @@ def test005_create_tests_advgw_tidal(tmpdir, example_data_path): for ims_file in sim._ims_files.values(): assert ims_file.filename == "all_files_same_name.ims" sim.write_simulation() - name_file = str(tmpdir / "all_files_same_name.nam") + name_file = str(function_tmpdir / "all_files_same_name.nam") assert os.path.exists(name_file) - dis_file = str(tmpdir / "all_files_same_name.dis") + dis_file = str(function_tmpdir / "all_files_same_name.dis") assert os.path.exists(dis_file) - tdis_file = str(tmpdir / "all_files_same_name.tdis") + tdis_file = str(function_tmpdir / "all_files_same_name.tdis") assert os.path.exists(tdis_file) # test time series data file with relative path to simulation path - ts_path = str(tmpdir / "well-rates" / "all_files_same_name.ts") + ts_path = str(function_tmpdir / "well-rates" / "all_files_same_name.ts") assert os.path.exists(ts_path) # load simulation @@ -1757,7 +1759,7 @@ def test005_create_tests_advgw_tidal(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test004_create_tests_bcfss(tmpdir, example_data_path): +def test004_create_tests_bcfss(function_tmpdir, example_data_path): import pymake # init paths @@ -1928,7 +1930,7 @@ def test004_create_tests_bcfss(tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.set_all_data_external() @@ -1938,8 +1940,8 @@ def test004_create_tests_bcfss(tmpdir, example_data_path): sim.run_simulation() # compare output to expected results - head_new = os.path.join(str(tmpdir), "bcf2ss.hds") - outfile = os.path.join(str(tmpdir), "head_compare.dat") + head_new = os.path.join(str(function_tmpdir), "bcf2ss.hds") + outfile = os.path.join(str(function_tmpdir), "head_compare.dat") assert pymake.compare_heads( None, None, @@ -1955,7 +1957,7 @@ def test004_create_tests_bcfss(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test035_create_tests_fhb(tmpdir, example_data_path): +def test035_create_tests_fhb(function_tmpdir, example_data_path): import pymake # init paths @@ -2071,7 +2073,7 @@ def test035_create_tests_fhb(tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.set_all_data_external() @@ -2081,8 +2083,8 @@ def test035_create_tests_fhb(tmpdir, example_data_path): sim.run_simulation() # compare output to expected results - head_new = str(tmpdir / "fhb2015_fhb.hds") - outfile = str(tmpdir / "head_compare.dat") + head_new = str(function_tmpdir / "fhb2015_fhb.hds") + outfile = str(function_tmpdir / "head_compare.dat") assert pymake.compare_heads( None, None, @@ -2098,7 +2100,7 @@ def test035_create_tests_fhb(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake", "shapefile") @pytest.mark.regression -def test006_create_tests_gwf3_disv(tmpdir, example_data_path): +def test006_create_tests_gwf3_disv(function_tmpdir, example_data_path): import pymake # init paths @@ -2115,7 +2117,7 @@ def test006_create_tests_gwf3_disv(tmpdir, example_data_path): exe_name="mf6", sim_ws=str(data_path), ) - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) tdis_rc = [(1.0, 1, 1.0)] tdis_package = ModflowTdis( sim, time_units="DAYS", nper=1, perioddata=tdis_rc @@ -2355,7 +2357,7 @@ def test006_create_tests_gwf3_disv(tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.write_simulation() @@ -2365,12 +2367,12 @@ def test006_create_tests_gwf3_disv(tmpdir, example_data_path): # inspect cells cell_list = [(0, 0), (0, 7), (0, 17)] - out_file = str(tmpdir / "inspect_test_gwf3_disv.csv") + out_file = str(function_tmpdir / "inspect_test_gwf3_disv.csv") model.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results - head_new = str(tmpdir / "flow.hds") - outfile = str(tmpdir / "head_compare.dat") + head_new = str(function_tmpdir / "flow.hds") + outfile = str(function_tmpdir / "head_compare.dat") assert pymake.compare_heads( None, None, @@ -2383,7 +2385,7 @@ def test006_create_tests_gwf3_disv(tmpdir, example_data_path): # model.export(os.path.join(run_folder, "test006_gwf3.nc")) # export to shape file - model.export(str(tmpdir / "test006_gwf3.shp")) + model.export(str(function_tmpdir / "test006_gwf3.shp")) # clean up sim.delete_output_files() @@ -2392,7 +2394,7 @@ def test006_create_tests_gwf3_disv(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test006_create_tests_2models_gnc(tmpdir, example_data_path): +def test006_create_tests_2models_gnc(function_tmpdir, example_data_path): import pymake # init paths @@ -2664,21 +2666,21 @@ def test006_create_tests_2models_gnc(tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.write_simulation() # test gnc file was created in correct location - gnc_full_path = str(tmpdir / gnc_path) + gnc_full_path = str(function_tmpdir / gnc_path) assert os.path.exists(gnc_full_path) # run simulation sim.run_simulation() # compare output to expected results - head_new = str(tmpdir / "model1.hds") - outfile = str(tmpdir / "head_compare.dat") + head_new = str(function_tmpdir / "model1.hds") + outfile = str(function_tmpdir / "head_compare.dat") assert pymake.compare_heads( None, None, @@ -2688,8 +2690,8 @@ def test006_create_tests_2models_gnc(tmpdir, example_data_path): ) # compare output to expected results - head_new = str(tmpdir / "model2.hds") - outfile = str(tmpdir / "head_compare.dat") + head_new = str(function_tmpdir / "model2.hds") + outfile = str(function_tmpdir / "head_compare.dat") assert pymake.compare_heads( None, None, @@ -2699,15 +2701,15 @@ def test006_create_tests_2models_gnc(tmpdir, example_data_path): ) # test external file paths - sim_path = str(tmpdir / "path_test") + sim_path = str(function_tmpdir / "path_test") sim.set_sim_path(sim_path) model_1.set_model_relative_path("model1") model_2.set_model_relative_path("model2") - sim.set_all_data_external(external_data_folder=tmpdir / "data") + sim.set_all_data_external(external_data_folder=function_tmpdir / "data") sim.write_simulation() - ext_file_path_1 = str(tmpdir / "data" / "model1.dis_botm.txt") + ext_file_path_1 = str(function_tmpdir / "data" / "model1.dis_botm.txt") assert os.path.exists(ext_file_path_1) - ext_file_path_2 = str(tmpdir / "data" / "model2.dis_botm.txt") + ext_file_path_2 = str(function_tmpdir / "data" / "model2.dis_botm.txt") assert os.path.exists(ext_file_path_2) # test gnc file was created in correct location gnc_full_path = os.path.join(sim_path, gnc_path) @@ -2717,7 +2719,7 @@ def test006_create_tests_2models_gnc(tmpdir, example_data_path): sim.delete_output_files() # test rename all packages - rename_folder = str(tmpdir / "rename") + rename_folder = str(function_tmpdir / "rename") sim.rename_all_packages("file_rename") sim.set_sim_path(rename_folder) sim.write_simulation() @@ -2733,7 +2735,7 @@ def test006_create_tests_2models_gnc(tmpdir, example_data_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test050_create_tests_circle_island(tmpdir, example_data_path): +def test050_create_tests_circle_island(function_tmpdir, example_data_path): import pymake # init paths @@ -2806,7 +2808,7 @@ def test050_create_tests_circle_island(tmpdir, example_data_path): ) # change folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.set_all_data_external() @@ -2816,8 +2818,8 @@ def test050_create_tests_circle_island(tmpdir, example_data_path): sim.run_simulation() # compare output to expected results - head_new = str(tmpdir / "ci.output.hds") - outfile = str(tmpdir / "head_compare.dat") + head_new = str(function_tmpdir / "ci.output.hds") + outfile = str(function_tmpdir / "head_compare.dat") assert pymake.compare_heads( None, None, @@ -2837,7 +2839,7 @@ def test050_create_tests_circle_island(tmpdir, example_data_path): "https://github.com/modflowpy/flopy/runs/7581629193?check_suite_focus=true#step:11:1753" ) @pytest.mark.regression -def test028_create_tests_sfr(tmpdir, example_data_path): +def test028_create_tests_sfr(function_tmpdir, example_data_path): import pymake # init paths @@ -3016,13 +3018,13 @@ def test028_create_tests_sfr(tmpdir, example_data_path): assert sfr_package.connectiondata.get_data()[2][1] == 1.0 assert sfr_package.packagedata.get_data()[1][1].lower() == "none" - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) sim.write_simulation() sim.load( sim_name=test_ex_name, version="mf6", exe_name="mf6", - sim_ws=str(tmpdir), + sim_ws=str(function_tmpdir), ) model = sim.get_model(model_name) sfr_package = model.get_package("sfr") @@ -3086,12 +3088,12 @@ def test028_create_tests_sfr(tmpdir, example_data_path): # inspect cells cell_list = [(0, 2, 3), (0, 3, 4), (0, 4, 5)] - out_file = str(tmpdir / "inspect_test028_sfr.csv") + out_file = str(function_tmpdir / "inspect_test028_sfr.csv") model.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results - head_new = str(tmpdir / "test1tr.hds") - outfile = str(tmpdir / "head_compare.dat") + head_new = str(function_tmpdir / "test1tr.hds") + outfile = str(function_tmpdir / "head_compare.dat") assert pymake.compare_heads( None, None, @@ -3108,7 +3110,7 @@ def test028_create_tests_sfr(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test_create_tests_transport(tmpdir, example_data_path): +def test_create_tests_transport(function_tmpdir, example_data_path): import pymake # init paths @@ -3148,7 +3150,7 @@ def test_create_tests_transport(tmpdir, example_data_path): sim_name=name, version="mf6", exe_name="mf6", - sim_ws=str(tmpdir), + sim_ws=str(function_tmpdir), ) # create tdis package tdis = ModflowTdis(sim, time_units="DAYS", nper=nper, perioddata=tdis_rc) @@ -3317,14 +3319,14 @@ def test_create_tests_transport(tmpdir, example_data_path): cell_list = [ (0, 0, 0), ] - out_file = str(tmpdir / "inspect_transport_gwf.csv") + out_file = str(function_tmpdir / "inspect_transport_gwf.csv") gwf.inspect_cells(cell_list, output_file_path=out_file) - out_file = str(tmpdir / "inspect_transport_gwt.csv") + out_file = str(function_tmpdir / "inspect_transport_gwt.csv") gwt.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results - head_new = str(tmpdir / "gwf_mst03.hds") - outfile = str(tmpdir / "head_compare.dat") + head_new = str(function_tmpdir / "gwf_mst03.hds") + outfile = str(function_tmpdir / "head_compare.dat") assert pymake.compare_heads( None, None, @@ -3332,7 +3334,7 @@ def test_create_tests_transport(tmpdir, example_data_path): files2=head_new, outfile=outfile, ) - conc_new = str(tmpdir / "gwt_mst03.ucn") + conc_new = str(function_tmpdir / "gwt_mst03.ucn") assert pymake.compare_concs( None, None, @@ -3349,7 +3351,7 @@ def test_create_tests_transport(tmpdir, example_data_path): @requires_pkg("pymake", "shapely") @pytest.mark.slow @pytest.mark.regression -def test001a_tharmonic(tmpdir, example_data_path): +def test001a_tharmonic(function_tmpdir, example_data_path): import pymake # init paths @@ -3383,13 +3385,13 @@ def test001a_tharmonic(tmpdir, example_data_path): verify_data=True, write_headers=False, ) - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.set_all_data_external(external_data_folder="data") sim.write_simulation(silent=True) # verify external data written to correct location - data_folder = str(tmpdir / "data" / "flow15.dis_botm.txt") + data_folder = str(function_tmpdir / "data" / "flow15.dis_botm.txt") assert os.path.exists(data_folder) # model export test model = sim.get_model(model_name) @@ -3412,7 +3414,7 @@ def test001a_tharmonic(tmpdir, example_data_path): ) # compare output to expected results - head_new = str(tmpdir / "flow15_flow.hds") + head_new = str(function_tmpdir / "flow15_flow.hds") assert pymake.compare_heads( None, None, files1=expected_head_file_a, files2=head_new ) @@ -3450,7 +3452,7 @@ def test001a_tharmonic(tmpdir, example_data_path): ) # write simulation again - save_folder = tmpdir / "save" + save_folder = function_tmpdir / "save" save_folder.mkdir() sim.set_sim_path(str(save_folder)) sim.write_simulation() @@ -3480,7 +3482,7 @@ def test001a_tharmonic(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test003_gwfs_disv(tmpdir, example_data_path): +def test003_gwfs_disv(function_tmpdir, example_data_path): import pymake # init paths @@ -3501,7 +3503,7 @@ def test003_gwfs_disv(tmpdir, example_data_path): ) # make temp folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.simulation_data.max_columns_of_data = 10 @@ -3517,7 +3519,7 @@ def test003_gwfs_disv(tmpdir, example_data_path): budget_obj.get_data(text=" FLOW JA FACE", full3D=True) ) - head_new = os.path.join(str(tmpdir), "model.hds") + head_new = os.path.join(str(function_tmpdir), "model.hds") assert pymake.compare_heads( None, None, files1=expected_head_file_a, files2=head_new ) @@ -3528,7 +3530,7 @@ def test003_gwfs_disv(tmpdir, example_data_path): assert array_util.array_comp(budget_fjf_valid, budget_frf) model = sim.get_model(model_name) - model.export(str(tmpdir / f"{test_ex_name}.shp")) + model.export(str(function_tmpdir / f"{test_ex_name}.shp")) # change some settings chd_head_left = model.get_package("CHD_LEFT") @@ -3543,7 +3545,7 @@ def test003_gwfs_disv(tmpdir, example_data_path): chd_right_period.set_data(chd_right_data_slice, 0) # write simulation again - save_folder = tmpdir / "save" + save_folder = function_tmpdir / "save" save_folder.mkdir() sim.set_sim_path(str(save_folder)) sim.write_simulation() @@ -3574,7 +3576,7 @@ def test003_gwfs_disv(tmpdir, example_data_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test005_advgw_tidal(tmpdir, example_data_path): +def test005_advgw_tidal(function_tmpdir, example_data_path): import pymake # init paths @@ -3616,7 +3618,7 @@ def test005_advgw_tidal(tmpdir, example_data_path): ghb.stress_period_data.set_data(spd) # make temp folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.set_all_data_external() @@ -3627,8 +3629,8 @@ def test005_advgw_tidal(tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = os.path.join(str(tmpdir), "advgw_tidal.hds") - outfile = os.path.join(str(tmpdir), "head_compare.dat") + head_new = os.path.join(str(function_tmpdir), "advgw_tidal.hds") + outfile = os.path.join(str(function_tmpdir), "head_compare.dat") assert pymake.compare_heads( None, None, @@ -3641,7 +3643,7 @@ def test005_advgw_tidal(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test006_gwf3(tmpdir, example_data_path): +def test006_gwf3(function_tmpdir, example_data_path): import pymake # init paths @@ -3660,7 +3662,7 @@ def test006_gwf3(tmpdir, example_data_path): sim = MFSimulation.load( model_name, "mf6", "mf6", str(pth), verify_data=True ) - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) model = sim.get_model() disu = model.get_package("disu") # test switching disu array to internal array @@ -3678,7 +3680,7 @@ def test006_gwf3(tmpdir, example_data_path): } # make temp folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.set_all_data_external() sim.write_simulation() @@ -3689,7 +3691,7 @@ def test006_gwf3(tmpdir, example_data_path): # inspect cells cell_list = [(0,), (7,), (14,)] - out_file = str(tmpdir / "inspect_test006_gwf3.csv") + out_file = str(function_tmpdir / "inspect_test006_gwf3.csv") model.inspect_cells(cell_list, output_file_path=out_file) budget_obj = CellBudgetFile(expected_cbc_file_a, precision="double") @@ -3700,7 +3702,7 @@ def test006_gwf3(tmpdir, example_data_path): budget_fjf_valid.shape = (-1, jaentries) # compare output to expected results - head_new = os.path.join(str(tmpdir), "flow.hds") + head_new = os.path.join(str(function_tmpdir), "flow.hds") assert pymake.compare_heads( None, None, @@ -3729,7 +3731,7 @@ def test006_gwf3(tmpdir, example_data_path): assert ex_happened # write simulation again - save_folder = tmpdir / "save" + save_folder = function_tmpdir / "save" save_folder.mkdir() sim.set_sim_path(str(save_folder)) sim.write_simulation() @@ -3763,7 +3765,7 @@ def test006_gwf3(tmpdir, example_data_path): ) # confirm that files did move - save_folder = tmpdir / "save02" + save_folder = function_tmpdir / "save02" save_folder.mkdir() sim.set_sim_path(str(save_folder)) @@ -3826,7 +3828,7 @@ def test006_gwf3(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test045_lake1ss_table(tmpdir, example_data_path): +def test045_lake1ss_table(function_tmpdir, example_data_path): import pymake # init paths @@ -3850,7 +3852,7 @@ def test045_lake1ss_table(tmpdir, example_data_path): ) # make temp folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.write_simulation() @@ -3860,8 +3862,8 @@ def test045_lake1ss_table(tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = str(tmpdir / "lakeex1b.hds") - outfile = str(tmpdir / "headcompare_a.txt") + head_new = str(function_tmpdir / "lakeex1b.hds") + outfile = str(function_tmpdir / "headcompare_a.txt") success = pymake.compare_heads( None, None, @@ -3880,7 +3882,7 @@ def test045_lake1ss_table(tmpdir, example_data_path): laktbl_data[-1][0] = 700.0 laktbl.set_data(laktbl_data) # write simulation again - save_folder = tmpdir / "save" + save_folder = function_tmpdir / "save" save_folder.mkdir() sim.set_sim_path(str(save_folder)) sim.write_simulation() @@ -3891,7 +3893,7 @@ def test045_lake1ss_table(tmpdir, example_data_path): # compare output to expected results head_new = str(save_folder / "lakeex1b.hds") - outfile = str(tmpdir / "headcompare_b.txt") + outfile = str(function_tmpdir / "headcompare_b.txt") success = pymake.compare_heads( None, None, @@ -3906,7 +3908,7 @@ def test045_lake1ss_table(tmpdir, example_data_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test006_2models_mvr(tmpdir, example_data_path): +def test006_2models_mvr(function_tmpdir, example_data_path): import pymake # init paths @@ -3915,7 +3917,7 @@ def test006_2models_mvr(tmpdir, example_data_path): model_names = ["parent", "child"] data_folder = example_data_path / "mf6" / test_ex_name # copy example data into working directory - ws = tmpdir / "ws" + ws = function_tmpdir / "ws" shutil.copytree(data_folder, ws) expected_output_folder = ws / "expected_output" @@ -4015,7 +4017,7 @@ def test006_2models_mvr(tmpdir, example_data_path): pkg_dict["dis"].nlay = old_val # write simulation again - save_folder = tmpdir / "save" + save_folder = function_tmpdir / "save" save_folder.mkdir() sim.set_sim_path(str(save_folder)) sim.write_simulation() @@ -4095,7 +4097,7 @@ def test006_2models_mvr(tmpdir, example_data_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test001e_uzf_3lay(tmpdir, example_data_path): +def test001e_uzf_3lay(function_tmpdir, example_data_path): # init paths test_ex_name = "test001e_UZF_3lay" model_name = "gwf_1" @@ -4107,7 +4109,7 @@ def test001e_uzf_3lay(tmpdir, example_data_path): ) # make temp folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.write_simulation() @@ -4126,7 +4128,7 @@ def test001e_uzf_3lay(tmpdir, example_data_path): uzf_data.set_data(uzf_array) # write simulation again - save_folder = tmpdir / "save" + save_folder = function_tmpdir / "save" save_folder.mkdir() sim.set_sim_path(str(save_folder)) sim.write_simulation() @@ -4137,7 +4139,7 @@ def test001e_uzf_3lay(tmpdir, example_data_path): # inspect cells cell_list = [(0, 0, 1), (0, 0, 2), (2, 0, 8)] - out_file = str(tmpdir / "inspect_test001e_uzf_3lay.csv") + out_file = str(function_tmpdir / "inspect_test001e_uzf_3lay.csv") model.inspect_cells(cell_list, output_file_path=out_file) # test load_only @@ -4152,7 +4154,7 @@ def test001e_uzf_3lay(tmpdir, example_data_path): sim = MFSimulation.load( model_name, "mf6", "mf6", str(pth), load_only=load_only ) - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) model = sim.get_model() for package in model_package_check: assert (package in model.package_type_dict) == ( @@ -4162,17 +4164,19 @@ def test001e_uzf_3lay(tmpdir, example_data_path): sim = MFSimulation.load( model_name, "mf6", "mf6", str(pth), load_only=load_only_lists[0] ) - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) success, buff = sim.run_simulation() assert success, f"simulation {sim.name} from load did not run" cbc = CellBudgetFile( - str(tmpdir / "test001e_UZF_3lay.uzf.cbc"), precision="auto" + str(function_tmpdir / "test001e_UZF_3lay.uzf.cbc"), precision="auto" ) data = cbc.get_data(text="GWF", full3D=False) assert data[2].node[0] == 1, "Budget precision error for imeth 6" - sim = MFSimulation.load("mfsim", sim_ws=str(tmpdir), exe_name="mf6") + sim = MFSimulation.load( + "mfsim", sim_ws=str(function_tmpdir), exe_name="mf6" + ) ims = sim.ims sim.remove_package(ims) @@ -4194,7 +4198,7 @@ def test001e_uzf_3lay(tmpdir, example_data_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test045_lake2tr(tmpdir, example_data_path): +def test045_lake2tr(function_tmpdir, example_data_path): import pymake # init paths @@ -4211,7 +4215,7 @@ def test045_lake2tr(tmpdir, example_data_path): ) # write simulation to new location - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) sim.write_simulation() # run simulation @@ -4219,7 +4223,7 @@ def test045_lake2tr(tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = str(tmpdir / "lakeex2a.hds") + head_new = str(function_tmpdir / "lakeex2a.hds") assert pymake.compare_heads( None, None, @@ -4240,7 +4244,7 @@ def test045_lake2tr(tmpdir, example_data_path): lak_period.set_data(lak_period_data[0], 0) # write simulation again - save_folder = tmpdir / "save" + save_folder = function_tmpdir / "save" save_folder.mkdir() sim.set_sim_path(str(save_folder)) sim.write_simulation() @@ -4251,7 +4255,7 @@ def test045_lake2tr(tmpdir, example_data_path): # inspect cells cell_list = [(0, 6, 5), (0, 8, 5), (1, 18, 6)] - out_file = str(tmpdir / "inspect_test045_lake2tr.csv") + out_file = str(function_tmpdir / "inspect_test045_lake2tr.csv") model.inspect_cells(cell_list, output_file_path=out_file) # compare output to expected results @@ -4268,7 +4272,7 @@ def test045_lake2tr(tmpdir, example_data_path): @requires_exe("mf6") @requires_pkg("pymake") @pytest.mark.regression -def test036_twrihfb(tmpdir, example_data_path): +def test036_twrihfb(function_tmpdir, example_data_path): import pymake # init paths @@ -4287,7 +4291,7 @@ def test036_twrihfb(tmpdir, example_data_path): sim = MFSimulation.load(model_name, "mf6", "mf6", pth, verify_data=True) # make temp folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.set_all_data_external() @@ -4298,7 +4302,7 @@ def test036_twrihfb(tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = str(tmpdir / "twrihfb2015_output.hds") + head_new = str(function_tmpdir / "twrihfb2015_output.hds") assert pymake.compare_heads( None, None, @@ -4330,7 +4334,7 @@ def test036_twrihfb(tmpdir, example_data_path): assert rch_data[0][5, 1] == 0.00000003 # write simulation again - save_folder = tmpdir / "save" + save_folder = function_tmpdir / "save" save_folder.mkdir() sim.set_sim_path(str(save_folder)) sim.write_simulation() @@ -4353,7 +4357,7 @@ def test036_twrihfb(tmpdir, example_data_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test027_timeseriestest(tmpdir, example_data_path): +def test027_timeseriestest(function_tmpdir, example_data_path): import pymake # init paths @@ -4372,7 +4376,7 @@ def test027_timeseriestest(tmpdir, example_data_path): sim = MFSimulation.load(model_name, "mf6", "mf6", pth, verify_data=True) # make temp folder to save simulation - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write simulation to new location sim.set_all_data_external() @@ -4380,7 +4384,7 @@ def test027_timeseriestest(tmpdir, example_data_path): # reload sim sim = MFSimulation.load( - model_name, "mf6", "mf6", str(tmpdir), verify_data=True + model_name, "mf6", "mf6", str(function_tmpdir), verify_data=True ) sim.write_simulation() @@ -4389,8 +4393,8 @@ def test027_timeseriestest(tmpdir, example_data_path): assert success, f"simulation {sim.name} did not run" # compare output to expected results - head_new = str(tmpdir / "timeseriestest.hds") - outfile = str(tmpdir / "head_compare.dat") + head_new = str(function_tmpdir / "timeseriestest.hds") + outfile = str(function_tmpdir / "head_compare.dat") assert pymake.compare_heads( None, None, @@ -4409,7 +4413,7 @@ def test027_timeseriestest(tmpdir, example_data_path): tas_rch.tas_array.set_data(tas_array_data, key=12.0) # write simulation again - save_folder = tmpdir / "save" + save_folder = function_tmpdir / "save" save_folder.mkdir() sim.set_sim_path(str(save_folder)) sim.write_simulation() diff --git a/autotest/regression/test_mf6_examples.py b/autotest/regression/test_mf6_examples.py index 0b9818c792..664ffb7046 100644 --- a/autotest/regression/test_mf6_examples.py +++ b/autotest/regression/test_mf6_examples.py @@ -2,8 +2,8 @@ from shutil import copytree import pytest -from autotest.conftest import requires_exe, requires_pkg from autotest.regression.conftest import is_nested +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.mf6 import MFSimulation @@ -14,13 +14,13 @@ @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test_mf6_example_simulations(tmpdir, mf6_example_namfiles): +def test_mf6_example_simulations(function_tmpdir, mf6_example_namfiles): # MF6 examples parametrized by simulation. `mf6_example_namfiles` is a list # of models to run in order provided. Coupled models share the same tempdir # # Parameters # ---------- - # tmpdir: function-scoped temporary directory fixture + # function_tmpdir: function-scoped temporary directory fixture # mf6_example_namfiles: ordered list of namfiles for 1+ coupled models import pymake @@ -33,14 +33,15 @@ def test_mf6_example_simulations(tmpdir, mf6_example_namfiles): # coupled models have nested dirs (e.g., 'mf6gwf' and 'mf6gwt') under model directory # TODO: are there multiple types of couplings? e.g. besides GWF-GWT, mt3dms? nested = is_nested(namfile) - tmpdir = Path( - tmpdir / "workspace" + function_tmpdir = Path( + function_tmpdir / "workspace" ) # working directory (must not exist for copytree) - cmpdir = tmpdir / "compare" # comparison directory + cmpdir = function_tmpdir / "compare" # comparison directory # copy model files into working directory copytree( - src=namfile.parent.parent if nested else namfile.parent, dst=tmpdir + src=namfile.parent.parent if nested else namfile.parent, + dst=function_tmpdir, ) def run_models(): @@ -52,7 +53,11 @@ def run_models(): # working directory must be named according to the name file's parent (e.g. # 'mf6gwf') because coupled models refer to each other with relative paths - wrkdir = Path(tmpdir / model_path.name) if nested else tmpdir + wrkdir = ( + Path(function_tmpdir / model_path.name) + if nested + else function_tmpdir + ) # load simulation sim = MFSimulation.load( diff --git a/autotest/regression/test_mfnwt.py b/autotest/regression/test_mfnwt.py index 5b3eda1158..7b2ac4ee25 100644 --- a/autotest/regression/test_mfnwt.py +++ b/autotest/regression/test_mfnwt.py @@ -1,7 +1,8 @@ import os import pytest -from autotest.conftest import get_example_data_path, requires_exe, requires_pkg +from autotest.conftest import get_example_data_path +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.modflow import Modflow, ModflowNwt, ModflowUpw from flopy.utils import parsenamefile @@ -31,7 +32,7 @@ def get_nfnwt_namfiles(): @pytest.mark.slow @pytest.mark.regression @pytest.mark.parametrize("namfile", get_nfnwt_namfiles()) -def test_run_mfnwt_model(tmpdir, namfile): +def test_run_mfnwt_model(function_tmpdir, namfile): import pymake # load a MODFLOW-2005 model, convert to a MFNWT model, @@ -108,16 +109,16 @@ def test_run_mfnwt_model(tmpdir, namfile): wel.iunitramp = 2 # change workspace and write MODFLOW-NWT model - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) m.write_input() success, buff = m.run_model(silent=False) assert success, "base model run did not terminate successfully" - fn0 = str(tmpdir / namfile) + fn0 = str(function_tmpdir / namfile) # reload the model just written m = Modflow.load( namfile, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), version="mfnwt", verbose=True, check=False, @@ -127,19 +128,19 @@ def test_run_mfnwt_model(tmpdir, namfile): assert m.load_fail is False # change workspace and write MODFLOW-NWT model - pthf = str(tmpdir / "flopy") + pthf = str(function_tmpdir / "flopy") m.change_model_ws(pthf) m.write_input() success, buff = m.run_model(silent=False) assert success, "base model run did not terminate successfully" fn1 = os.path.join(pthf, namfile) - fsum = str(tmpdir / f"{base_name}.head.out") + fsum = str(function_tmpdir / f"{base_name}.head.out") assert pymake.compare_heads( fn0, fn1, outfile=fsum ), "head comparison failure" - fsum = str(tmpdir / f"{base_name}.budget.out") + fsum = str(function_tmpdir / f"{base_name}.budget.out") assert pymake.compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum ), "budget comparison failure" diff --git a/autotest/regression/test_modflow.py b/autotest/regression/test_modflow.py index 98e5e142bb..4daf494d75 100644 --- a/autotest/regression/test_modflow.py +++ b/autotest/regression/test_modflow.py @@ -4,7 +4,8 @@ from shutil import copytree import pytest -from autotest.conftest import get_example_data_path, requires_exe, requires_pkg +from autotest.conftest import get_example_data_path +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.modflow import Modflow, ModflowOc @@ -23,11 +24,11 @@ def uzf_example_path(example_data_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test_uzf_unit_numbers(tmpdir, uzf_example_path): +def test_uzf_unit_numbers(function_tmpdir, uzf_example_path): import pymake mfnam = "UZFtest2.nam" - ws = str(tmpdir / "ws") + ws = str(function_tmpdir / "ws") copytree(uzf_example_path, ws) m = Modflow.load( @@ -74,7 +75,7 @@ def test_uzf_unit_numbers(tmpdir, uzf_example_path): fn1 = join(model_ws2, mfnam) # compare budget terms - fsum = join(str(tmpdir), f"{splitext(mfnam)[0]}.budget.out") + fsum = join(str(function_tmpdir), f"{splitext(mfnam)[0]}.budget.out") success = pymake.compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum ) @@ -85,11 +86,11 @@ def test_uzf_unit_numbers(tmpdir, uzf_example_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test_unitnums(tmpdir, mf2005_test_path): +def test_unitnums(function_tmpdir, mf2005_test_path): import pymake mfnam = "testsfr2_tab.nam" - ws = str(tmpdir / "ws") + ws = str(function_tmpdir / "ws") copytree(mf2005_test_path, ws) m = Modflow.load(mfnam, verbose=True, model_ws=ws, exe_name="mf2005") @@ -126,7 +127,7 @@ def test_unitnums(tmpdir, mf2005_test_path): @requires_pkg("pymake") @pytest.mark.slow @pytest.mark.regression -def test_gage(tmpdir, example_data_path): +def test_gage(function_tmpdir, example_data_path): """ test043 load and write of MODFLOW-2005 GAGE example problem """ @@ -134,7 +135,7 @@ def test_gage(tmpdir, example_data_path): pth = str(example_data_path / "mf2005_test") fpth = join(pth, "testsfr2_tab.nam") - ws = str(tmpdir / "ws") + ws = str(function_tmpdir / "ws") copytree(pth, ws) # load the modflow model @@ -181,10 +182,10 @@ def test_gage(tmpdir, example_data_path): for nf in ["twri.nam", "MNW2.nam"] ], ) -def test_mf2005pcgn(tmpdir, namfile): +def test_mf2005pcgn(function_tmpdir, namfile): import pymake - ws = tmpdir / "ws" + ws = function_tmpdir / "ws" copytree(Path(namfile).parent, ws) nf = Path(namfile).name @@ -205,7 +206,7 @@ def test_mf2005pcgn(tmpdir, namfile): fn0 = str(ws / nf) # rewrite files - ws2 = tmpdir / "ws2" + ws2 = function_tmpdir / "ws2" m.change_model_ws(str(ws2)) m.write_input() @@ -213,11 +214,11 @@ def test_mf2005pcgn(tmpdir, namfile): assert success, "new model run did not terminate successfully" fn1 = str(ws2 / nf) - fsum = str(tmpdir / f"{Path(namfile).stem}.head.out") + fsum = str(function_tmpdir / f"{Path(namfile).stem}.head.out") success = pymake.compare_heads(fn0, fn1, outfile=fsum, htol=0.005) assert success, "head comparison failure" - fsum = str(tmpdir / f"{Path(namfile).stem}.budget.out") + fsum = str(function_tmpdir / f"{Path(namfile).stem}.budget.out") success = pymake.compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum ) @@ -231,10 +232,10 @@ def test_mf2005pcgn(tmpdir, namfile): @pytest.mark.parametrize( "namfile", [str(__example_data_path / "secp" / nf) for nf in ["secp.nam"]] ) -def test_mf2005gmg(tmpdir, namfile): +def test_mf2005gmg(function_tmpdir, namfile): import pymake - ws = tmpdir / "ws" + ws = function_tmpdir / "ws" copytree(Path(namfile).parent, ws) nf = Path(namfile).name @@ -251,18 +252,18 @@ def test_mf2005gmg(tmpdir, namfile): fn0 = str(ws / nf) # rewrite files - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) m.write_input() success, buff = m.run_model(silent=False) assert success, "new model run did not terminate successfully" - fn1 = str(tmpdir / nf) + fn1 = str(function_tmpdir / nf) - fsum = str(tmpdir / f"{Path(namfile).stem}.head.out") + fsum = str(function_tmpdir / f"{Path(namfile).stem}.head.out") success = pymake.compare_heads(fn0, fn1, outfile=fsum) assert success, "head comparison failure" - fsum = str(tmpdir / f"{Path(namfile).stem}.budget.out") + fsum = str(function_tmpdir / f"{Path(namfile).stem}.budget.out") success = pymake.compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum ) @@ -276,14 +277,14 @@ def test_mf2005gmg(tmpdir, namfile): "namfile", [str(__example_data_path / "freyberg" / nf) for nf in ["freyberg.nam"]], ) -def test_mf2005(tmpdir, namfile): +def test_mf2005(function_tmpdir, namfile): """ test045 load and write of MODFLOW-2005 GMG example problem """ import pymake - compth = tmpdir / "flopy" - ws = tmpdir / "ws" + compth = function_tmpdir / "flopy" + ws = function_tmpdir / "ws" copytree(Path(namfile).parent, str(ws)) m = Modflow.load( @@ -357,10 +358,10 @@ def test_mf2005(tmpdir, namfile): @pytest.mark.slow @pytest.mark.regression @pytest.mark.parametrize("namfile", mf2005_namfiles) -def test_mf2005fhb(tmpdir, namfile): +def test_mf2005fhb(function_tmpdir, namfile): import pymake - ws = str(tmpdir / "ws") + ws = str(function_tmpdir / "ws") copytree(Path(namfile).parent, ws) m = Modflow.load( @@ -373,12 +374,12 @@ def test_mf2005fhb(tmpdir, namfile): fn0 = join(ws, Path(namfile).name) # rewrite files - m.change_model_ws(str(tmpdir), reset_external=True) + m.change_model_ws(str(function_tmpdir), reset_external=True) m.write_input() success, buff = m.run_model() assert success, "new model run did not terminate successfully" - fn1 = join(str(tmpdir), Path(namfile).name) + fn1 = join(str(function_tmpdir), Path(namfile).name) fsum = join(ws, f"{Path(namfile).stem}.head.out") success = pymake.compare_heads(fn0, fn1, outfile=fsum) @@ -396,10 +397,10 @@ def test_mf2005fhb(tmpdir, namfile): @pytest.mark.slow @pytest.mark.regression @pytest.mark.parametrize("namfile", mf2005_namfiles) -def test_mf2005_lake(tmpdir, namfile, mf2005_test_path): +def test_mf2005_lake(function_tmpdir, namfile, mf2005_test_path): import pymake - ws = str(tmpdir / "ws") + ws = str(function_tmpdir / "ws") copytree(mf2005_test_path, ws) m = Modflow.load( diff --git a/autotest/regression/test_str.py b/autotest/regression/test_str.py index 6cebfbb0a5..0ad095c28e 100644 --- a/autotest/regression/test_str.py +++ b/autotest/regression/test_str.py @@ -1,5 +1,5 @@ import pytest -from autotest.conftest import requires_exe, requires_pkg +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.modflow import Modflow, ModflowOc, ModflowStr @@ -15,7 +15,7 @@ @requires_exe("mf2005") @requires_pkg("pymake") @pytest.mark.regression -def test_str_fixed_free(tmpdir, example_data_path): +def test_str_fixed_free(function_tmpdir, example_data_path): import pymake mf2005_model_path = example_data_path / "mf2005_test" @@ -27,7 +27,7 @@ def test_str_fixed_free(tmpdir, example_data_path): verbose=False, check=False, ) - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) # get pointer to str package mstr = m.str @@ -94,10 +94,10 @@ def test_str_fixed_free(tmpdir, example_data_path): m2 is not None ), "could not load the fixed format model with aux variables" - for p in tmpdir.glob("*"): + for p in function_tmpdir.glob("*"): p.unlink() - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) m.set_ifrefm() m.write_input() @@ -109,7 +109,7 @@ def test_str_fixed_free(tmpdir, example_data_path): m2 = Modflow.load( str_items[0]["mfnam"], exe_name="mf2005", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), verbose=False, check=False, ) @@ -121,8 +121,8 @@ def test_str_fixed_free(tmpdir, example_data_path): ), "could not load the free format model with aux variables" # compare the fixed and free format head files - fn1 = str(tmpdir / "str.nam") - fn2 = str(tmpdir / "str.nam") + fn1 = str(function_tmpdir / "str.nam") + fn2 = str(function_tmpdir / "str.nam") assert pymake.compare_heads( fn1, fn2, verbose=True ), "fixed and free format input output head files are different" diff --git a/autotest/regression/test_swi2.py b/autotest/regression/test_swi2.py index 4f738bd5e5..8a37df8af6 100644 --- a/autotest/regression/test_swi2.py +++ b/autotest/regression/test_swi2.py @@ -2,7 +2,7 @@ import shutil import pytest -from autotest.conftest import requires_exe, requires_pkg +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.modflow import Modflow @@ -19,11 +19,11 @@ def swi_path(example_data_path): @pytest.mark.parametrize( "namfile", ["swiex1.nam", "swiex2_strat.nam", "swiex3.nam"] ) -def test_mf2005swi2(tmpdir, swi_path, namfile): +def test_mf2005swi2(function_tmpdir, swi_path, namfile): import pymake name = namfile.replace(".nam", "") - ws = str(tmpdir / "ws") + ws = str(function_tmpdir / "ws") shutil.copytree(swi_path, ws) m = Modflow.load(namfile, model_ws=ws, verbose=True, exe_name="mf2005") diff --git a/autotest/regression/test_wel.py b/autotest/regression/test_wel.py index ea3c917233..0af16e34d9 100644 --- a/autotest/regression/test_wel.py +++ b/autotest/regression/test_wel.py @@ -2,7 +2,7 @@ import numpy as np import pytest -from autotest.conftest import requires_exe, requires_pkg +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.modflow import ( Modflow, @@ -18,7 +18,7 @@ @requires_exe("mf2005") @requires_pkg("pymake") @pytest.mark.regression -def test_binary_well(tmpdir): +def test_binary_well(function_tmpdir): import pymake nlay = 3 @@ -27,7 +27,7 @@ def test_binary_well(tmpdir): mfnam = "t1" ml = Modflow( modelname=mfnam, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), verbose=True, exe_name="mf2005", ) @@ -62,12 +62,12 @@ def test_binary_well(tmpdir): # run the modflow-2005 model success, buff = ml.run_model(silent=False) assert success, "could not run MODFLOW-2005 model" - fn0 = os.path.join(str(tmpdir), f"{mfnam}.nam") + fn0 = os.path.join(str(function_tmpdir), f"{mfnam}.nam") # load the model m = Modflow.load( f"{mfnam}.nam", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), verbose=True, exe_name="mf2005", ) @@ -79,7 +79,7 @@ def test_binary_well(tmpdir): ) # change model work space - pth = os.path.join(str(tmpdir), "flopy") + pth = os.path.join(str(function_tmpdir), "flopy") m.change_model_ws(new_pth=pth) # remove the existing well package @@ -99,13 +99,15 @@ def test_binary_well(tmpdir): fn1 = os.path.join(pth, f"{mfnam}.nam") # compare the files - fsum = os.path.join(str(tmpdir), f"{os.path.splitext(mfnam)[0]}.head.out") + fsum = os.path.join( + str(function_tmpdir), f"{os.path.splitext(mfnam)[0]}.head.out" + ) assert pymake.compare_heads( fn0, fn1, outfile=fsum ), "head comparison failure" fsum = os.path.join( - str(tmpdir), f"{os.path.splitext(mfnam)[0]}.budget.out" + str(function_tmpdir), f"{os.path.splitext(mfnam)[0]}.budget.out" ) assert pymake.compare_budget( fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum diff --git a/autotest/test_binaryfile.py b/autotest/test_binaryfile.py index 2dada82a51..47c59603d6 100644 --- a/autotest/test_binaryfile.py +++ b/autotest/test_binaryfile.py @@ -21,11 +21,11 @@ def nwt_model_path(example_data_path): return example_data_path / "nwt_test" -def test_binaryfile_writeread(tmpdir, nwt_model_path): +def test_binaryfile_writeread(function_tmpdir, nwt_model_path): model = "Pr3_MFNWT_lower.nam" ml = Modflow.load(model, version="mfnwt", model_ws=str(nwt_model_path)) # change the model work space - ml.change_model_ws(str(tmpdir)) + ml.change_model_ws(str(function_tmpdir)) # ncol = ml.dis.ncol nrow = ml.dis.nrow @@ -46,7 +46,7 @@ def test_binaryfile_writeread(tmpdir, nwt_model_path): kper=1, ) b = ml.dis.botm.array[0, :, :].astype(np.float64) - pth = str(tmpdir / "bottom.hds") + pth = str(function_tmpdir / "bottom.hds") Util2d.write_bin(b.shape, pth, b, header_data=header) bo = HeadFile(pth, precision=precision) @@ -76,7 +76,7 @@ def test_binaryfile_writeread(tmpdir, nwt_model_path): kper=1, ) b = ml.dis.botm.array[0, :, :].astype(np.float32) - pth = str(tmpdir / "bottom_single.hds") + pth = str(function_tmpdir / "bottom_single.hds") Util2d.write_bin(b.shape, pth, b, header_data=header) bo = HeadFile(pth, precision=precision) @@ -117,7 +117,7 @@ def test_plot_binary_head_file(example_data_path): plt.close() -def test_headu_file_data(tmpdir, example_data_path): +def test_headu_file_data(function_tmpdir, example_data_path): fname = str(example_data_path / "unstructured" / "headu.githds") headobj = HeadUFile(fname) assert isinstance(headobj, HeadUFile) @@ -157,18 +157,24 @@ def test_headufile_get_ts(example_data_path): for i in range(0, nnodes, 100): heads.get_ts(idx=i) with pytest.raises(IndexError): - heads.get_ts(idx=i+100) + heads.get_ts(idx=i + 100) # ...and retrieved in groups for i in range(10): heads.get_ts([i, i + 1, i + 2]) - heads = HeadUFile(example_data_path / "mfusg_test" / "01A_nestedgrid_nognc" / "output" / "flow.hds") + heads = HeadUFile( + example_data_path + / "mfusg_test" + / "01A_nestedgrid_nognc" + / "output" + / "flow.hds" + ) nnodes = 121 for i in range(nnodes): heads.get_ts(idx=i) with pytest.raises(IndexError): - heads.get_ts(idx=i+1) + heads.get_ts(idx=i + 1) # ...and retrieved in groups for i in range(10): diff --git a/autotest/test_cbc_full3D.py b/autotest/test_cbc_full3D.py index d8fa6453f5..581d17b1ce 100644 --- a/autotest/test_cbc_full3D.py +++ b/autotest/test_cbc_full3D.py @@ -3,7 +3,8 @@ import numpy as np import pytest -from autotest.conftest import get_example_data_path, requires_exe +from autotest.conftest import get_example_data_path +from modflow_devtools.markers import requires_exe from flopy.mf6 import MFSimulation, ModflowGwfoc from flopy.modflow import Modflow @@ -122,8 +123,8 @@ def cbc_eval(cbcobj, nnodes, shape3d, modelgrid): @requires_exe("mf6") @pytest.mark.mf6 @pytest.mark.parametrize("path", mf6_paths) -def test_cbc_full3D_mf6(tmpdir, path): - sim = load_mf6(path, str(tmpdir)) +def test_cbc_full3D_mf6(function_tmpdir, path): + sim = load_mf6(path, str(function_tmpdir)) # write the simulation sim.write_simulation() @@ -145,8 +146,8 @@ def test_cbc_full3D_mf6(tmpdir, path): @requires_exe("mf2005") @pytest.mark.parametrize("path", mf2005_paths) -def test_cbc_full3D_mf2005(tmpdir, path): - ml = load_mf2005(path, str(tmpdir)) +def test_cbc_full3D_mf2005(function_tmpdir, path): + ml = load_mf2005(path, str(function_tmpdir)) # write the model ml.write_input() @@ -158,7 +159,7 @@ def test_cbc_full3D_mf2005(tmpdir, path): nnodes, shape3d = ml.modelgrid.nnodes, ml.modelgrid.shape # get the cell by cell object - fpth = os.path.join(str(tmpdir), f"{Path(path).name}.cbc") + fpth = os.path.join(str(function_tmpdir), f"{Path(path).name}.cbc") cbc = CellBudgetFile(fpth) # evaluate the full3D option diff --git a/autotest/test_conftest.py b/autotest/test_conftest.py index e7754f303c..1085e59ba1 100644 --- a/autotest/test_conftest.py +++ b/autotest/test_conftest.py @@ -6,79 +6,14 @@ import pytest from _pytest.config import ExitCode -from autotest.conftest import ( +from autotest.conftest import get_example_data_path, get_project_root_path +from modflow_devtools.markers import ( excludes_platform, - get_example_data_path, - get_project_root_path, requires_exe, requires_pkg, requires_platform, ) -# temporary directory fixtures - - -def test_tmpdirs(tmpdir, module_tmpdir): - # function-scoped temporary directory - assert isinstance(tmpdir, Path) - assert tmpdir.is_dir() - assert inspect.currentframe().f_code.co_name in tmpdir.stem - - # module-scoped temp dir (accessible to other tests in the script) - assert module_tmpdir.is_dir() - assert "autotest" in module_tmpdir.stem - - -def test_function_scoped_tmpdir(tmpdir): - assert isinstance(tmpdir, Path) - assert tmpdir.is_dir() - assert inspect.currentframe().f_code.co_name in tmpdir.stem - - -@pytest.mark.parametrize("name", ["noslash", "forward/slash", "back\\slash"]) -def test_function_scoped_tmpdir_slash_in_name(tmpdir, name): - assert isinstance(tmpdir, Path) - assert tmpdir.is_dir() - - # node name might have slashes if test function is parametrized - # (e.g., test_function_scoped_tmpdir_slash_in_name[a/slash]) - replaced1 = name.replace("/", "_").replace("\\", "_").replace(":", "_") - replaced2 = name.replace("/", "_").replace("\\", "__").replace(":", "_") - assert ( - f"{inspect.currentframe().f_code.co_name}[{replaced1}]" in tmpdir.stem - or f"{inspect.currentframe().f_code.co_name}[{replaced2}]" - in tmpdir.stem - ) - - -class TestClassScopedTmpdir: - filename = "hello.txt" - - @pytest.fixture(autouse=True) - def setup(self, class_tmpdir): - with open(class_tmpdir / self.filename, "w") as file: - file.write("hello, class-scoped tmpdir") - - def test_class_scoped_tmpdir(self, class_tmpdir): - assert isinstance(class_tmpdir, Path) - assert class_tmpdir.is_dir() - assert self.__class__.__name__ in class_tmpdir.stem - assert Path(class_tmpdir / self.filename).is_file() - - -def test_module_scoped_tmpdir(module_tmpdir): - assert isinstance(module_tmpdir, Path) - assert module_tmpdir.is_dir() - assert Path(inspect.getmodulename(__file__)).stem in module_tmpdir.name - - -def test_session_scoped_tmpdir(session_tmpdir): - assert isinstance(session_tmpdir, Path) - assert session_tmpdir.is_dir() - - -# misc utilities - def test_get_project_root_path(): root = get_project_root_path() @@ -89,215 +24,13 @@ def test_get_project_root_path(): assert "autotest" in contents and "README.md" in contents -def test_get_paths(): - example_data = get_example_data_path() - project_root = get_project_root_path() - - assert example_data.parent.parent == project_root - - def test_get_example_data_path(): parts = get_example_data_path().parts assert parts[-2:] == ("examples", "data") -# requiring/excluding executables & platforms - - -@requires_exe("mf6") -def test_mf6(): - assert which("mf6") - - -exes = ["mfusg", "mfnwt"] - - -@requires_exe(*exes) -def test_mfusg_and_mfnwt(): - assert all(which(exe) for exe in exes) - - -@requires_pkg("numpy") -def test_numpy(): - import numpy - - assert numpy is not None - - -@requires_pkg("numpy", "matplotlib") -def test_numpy_and_matplotlib(): - import matplotlib - import numpy - - assert numpy is not None and matplotlib is not None - - -@requires_platform("Windows") -def test_needs_windows(): - assert platform.system() == "Windows" - - -@excludes_platform("Darwin", ci_only=True) -def test_breaks_osx_ci(): - if "CI" in os.environ: - assert platform.system() != "Darwin" - - -# meta-test marker and CLI argument --meta (-M) - - -@pytest.mark.meta("test_meta") -def test_meta_inner(): - pass - - -class TestMeta: - def pytest_terminal_summary(self, terminalreporter): - stats = terminalreporter.stats - assert "failed" not in stats - - passed = [test.head_line for test in stats["passed"]] - assert len(passed) == 1 - assert test_meta_inner.__name__ in passed - - deselected = [fn.name for fn in stats["deselected"]] - assert len(deselected) > 0 - - -def test_meta(): - args = [ - f"{__file__}", - "-v", - "-s", - "-k", - test_meta_inner.__name__, - "-M", - "test_meta", - ] - assert pytest.main(args, plugins=[TestMeta()]) == ExitCode.OK - - -# CLI arguments --keep (-K) and --keep-failed - -FILE_NAME = "hello.txt" - - -@pytest.mark.meta("test_keep") -def test_keep_function_scoped_tmpdir_inner(tmpdir): - with open(tmpdir / FILE_NAME, "w") as f: - f.write("hello, function-scoped tmpdir") - - -@pytest.mark.meta("test_keep") -class TestKeepClassScopedTmpdirInner: - def test_keep_class_scoped_tmpdir_inner(self, class_tmpdir): - with open(class_tmpdir / FILE_NAME, "w") as f: - f.write("hello, class-scoped tmpdir") - - -@pytest.mark.meta("test_keep") -def test_keep_module_scoped_tmpdir_inner(module_tmpdir): - with open(module_tmpdir / FILE_NAME, "w") as f: - f.write("hello, module-scoped tmpdir") - - -@pytest.mark.meta("test_keep") -def test_keep_session_scoped_tmpdir_inner(session_tmpdir): - with open(session_tmpdir / FILE_NAME, "w") as f: - f.write("hello, session-scoped tmpdir") - - -@pytest.mark.parametrize("arg", ["--keep", "-K"]) -def test_keep_function_scoped_tmpdir(tmpdir, arg): - inner_fn = test_keep_function_scoped_tmpdir_inner.__name__ - args = [ - __file__, - "-v", - "-s", - "-k", - inner_fn, - "-M", - "test_keep", - "-K", - tmpdir, - ] - assert pytest.main(args) == ExitCode.OK - assert Path(tmpdir / f"{inner_fn}0" / FILE_NAME).is_file() - - -@pytest.mark.parametrize("arg", ["--keep", "-K"]) -def test_keep_class_scoped_tmpdir(tmpdir, arg): - args = [ - __file__, - "-v", - "-s", - "-k", - TestKeepClassScopedTmpdirInner.test_keep_class_scoped_tmpdir_inner.__name__, - "-M", - "test_keep", - "-K", - tmpdir, - ] - assert pytest.main(args) == ExitCode.OK - assert Path( - tmpdir / f"{TestKeepClassScopedTmpdirInner.__name__}0" / FILE_NAME - ).is_file() - - -@pytest.mark.parametrize("arg", ["--keep", "-K"]) -def test_keep_module_scoped_tmpdir(tmpdir, arg): - args = [ - __file__, - "-v", - "-s", - "-k", - test_keep_module_scoped_tmpdir_inner.__name__, - "-M", - "test_keep", - "-K", - tmpdir, - ] - assert pytest.main(args) == ExitCode.OK - this_file_path = Path(__file__) - this_test_dir = ( - tmpdir - / f"{str(this_file_path.parent.name)}.{str(this_file_path.stem)}0" - ) - assert FILE_NAME in [f.name for f in this_test_dir.glob("*")] - - -@pytest.mark.parametrize("arg", ["--keep", "-K"]) -def test_keep_session_scoped_tmpdir(tmpdir, arg, request): - args = [ - __file__, - "-v", - "-s", - "-k", - test_keep_session_scoped_tmpdir_inner.__name__, - "-M", - "test_keep", - "-K", - tmpdir, - ] - assert pytest.main(args) == ExitCode.OK - assert Path(tmpdir / f"{request.session.name}0" / FILE_NAME).is_file() - - -@pytest.mark.meta("test_keep_failed") -def test_keep_failed_function_scoped_tmpdir_inner(tmpdir): - with open(tmpdir / FILE_NAME, "w") as f: - f.write("hello, function-scoped tmpdir") - - assert False, "oh no" - - -@pytest.mark.parametrize("keep", [True, False]) -def test_keep_failed_function_scoped_tmpdir(tmpdir, keep): - inner_fn = test_keep_failed_function_scoped_tmpdir_inner.__name__ - args = [__file__, "-v", "-s", "-k", inner_fn, "-M", "test_keep_failed"] - if keep: - args += ["--keep-failed", tmpdir] - assert pytest.main(args) == ExitCode.TESTS_FAILED +def test_get_paths(): + example_data = get_example_data_path() + project_root = get_project_root_path() - kept_file = Path(tmpdir / f"{inner_fn}0" / FILE_NAME).is_file() - assert kept_file if keep else not kept_file + assert example_data.parent.parent == project_root diff --git a/autotest/test_example_notebooks.py b/autotest/test_example_notebooks.py index 9adbf94348..f79f3a3791 100644 --- a/autotest/test_example_notebooks.py +++ b/autotest/test_example_notebooks.py @@ -1,7 +1,8 @@ import re import pytest -from autotest.conftest import get_project_root_path, run_cmd +from autotest.conftest import get_project_root_path +from modflow_devtools.misc import run_cmd def get_example_notebooks(exclude=None): diff --git a/autotest/test_example_scripts.py b/autotest/test_example_scripts.py index 3408cf9e39..63207b8139 100644 --- a/autotest/test_example_scripts.py +++ b/autotest/test_example_scripts.py @@ -3,7 +3,8 @@ from os import linesep import pytest -from autotest.conftest import get_project_root_path, run_py_script +from autotest.conftest import get_project_root_path +from modflow_devtools.misc import run_py_script def get_example_scripts(exclude=None): diff --git a/autotest/test_export.py b/autotest/test_export.py index e004f87e35..375ce92e02 100644 --- a/autotest/test_export.py +++ b/autotest/test_export.py @@ -7,15 +7,15 @@ import matplotlib.pyplot as plt import numpy as np import pytest -from autotest.conftest import ( +from autotest.conftest import get_example_data_path +from flaky import flaky +from modflow_devtools.markers import ( excludes_platform, - get_example_data_path, - has_pkg, requires_exe, requires_pkg, requires_spatial_reference, ) -from flaky import flaky +from modflow_devtools.misc import has_pkg import flopy from flopy.discretization import StructuredGrid, UnstructuredGrid @@ -62,7 +62,7 @@ def namfiles() -> List[Path]: @requires_pkg("shapefile") -def test_output_helper_shapefile_export(tmpdir, example_data_path): +def test_output_helper_shapefile_export(function_tmpdir, example_data_path): ml = Modflow.load( "freyberg.nam", @@ -72,7 +72,7 @@ def test_output_helper_shapefile_export(tmpdir, example_data_path): cbc = CellBudgetFile(os.path.join(ml.model_ws, "freyberg.cbc")) flopy.export.utils.output_helper( - os.path.join(tmpdir, "test.shp"), + os.path.join(function_tmpdir, "test.shp"), ml, {"HDS": head, "cbc": cbc}, mflay=1, @@ -82,7 +82,7 @@ def test_output_helper_shapefile_export(tmpdir, example_data_path): @requires_pkg("pandas", "shapefile") @pytest.mark.slow -def test_freyberg_export(tmpdir, example_data_path): +def test_freyberg_export(function_tmpdir, example_data_path): # steady state name = "freyberg" @@ -93,10 +93,10 @@ def test_freyberg_export(tmpdir, example_data_path): ) # test export at model, package and object levels - m.export(f"{tmpdir}/model.shp") - m.wel.export(f"{tmpdir}/wel.shp") - m.lpf.hk.export(f"{tmpdir}/hk.shp") - m.riv.stress_period_data.export(f"{tmpdir}/riv_spd.shp") + m.export(f"{function_tmpdir}/model.shp") + m.wel.export(f"{function_tmpdir}/wel.shp") + m.lpf.hk.export(f"{function_tmpdir}/hk.shp") + m.riv.stress_period_data.export(f"{function_tmpdir}/riv_spd.shp") # transient # (doesn't work at model level because the total size of @@ -109,7 +109,7 @@ def test_freyberg_export(tmpdir, example_data_path): load_only=["DIS", "BAS6", "NWT", "OC", "RCH", "WEL", "DRN", "UPW"], ) # test export without instantiating an sr - shape = tmpdir / f"{name}_drn_sparse.shp" + shape = function_tmpdir / f"{name}_drn_sparse.shp" m.drn.stress_period_data.export(str(shape), sparse=True) for suffix in [".dbf", ".shp", ".shx"]: part = shape.with_suffix(suffix) @@ -145,7 +145,7 @@ def test_freyberg_export(tmpdir, example_data_path): # if wkt text was fetched from spatialreference.org if wkt is not None: # test default package export - shape = tmpdir / f"{name}_dis.shp" + shape = function_tmpdir / f"{name}_dis.shp" m.dis.export(str(shape)) for suffix in [".dbf", ".prj", ".shp", ".shx"]: part = shape.with_suffix(suffix) @@ -157,7 +157,7 @@ def test_freyberg_export(tmpdir, example_data_path): # test default package export to higher level dir ? # test sparse package export - shape = tmpdir / f"{name}_drn_sparse.shp" + shape = function_tmpdir / f"{name}_drn_sparse.shp" m.drn.stress_period_data.export(str(shape), sparse=True) for suffix in [".dbf", ".prj", ".shp", ".shx"]: part = shape.with_suffix(suffix) @@ -167,7 +167,7 @@ def test_freyberg_export(tmpdir, example_data_path): @requires_pkg("netCDF4", "pyproj") -def test_export_output(tmpdir, example_data_path): +def test_export_output(function_tmpdir, example_data_path): ml = Modflow.load( "freyberg.nam", model_ws=str(example_data_path / "freyberg") @@ -175,7 +175,7 @@ def test_export_output(tmpdir, example_data_path): hds_pth = os.path.join(ml.model_ws, "freyberg.githds") hds = flopy.utils.HeadFile(hds_pth) - out_pth = os.path.join(tmpdir, "freyberg.out.nc") + out_pth = os.path.join(function_tmpdir, "freyberg.out.nc") nc = flopy.export.utils.output_helper( out_pth, ml, {"freyberg.githds": hds} ) @@ -190,7 +190,7 @@ def test_export_output(tmpdir, example_data_path): @requires_pkg("shapefile") -def test_write_gridlines_shapefile(tmpdir): +def test_write_gridlines_shapefile(function_tmpdir): import shapefile from flopy.discretization import StructuredGrid @@ -203,7 +203,7 @@ def test_write_gridlines_shapefile(tmpdir): # cell spacing along model columns epsg=26715, ) - outshp = tmpdir / "gridlines.shp" + outshp = function_tmpdir / "gridlines.shp" write_gridlines_shapefile(outshp, sg) for suffix in [".dbf", ".prj", ".shp", ".shx"]: @@ -216,7 +216,7 @@ def test_write_gridlines_shapefile(tmpdir): @flaky @requires_pkg("shapefile", "shapely") -def test_write_grid_shapefile(tmpdir): +def test_write_grid_shapefile(function_tmpdir): from shapefile import Reader from flopy.discretization import StructuredGrid @@ -229,7 +229,7 @@ def test_write_grid_shapefile(tmpdir): # cell spacing along model columns epsg=26715, ) - outshp = tmpdir / "junk.shp" + outshp = function_tmpdir / "junk.shp" write_grid_shapefile(outshp, sg, array_dict={}) for suffix in [".dbf", ".prj", ".shp", ".shx"]: @@ -265,7 +265,7 @@ def test_write_grid_shapefile(tmpdir): @requires_pkg("shapefile") -def test_export_shapefile_polygon_closed(tmpdir): +def test_export_shapefile_polygon_closed(function_tmpdir): from shapefile import Reader xll, yll = 468970, 3478635 @@ -285,7 +285,7 @@ def test_export_shapefile_polygon_closed(tmpdir): m, delr=spacing, delc=spacing, nrow=nrow, ncol=ncol ) - shp_file = os.path.join(tmpdir, "test_polygon.shp") + shp_file = os.path.join(function_tmpdir, "test_polygon.shp") m.dis.export(shp_file) shp = Reader(shp_file) @@ -298,7 +298,7 @@ def test_export_shapefile_polygon_closed(tmpdir): @excludes_platform("Windows") @requires_pkg("rasterio", "shapefile", "scipy") -def test_export_array(tmpdir, example_data_path): +def test_export_array(function_tmpdir, example_data_path): import rasterio from scipy.ndimage import rotate @@ -314,16 +314,16 @@ def test_export_array(tmpdir, example_data_path): nodata = -9999 export_array( m.modelgrid, - os.path.join(tmpdir, "fb.asc"), + os.path.join(function_tmpdir, "fb.asc"), m.dis.top.array, nodata=nodata, ) - arr = np.loadtxt(os.path.join(tmpdir, "fb.asc"), skiprows=6) + arr = np.loadtxt(os.path.join(function_tmpdir, "fb.asc"), skiprows=6) - m.modelgrid.write_shapefile(os.path.join(tmpdir, "grid.shp")) + m.modelgrid.write_shapefile(os.path.join(function_tmpdir, "grid.shp")) # check bounds - with open(os.path.join(tmpdir, "fb.asc")) as src: + with open(os.path.join(function_tmpdir, "fb.asc")) as src: for line in src: if "xllcorner" in line.lower(): val = float(line.strip().split()[-1]) @@ -349,11 +349,11 @@ def test_export_array(tmpdir, example_data_path): export_array( m.modelgrid, - os.path.join(tmpdir, "fb.tif"), + os.path.join(function_tmpdir, "fb.tif"), m.dis.top.array, nodata=nodata, ) - with rasterio.open(os.path.join(tmpdir, "fb.tif")) as src: + with rasterio.open(os.path.join(function_tmpdir, "fb.tif")) as src: arr = src.read(1) assert src.shape == (m.nrow, m.ncol) # TODO: these tests currently fail -- fix is in progress @@ -363,7 +363,7 @@ def test_export_array(tmpdir, example_data_path): @requires_pkg("netCDF4", "pyproj") -def test_netcdf_classmethods(tmpdir, example_data_path): +def test_netcdf_classmethods(function_tmpdir, example_data_path): namfile = "freyberg.nam" name = namfile.replace(".nam", "") model_ws = example_data_path / "freyberg_multilayer_transient" @@ -375,9 +375,9 @@ def test_netcdf_classmethods(tmpdir, example_data_path): load_only=[], ) - f = ml.export(os.path.join(tmpdir, "freyberg.nc")) + f = ml.export(os.path.join(function_tmpdir, "freyberg.nc")) v1_set = set(f.nc.variables.keys()) - fnc = os.path.join(tmpdir, "freyberg.new.nc") + fnc = os.path.join(function_tmpdir, "freyberg.new.nc") new_f = flopy.export.NetCdf.zeros_like(f, output_filename=fnc) v2_set = set(new_f.nc.variables.keys()) diff = v1_set.symmetric_difference(v2_set) @@ -424,10 +424,10 @@ def test_wkt_parse(example_shapefiles): @requires_pkg("shapefile") -def test_shapefile_ibound(tmpdir, example_data_path): +def test_shapefile_ibound(function_tmpdir, example_data_path): from shapefile import Reader - shape_name = os.path.join(tmpdir, "test.shp") + shape_name = os.path.join(function_tmpdir, "test.shp") namfile = "freyberg.nam" model_ws = example_data_path / "freyberg_multilayer_transient" ml = flopy.modflow.Modflow.load( @@ -449,7 +449,7 @@ def test_shapefile_ibound(tmpdir, example_data_path): @requires_pkg("pandas", "shapefile") @pytest.mark.slow @pytest.mark.parametrize("namfile", namfiles()) -def test_shapefile(tmpdir, namfile): +def test_shapefile(function_tmpdir, namfile): from shapefile import Reader model = flopy.modflow.Modflow.load( @@ -460,7 +460,7 @@ def test_shapefile(tmpdir, namfile): msg = f"Could not load {namfile} model" assert isinstance(model, flopy.modflow.Modflow), msg - fnc_name = os.path.join(tmpdir, f"{model.name}.shp") + fnc_name = os.path.join(function_tmpdir, f"{model.name}.shp") fnc = model.export(fnc_name) # fnc2 = m.export(fnc_name, package_names=None) # fnc3 = m.export(fnc_name, package_names=['DIS']) @@ -474,7 +474,7 @@ def test_shapefile(tmpdir, namfile): @requires_pkg("pandas", "shapefile") @pytest.mark.slow @pytest.mark.parametrize("namfile", namfiles()) -def test_shapefile_export_modelgrid_override(tmpdir, namfile): +def test_shapefile_export_modelgrid_override(function_tmpdir, namfile): from shapefile import Reader model = flopy.modflow.Modflow.load( @@ -498,7 +498,7 @@ def test_shapefile_export_modelgrid_override(tmpdir, namfile): assert model, f"Could not load namefile {namfile}" assert isinstance(model, flopy.modflow.Modflow) - fnc_name = os.path.join(tmpdir, f"{model.name}.shp") + fnc_name = os.path.join(function_tmpdir, f"{model.name}.shp") model.export(fnc_name, modelgrid=modelgrid) # TODO: do we want to test exports with package_names options too? @@ -513,7 +513,7 @@ def test_shapefile_export_modelgrid_override(tmpdir, namfile): @requires_pkg("netCDF4", "pyproj") @pytest.mark.slow @pytest.mark.parametrize("namfile", namfiles()) -def test_export_netcdf(tmpdir, namfile): +def test_export_netcdf(function_tmpdir, namfile): from netCDF4 import Dataset model = flopy.modflow.Modflow.load( @@ -529,9 +529,9 @@ def test_export_netcdf(tmpdir, namfile): assert model, f"Could not load namefile {namfile}" assert isinstance(model, flopy.modflow.Modflow) - fnc = model.export(os.path.join(tmpdir, f"{model.name}.nc")) + fnc = model.export(os.path.join(function_tmpdir, f"{model.name}.nc")) fnc.write() - fnc_name = os.path.join(tmpdir, f"{model.name}.nc") + fnc_name = os.path.join(function_tmpdir, f"{model.name}.nc") fnc = model.export(fnc_name) fnc.write() @@ -540,7 +540,7 @@ def test_export_netcdf(tmpdir, namfile): @requires_pkg("shapefile") -def test_export_array2(tmpdir): +def test_export_array2(function_tmpdir): nrow = 7 ncol = 11 epsg = 4111 @@ -549,7 +549,7 @@ def test_export_array2(tmpdir): modelgrid = StructuredGrid( delr=np.ones(ncol) * 1.1, delc=np.ones(nrow) * 1.1 ) - filename = os.path.join(tmpdir, "myarray1.shp") + filename = os.path.join(function_tmpdir, "myarray1.shp") a = np.arange(nrow * ncol).reshape((nrow, ncol)) export_array(modelgrid, filename, a) assert os.path.isfile(filename), "did not create array shapefile" @@ -558,7 +558,7 @@ def test_export_array2(tmpdir): modelgrid = StructuredGrid( delr=np.ones(ncol) * 1.1, delc=np.ones(nrow) * 1.1, epsg=epsg ) - filename = os.path.join(tmpdir, "myarray2.shp") + filename = os.path.join(function_tmpdir, "myarray2.shp") a = np.arange(nrow * ncol).reshape((nrow, ncol)) export_array(modelgrid, filename, a) assert os.path.isfile(filename), "did not create array shapefile" @@ -567,14 +567,14 @@ def test_export_array2(tmpdir): modelgrid = StructuredGrid( delr=np.ones(ncol) * 1.1, delc=np.ones(nrow) * 1.1 ) - filename = os.path.join(tmpdir, "myarray3.shp") + filename = os.path.join(function_tmpdir, "myarray3.shp") a = np.arange(nrow * ncol).reshape((nrow, ncol)) export_array(modelgrid, filename, a, epsg=epsg) assert os.path.isfile(filename), "did not create array shapefile" @requires_pkg("shapefile", "shapely") -def test_export_array_contours(tmpdir): +def test_export_array_contours(function_tmpdir): nrow = 7 ncol = 11 epsg = 4111 @@ -583,7 +583,7 @@ def test_export_array_contours(tmpdir): modelgrid = StructuredGrid( delr=np.ones(ncol) * 1.1, delc=np.ones(nrow) * 1.1 ) - filename = os.path.join(tmpdir, "myarraycontours1.shp") + filename = os.path.join(function_tmpdir, "myarraycontours1.shp") a = np.arange(nrow * ncol).reshape((nrow, ncol)) export_array_contours(modelgrid, filename, a) assert os.path.isfile(filename), "did not create contour shapefile" @@ -592,7 +592,7 @@ def test_export_array_contours(tmpdir): modelgrid = StructuredGrid( delr=np.ones(ncol) * 1.1, delc=np.ones(nrow) * 1.1, epsg=epsg ) - filename = os.path.join(tmpdir, "myarraycontours2.shp") + filename = os.path.join(function_tmpdir, "myarraycontours2.shp") a = np.arange(nrow * ncol).reshape((nrow, ncol)) export_array_contours(modelgrid, filename, a) assert os.path.isfile(filename), "did not create contour shapefile" @@ -601,17 +601,17 @@ def test_export_array_contours(tmpdir): modelgrid = StructuredGrid( delr=np.ones(ncol) * 1.1, delc=np.ones(nrow) * 1.1 ) - filename = os.path.join(tmpdir, "myarraycontours3.shp") + filename = os.path.join(function_tmpdir, "myarraycontours3.shp") a = np.arange(nrow * ncol).reshape((nrow, ncol)) export_array_contours(modelgrid, filename, a, epsg=epsg) assert os.path.isfile(filename), "did not create contour shapefile" @requires_pkg("shapefile", "shapely") -def test_export_contourf(tmpdir, example_data_path): +def test_export_contourf(function_tmpdir, example_data_path): from shapefile import Reader - filename = os.path.join(tmpdir, "myfilledcontours.shp") + filename = os.path.join(function_tmpdir, "myfilledcontours.shp") mpath = example_data_path / "freyberg" ml = Modflow.load("freyberg.nam", model_ws=mpath) hds_pth = os.path.join(ml.model_ws, "freyberg.githds") @@ -632,16 +632,17 @@ def test_export_contourf(tmpdir, example_data_path): with Reader(filename) as r: shapes = r.shapes() # expect 65 with standard mpl contours (structured grids), 86 with tricontours - assert len(shapes) >= 65, "multipolygons were skipped in contourf routine" - + assert ( + len(shapes) >= 65 + ), "multipolygons were skipped in contourf routine" @pytest.mark.mf6 @requires_pkg("shapefile", "shapely") -def test_export_contours(tmpdir, example_data_path): +def test_export_contours(function_tmpdir, example_data_path): from shapefile import Reader - filename = os.path.join(tmpdir, "mycontours.shp") + filename = os.path.join(function_tmpdir, "mycontours.shp") mpath = example_data_path / "freyberg" ml = Modflow.load("freyberg.nam", model_ws=mpath) hds_pth = os.path.join(ml.model_ws, "freyberg.githds") @@ -665,10 +666,9 @@ def test_export_contours(tmpdir, example_data_path): assert len(shapes) >= 65 - @pytest.mark.mf6 @requires_pkg("shapely") -def test_mf6_grid_shp_export(tmpdir): +def test_mf6_grid_shp_export(function_tmpdir): nlay = 2 nrow = 10 ncol = 10 @@ -683,7 +683,7 @@ def test_mf6_grid_shp_export(tmpdir): m = flopy.modflow.Modflow( "junk", version="mfnwt", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) dis = flopy.modflow.ModflowDis( m, @@ -727,7 +727,7 @@ def test_mf6_grid_shp_export(tmpdir): sim_name=mf6name, version="mf6", exe_name="mf6", - sim_ws=str(tmpdir), + sim_ws=str(function_tmpdir), ) tdis = flopy.mf6.modflow.mftdis.ModflowTdis( sim, pname="tdis", time_units="DAYS", nper=nper, perioddata=perioddata @@ -770,12 +770,12 @@ def cellid(k, i, j, nrow, ncol): return # rch6.export('{}/mf6.shp'.format(baseDir)) - m.export(str(tmpdir / "mfnwt.shp")) - gwf.export(str(tmpdir / "mf6.shp")) + m.export(str(function_tmpdir / "mfnwt.shp")) + gwf.export(str(function_tmpdir / "mf6.shp")) # check that the two shapefiles are the same - ra = shp2recarray(str(tmpdir / "mfnwt.shp")) - ra6 = shp2recarray(str(tmpdir / "mf6.shp")) + ra = shp2recarray(str(function_tmpdir / "mfnwt.shp")) + ra6 = shp2recarray(str(function_tmpdir / "mf6.shp")) # check first and last exported cells assert ra.geometry[0] == ra6.geometry[0] @@ -801,7 +801,7 @@ def cellid(k, i, j, nrow, ncol): @requires_pkg("shapefile") @pytest.mark.slow -def test_export_huge_shapefile(tmpdir): +def test_export_huge_shapefile(function_tmpdir): nlay = 2 nrow = 200 ncol = 200 @@ -813,7 +813,9 @@ def test_export_huge_shapefile(tmpdir): # perioddata = [[perlen, nstp, tsmult]] * 2 botm = np.zeros((nlay, nrow, ncol)) - m = flopy.modflow.Modflow("junk", version="mfnwt", model_ws=str(tmpdir)) + m = flopy.modflow.Modflow( + "junk", version="mfnwt", model_ws=str(function_tmpdir) + ) flopy.modflow.ModflowDis( m, nlay=nlay, @@ -827,13 +829,13 @@ def test_export_huge_shapefile(tmpdir): botm=botm, ) - m.export(str(tmpdir / "huge.shp")) + m.export(str(function_tmpdir / "huge.shp")) @requires_pkg("netCDF4", "pyproj") -def test_polygon_from_ij(tmpdir): +def test_polygon_from_ij(function_tmpdir): """test creation of a polygon from an i, j location using get_vertices().""" - ws = str(tmpdir) + ws = str(function_tmpdir) m = Modflow("toy_model", model_ws=ws) botm = np.zeros((2, 10, 10)) @@ -891,8 +893,8 @@ def test_polygon_from_ij(tmpdir): @flaky @requires_pkg("netCDF4", "pyproj") @requires_spatial_reference -def test_polygon_from_ij_with_epsg(tmpdir): - ws = str(tmpdir) +def test_polygon_from_ij_with_epsg(function_tmpdir): + ws = str(function_tmpdir) m = Modflow("toy_model", model_ws=ws) botm = np.zeros((2, 10, 10)) @@ -988,7 +990,7 @@ def is_binary_file(filepath): @requires_pkg("vtk") -def test_vtk_export_array2d(tmpdir, example_data_path): +def test_vtk_export_array2d(function_tmpdir, example_data_path): # test mf 2005 freyberg mpath = str(example_data_path / "freyberg_multilayer_transient") namfile = "freyberg.nam" @@ -997,18 +999,22 @@ def test_vtk_export_array2d(tmpdir, example_data_path): ) # export and check - m.dis.top.export(str(tmpdir), name="top", fmt="vtk", binary=False) - assert count_lines_in_file(tmpdir / "top.vtk") == 17615 + m.dis.top.export(str(function_tmpdir), name="top", fmt="vtk", binary=False) + assert count_lines_in_file(function_tmpdir / "top.vtk") == 17615 # with smoothing m.dis.top.export( - str(tmpdir), fmt="vtk", name="top_smooth", binary=False, smooth=True + str(function_tmpdir), + fmt="vtk", + name="top_smooth", + binary=False, + smooth=True, ) - assert count_lines_in_file(tmpdir / "top_smooth.vtk") == 17615 + assert count_lines_in_file(function_tmpdir / "top_smooth.vtk") == 17615 @requires_pkg("vtk") -def test_vtk_export_array3d(tmpdir, example_data_path): +def test_vtk_export_array3d(function_tmpdir, example_data_path): # test mf 2005 freyberg mpath = str(example_data_path / "freyberg_multilayer_transient") namfile = "freyberg.nam" @@ -1020,33 +1026,33 @@ def test_vtk_export_array3d(tmpdir, example_data_path): ) # export and check - m.upw.hk.export(str(tmpdir), fmt="vtk", name="hk", binary=False) - assert count_lines_in_file(tmpdir / "hk.vtk") == 17615 + m.upw.hk.export(str(function_tmpdir), fmt="vtk", name="hk", binary=False) + assert count_lines_in_file(function_tmpdir / "hk.vtk") == 17615 # with point scalars m.upw.hk.export( - str(tmpdir), + str(function_tmpdir), fmt="vtk", name="hk_points", point_scalars=True, binary=False, ) - assert count_lines_in_file(tmpdir / "hk_points.vtk") == 19482 + assert count_lines_in_file(function_tmpdir / "hk_points.vtk") == 19482 # with point scalars and binary m.upw.hk.export( - str(tmpdir), + str(function_tmpdir), fmt="vtk", name="hk_points_bin", point_scalars=True, ) - assert is_binary_file(tmpdir / "hk_points_bin.vtk") + assert is_binary_file(function_tmpdir / "hk_points_bin.vtk") @requires_pkg("vtk") -def test_vtk_transient_array_2d(tmpdir, example_data_path): +def test_vtk_transient_array_2d(function_tmpdir, example_data_path): # test mf 2005 freyberg - ws = str(tmpdir) + ws = str(function_tmpdir) mpath = str(example_data_path / "freyberg_multilayer_transient") namfile = "freyberg.nam" m = Modflow.load( @@ -1060,21 +1066,21 @@ def test_vtk_transient_array_2d(tmpdir, example_data_path): # export and check m.rch.rech.export(ws, fmt="vtk", kpers=kpers, binary=False, xml=True) - assert count_lines_in_file(tmpdir / "rech_000001.vtk") == 26837 - assert count_lines_in_file(tmpdir / "rech_001096.vtk") == 26837 + assert count_lines_in_file(function_tmpdir / "rech_000001.vtk") == 26837 + assert count_lines_in_file(function_tmpdir / "rech_001096.vtk") == 26837 # with binary m.rch.rech.export(ws, fmt="vtk", binary=True, kpers=kpers) - assert is_binary_file(tmpdir / "rech_000001.vtk") - assert is_binary_file(tmpdir / "rech_001096.vtk") + assert is_binary_file(function_tmpdir / "rech_000001.vtk") + assert is_binary_file(function_tmpdir / "rech_001096.vtk") @requires_pkg("vtk") @pytest.mark.slow -def test_vtk_export_packages(tmpdir, example_data_path): +def test_vtk_export_packages(function_tmpdir, example_data_path): # test mf 2005 freyberg - ws = str(tmpdir) + ws = str(function_tmpdir) mpath = str(example_data_path / "freyberg_multilayer_transient") namfile = "freyberg.nam" m = Modflow.load( @@ -1087,37 +1093,37 @@ def test_vtk_export_packages(tmpdir, example_data_path): # dis export and check # todo: pakbase.export() for vtk!!!! m.dis.export(ws, fmt="vtk", xml=True, binary=False) - filetocheck = tmpdir / "DIS.vtk" + filetocheck = function_tmpdir / "DIS.vtk" # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==1019857) assert count_lines_in_file(filetocheck) == 27239 # upw with point scalar output m.upw.export(ws, fmt="vtk", xml=True, binary=False, point_scalars=True) - assert count_lines_in_file(tmpdir / "UPW.vtk") == 42445 + assert count_lines_in_file(function_tmpdir / "UPW.vtk") == 42445 # bas with smoothing on m.bas6.export(ws, fmt="vtk", binary=False, smooth=True) - assert count_lines_in_file(tmpdir / "BAS6.vtk") == 17883 + assert count_lines_in_file(function_tmpdir / "BAS6.vtk") == 17883 # transient package drain kpers = [0, 1, 1096] m.drn.export(ws, fmt="vtk", binary=False, xml=True, kpers=kpers, pvd=True) - assert count_lines_in_file(tmpdir / "DRN_000001.vtu") == 27239 - assert count_lines_in_file(tmpdir / "DRN_001096.vtu") == 27239 + assert count_lines_in_file(function_tmpdir / "DRN_000001.vtu") == 27239 + assert count_lines_in_file(function_tmpdir / "DRN_001096.vtu") == 27239 # dis with binary m.dis.export(ws, fmt="vtk", binary=True) - assert is_binary_file(tmpdir / "DIS.vtk") + assert is_binary_file(function_tmpdir / "DIS.vtk") # upw with point scalars and binary m.upw.export(ws, fmt="vtk", point_scalars=True, binary=True) - assert is_binary_file(tmpdir / "UPW.vtk") + assert is_binary_file(function_tmpdir / "UPW.vtk") @pytest.mark.mf6 @requires_pkg("vtk") -def test_vtk_mf6(tmpdir, example_data_path): +def test_vtk_mf6(function_tmpdir, example_data_path): # test mf6 mf6expth = str(example_data_path / "mf6") mf6sims = [ @@ -1136,10 +1142,10 @@ def test_vtk_mf6(tmpdir, example_data_path): for mname in sim_models: print(mname) m = loaded_sim.get_model(mname) - m.export(str(tmpdir), fmt="vtk", binary=False) + m.export(str(function_tmpdir), fmt="vtk", binary=False) # check one - filetocheck = tmpdir / "twrihfb2015_000000.vtk" + filetocheck = function_tmpdir / "twrihfb2015_000000.vtk" # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==21609) assert count_lines_in_file(filetocheck) == 9537 @@ -1147,7 +1153,7 @@ def test_vtk_mf6(tmpdir, example_data_path): @requires_pkg("vtk") @pytest.mark.slow -def test_vtk_binary_head_export(tmpdir, example_data_path): +def test_vtk_binary_head_export(function_tmpdir, example_data_path): # test mf 2005 freyberg mpth = str(example_data_path / "freyberg_multilayer_transient") namfile = "freyberg.nam" @@ -1156,7 +1162,7 @@ def test_vtk_binary_head_export(tmpdir, example_data_path): m = Modflow.load( namfile, model_ws=mpth, verbose=False, load_only=["dis", "bas6"] ) - filetocheck = tmpdir / "freyberg_head_000003.vtu" + filetocheck = function_tmpdir / "freyberg_head_000003.vtu" # export and check @@ -1164,7 +1170,7 @@ def test_vtk_binary_head_export(tmpdir, example_data_path): vtkobj.add_heads( heads, kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0, 1089)] ) - vtkobj.write(tmpdir / "freyberg_head") + vtkobj.write(function_tmpdir / "freyberg_head") assert count_lines_in_file(filetocheck) == 34 filetocheck.unlink() @@ -1175,7 +1181,7 @@ def test_vtk_binary_head_export(tmpdir, example_data_path): vtkobj.add_heads( heads, kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0, 1089)] ) - vtkobj.write(tmpdir / "freyberg_head") + vtkobj.write(function_tmpdir / "freyberg_head") assert count_lines_in_file(filetocheck) == 34 filetocheck.unlink() @@ -1186,17 +1192,17 @@ def test_vtk_binary_head_export(tmpdir, example_data_path): vtkobj.add_heads( heads, kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0, 1089)] ) - vtkobj.write(tmpdir / "freyberg_head") + vtkobj.write(function_tmpdir / "freyberg_head") assert count_lines_in_file(filetocheck) == 34 @requires_pkg("vtk") @pytest.mark.slow -def test_vtk_cbc(tmpdir, example_data_path): +def test_vtk_cbc(function_tmpdir, example_data_path): # test mf 2005 freyberg - ws = str(tmpdir) + ws = str(function_tmpdir) mpth = str(example_data_path / "freyberg_multilayer_transient") namfile = "freyberg.nam" cbcfile = os.path.join(mpth, "freyberg.cbc") @@ -1208,20 +1214,25 @@ def test_vtk_cbc(tmpdir, example_data_path): # export and check with point scalar vtkobj = Vtk(m, binary=False, xml=True, pvd=True, point_scalars=True) vtkobj.add_cell_budget(cbc, kstpkper=[(0, 0), (0, 1), (0, 2)]) - vtkobj.write(tmpdir / "freyberg_CBC") + vtkobj.write(function_tmpdir / "freyberg_CBC") - assert count_lines_in_file(tmpdir / "freyberg_CBC_000000.vtu") == 39243 + assert ( + count_lines_in_file(function_tmpdir / "freyberg_CBC_000000.vtu") + == 39243 + ) # with point scalars and binary vtkobj = Vtk(m, xml=True, pvd=True, point_scalars=True) vtkobj.add_cell_budget(cbc, kstpkper=[(0, 0), (0, 1), (0, 2)]) - vtkobj.write(tmpdir / "freyberg_CBC") - assert count_lines_in_file(tmpdir / "freyberg_CBC_000000.vtu") == 28 + vtkobj.write(function_tmpdir / "freyberg_CBC") + assert ( + count_lines_in_file(function_tmpdir / "freyberg_CBC_000000.vtu") == 28 + ) @requires_pkg("vtk") @pytest.mark.slow -def test_vtk_vector(tmpdir, example_data_path): +def test_vtk_vector(function_tmpdir, example_data_path): # test mf 2005 freyberg mpth = str(example_data_path / "freyberg_multilayer_transient") namfile = "freyberg.nam" @@ -1237,7 +1248,7 @@ def test_vtk_vector(tmpdir, example_data_path): ) q = pp.get_specific_discharge(vectors, m, head) - filenametocheck = tmpdir / "discharge.vtu" + filenametocheck = function_tmpdir / "discharge.vtu" # export and check with point scalar vtkobj = Vtk(m, xml=True, binary=False, point_scalars=True) @@ -1256,7 +1267,7 @@ def test_vtk_vector(tmpdir, example_data_path): # test at cell centers q = pp.get_specific_discharge(vectors, m, head) - filenametocheck = tmpdir / "discharge_verts.vtu" + filenametocheck = function_tmpdir / "discharge_verts.vtu" vtkobj = Vtk(m, xml=True, binary=False) vtkobj.add_vector(q, "discharge") vtkobj.write(filenametocheck) @@ -1272,7 +1283,7 @@ def test_vtk_vector(tmpdir, example_data_path): @requires_pkg("vtk") -def test_vtk_unstructured(tmpdir, example_data_path): +def test_vtk_unstructured(function_tmpdir, example_data_path): from vtkmodules.util.numpy_support import vtk_to_numpy from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader @@ -1312,7 +1323,7 @@ def test_vtk_unstructured(tmpdir, example_data_path): ncpl=ncpl, ) - outfile = tmpdir / "disu_grid.vtu" + outfile = function_tmpdir / "disu_grid.vtu" vtkobj = Vtk( modelgrid=modelgrid, vertical_exageration=2, binary=True, smooth=False ) @@ -1336,7 +1347,7 @@ def test_vtk_unstructured(tmpdir, example_data_path): @pytest.mark.mf6 @requires_pkg("vtk") -def test_vtk_vertex(tmpdir, example_data_path): +def test_vtk_vertex(function_tmpdir, example_data_path): from vtkmodules.util.numpy_support import vtk_to_numpy from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader @@ -1346,7 +1357,7 @@ def test_vtk_vertex(tmpdir, example_data_path): sim = MFSimulation.load(sim_ws=workspace) gwf = sim.get_model("gwf_1") - outfile = tmpdir / "disv.vtk" + outfile = function_tmpdir / "disv.vtk" vtkobj = Vtk(model=gwf, binary=True, smooth=False) vtkobj.add_model(gwf) vtkobj.write(outfile) @@ -1372,19 +1383,22 @@ def test_vtk_vertex(tmpdir, example_data_path): @requires_exe("mf2005") @requires_pkg("pandas", "vtk") -def test_vtk_pathline(tmpdir, example_data_path): +def test_vtk_pathline(function_tmpdir, example_data_path): from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader # pathline test for vtk ws = str(example_data_path / "freyberg") ml = Modflow.load("freyberg.nam", model_ws=ws, exe_name="mf2005") - ml.change_model_ws(new_pth=str(tmpdir)) + ml.change_model_ws(new_pth=str(function_tmpdir)) ml.write_input() ml.run_model() mpp = Modpath6( - "freybergmpp", modflowmodel=ml, model_ws=str(tmpdir), exe_name="mp6" + "freybergmpp", + modflowmodel=ml, + model_ws=str(function_tmpdir), + exe_name="mp6", ) mpbas = Modpath6Bas( mpp, @@ -1400,12 +1414,12 @@ def test_vtk_pathline(tmpdir, example_data_path): mpp.write_input() mpp.run_model() - pthfile = os.path.join(tmpdir, mpp.sim.pathline_file) + pthfile = os.path.join(function_tmpdir, mpp.sim.pathline_file) pthobj = PathlineFile(pthfile) travel_time_max = 200.0 * 365.25 * 24.0 * 60.0 * 60.0 plines = pthobj.get_alldata(totim=travel_time_max, ge=False) - outfile = tmpdir / "pathline.vtk" + outfile = function_tmpdir / "pathline.vtk" vtkobj = Vtk(model=ml, binary=True, vertical_exageration=50, smooth=False) vtkobj.add_model(ml) @@ -1494,14 +1508,16 @@ def load_iverts(fname, closed=False): @pytest.mark.mf6 @requires_pkg("vtk") -def test_vtk_export_model_without_packages_names(tmpdir): +def test_vtk_export_model_without_packages_names(function_tmpdir): from vtkmodules.util.numpy_support import vtk_to_numpy from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader from flopy.export.vtk import Vtk name = "mymodel" - sim = MFSimulation(sim_name=name, sim_ws=str(tmpdir), exe_name="mf6") + sim = MFSimulation( + sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" + ) tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) @@ -1518,11 +1534,11 @@ def test_vtk_export_model_without_packages_names(tmpdir): gwf = sim.get_model() vtkobj = Vtk(gwf, binary=False) vtkobj.add_model(gwf) - vtkobj.write(tmpdir / "gwf.vtk") + vtkobj.write(function_tmpdir / "gwf.vtk") # load the output using the vtk standard library gridreader = vtkUnstructuredGridReader() - gridreader.SetFileName(str(tmpdir / "gwf_000000.vtk")) + gridreader.SetFileName(str(function_tmpdir / "gwf_000000.vtk")) gridreader.Update() grid = gridreader.GetOutput() @@ -1549,14 +1565,16 @@ def test_vtk_export_model_without_packages_names(tmpdir): @pytest.mark.mf6 @requires_pkg("vtk") -def test_vtk_export_disv1_model(tmpdir): +def test_vtk_export_disv1_model(function_tmpdir): from vtkmodules.util.numpy_support import vtk_to_numpy from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader from flopy.export.vtk import Vtk name = "mymodel" - sim = MFSimulation(sim_name=name, sim_ws=str(tmpdir), exe_name="mf6") + sim = MFSimulation( + sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" + ) tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) @@ -1588,7 +1606,7 @@ def test_vtk_export_disv1_model(tmpdir): gwf = sim.get_model() vtkobj = Vtk(gwf, binary=False) vtkobj.add_model(gwf) - f = tmpdir / "gwf.vtk" + f = function_tmpdir / "gwf.vtk" vtkobj.write(f) # load the output using the vtk standard library @@ -1621,7 +1639,7 @@ def test_vtk_export_disv1_model(tmpdir): @pytest.mark.mf6 @requires_pkg("vtk") -def test_vtk_export_disv2_model(tmpdir): +def test_vtk_export_disv2_model(function_tmpdir): from vtkmodules.util.numpy_support import vtk_to_numpy from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader @@ -1629,7 +1647,9 @@ def test_vtk_export_disv2_model(tmpdir): # in this case, test for iverts that do not explicitly close the cell polygons name = "mymodel" - sim = MFSimulation(sim_name=name, sim_ws=str(tmpdir), exe_name="mf6") + sim = MFSimulation( + sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" + ) tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) @@ -1653,7 +1673,7 @@ def test_vtk_export_disv2_model(tmpdir): gwf = sim.get_model() vtkobj = Vtk(gwf, binary=False) vtkobj.add_model(gwf) - f = tmpdir / "gwf.vtk" + f = function_tmpdir / "gwf.vtk" vtkobj.write(f) # load the output using the vtk standard library @@ -1685,7 +1705,7 @@ def test_vtk_export_disv2_model(tmpdir): @requires_pkg("vtk") -def test_vtk_export_disu1_grid(tmpdir, example_data_path): +def test_vtk_export_disu1_grid(function_tmpdir, example_data_path): from vtkmodules.util.numpy_support import vtk_to_numpy from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader @@ -1728,7 +1748,7 @@ def test_vtk_export_disu1_grid(tmpdir, example_data_path): ncpl=ncpl, ) - outfile = tmpdir / "disu_grid.vtu" + outfile = function_tmpdir / "disu_grid.vtu" vtkobj = Vtk( modelgrid=modelgrid, vertical_exageration=2, @@ -1766,7 +1786,7 @@ def test_vtk_export_disu1_grid(tmpdir, example_data_path): @requires_pkg("vtk") -def test_vtk_export_disu2_grid(tmpdir, example_data_path): +def test_vtk_export_disu2_grid(function_tmpdir, example_data_path): from vtkmodules.util.numpy_support import vtk_to_numpy from vtkmodules.vtkIOLegacy import vtkUnstructuredGridReader @@ -1809,7 +1829,7 @@ def test_vtk_export_disu2_grid(tmpdir, example_data_path): ncpl=ncpl, ) - outfile = tmpdir / "disu_grid.vtu" + outfile = function_tmpdir / "disu_grid.vtu" vtkobj = Vtk( modelgrid=modelgrid, vertical_exageration=2, @@ -1849,7 +1869,7 @@ def test_vtk_export_disu2_grid(tmpdir, example_data_path): @pytest.mark.mf6 @requires_exe("mf6", "gridgen") @requires_pkg("vtk", "shapefile") -def test_vtk_export_disu_model(tmpdir): +def test_vtk_export_disu_model(function_tmpdir): from vtkmodules.util.numpy_support import vtk_to_numpy from flopy.export.vtk import Vtk @@ -1879,7 +1899,7 @@ def test_vtk_export_disu_model(tmpdir): botm=botm, ) - g = Gridgen(ml5.modelgrid, model_ws=str(tmpdir)) + g = Gridgen(ml5.modelgrid, model_ws=str(function_tmpdir)) xmin = 7 * delr xmax = 12 * delr @@ -1908,7 +1928,9 @@ def test_vtk_export_disu_model(tmpdir): gridprops = g.get_gridprops_disu6() - sim = MFSimulation(sim_name=name, sim_ws=str(tmpdir), exe_name="mf6") + sim = MFSimulation( + sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" + ) tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) @@ -1926,7 +1948,7 @@ def test_vtk_export_disu_model(tmpdir): vtkobj = Vtk(gwf, binary=False) vtkobj.add_model(gwf) - f = tmpdir / "gwf.vtk" + f = function_tmpdir / "gwf.vtk" vtkobj.write(f) # load the output using the vtk standard library diff --git a/autotest/test_flopy_module.py b/autotest/test_flopy_module.py index e6dbb210a5..9e12c949ee 100644 --- a/autotest/test_flopy_module.py +++ b/autotest/test_flopy_module.py @@ -39,10 +39,10 @@ def test_modflow(): assert isinstance(pcg, flopy.modflow.ModflowPcg) -def test_modflow_unstructured(tmpdir): +def test_modflow_unstructured(function_tmpdir): import flopy - mf = flopy.mfusg.MfUsg(structured=False, model_ws=str(tmpdir)) + mf = flopy.mfusg.MfUsg(structured=False, model_ws=str(function_tmpdir)) assert isinstance(mf, flopy.mfusg.MfUsg) disu = flopy.mfusg.MfUsgDisU( @@ -72,19 +72,19 @@ def test_modflow_unstructured(tmpdir): # write well file wel.write_file() - wel_path = Path(tmpdir / f"{mf.name}.wel") + wel_path = Path(function_tmpdir / f"{mf.name}.wel") assert wel_path.is_file() wel2 = flopy.mfusg.MfUsgWel.load(str(wel_path), mf) assert wel2.stress_period_data[0] == wel.stress_period_data[0] # write ghb file ghb.write_file(check=False) - ghb_path = Path(tmpdir / f"{mf.name}.ghb") + ghb_path = Path(function_tmpdir / f"{mf.name}.ghb") assert ghb_path.is_file() is True ghb2 = flopy.modflow.ModflowGhb.load(str(ghb_path), mf) -def test_mflist_reference(tmpdir): +def test_mflist_reference(function_tmpdir): # make the model ml = flopy.modflow.Modflow() assert isinstance(ml, flopy.modflow.Modflow) @@ -136,7 +136,7 @@ def test_mflist_reference(tmpdir): assert isinstance(ghb, flopy.modflow.ModflowGhb) # TODO: test separately - # shp_path = str(tmpdir / "test3.shp") + # shp_path = str(function_tmpdir / "test3.shp") # ml.export(shp_path, kper=0) # shp = shapefile.Reader(shp_path) # assert shp.numRecords == nrow * ncol diff --git a/autotest/test_formattedfile.py b/autotest/test_formattedfile.py index 65c9ac07e1..66c02be510 100644 --- a/autotest/test_formattedfile.py +++ b/autotest/test_formattedfile.py @@ -29,7 +29,7 @@ def test_formattedfile_reference(example_data_path): plt.close() -def test_formattedfile_read(tmpdir, example_data_path): +def test_formattedfile_read(function_tmpdir, example_data_path): mf2005_model_path = example_data_path / "mf2005_test" h = FormattedHeadFile(str(mf2005_model_path / "test1tr.githds")) assert isinstance(h, FormattedHeadFile) @@ -58,14 +58,14 @@ def test_formattedfile_read(tmpdir, example_data_path): h.close() # Check error when reading empty file - fname = str(tmpdir / "empty.githds") + fname = str(function_tmpdir / "empty.githds") with open(fname, "w"): pass with pytest.raises(ValueError): FormattedHeadFile(fname) -def test_binaryfile_read(tmpdir, freyberg_model_path): +def test_binaryfile_read(function_tmpdir, freyberg_model_path): h = HeadFile(str(freyberg_model_path / "freyberg.githds")) assert isinstance(h, HeadFile) @@ -93,7 +93,7 @@ def test_binaryfile_read(tmpdir, freyberg_model_path): h.close() # Check error when reading empty file - fname = str(tmpdir / "empty.githds") + fname = str(function_tmpdir / "empty.githds") with open(fname, "w"): pass with pytest.raises(ValueError): @@ -151,7 +151,7 @@ def test_cellbudgetfile_read(example_data_path): v.close() -def test_cellbudgetfile_position(tmpdir, zonbud_model_path): +def test_cellbudgetfile_position(function_tmpdir, zonbud_model_path): fpth = str(zonbud_model_path / "freyberg.gitcbc") v = CellBudgetFile(fpth) assert isinstance(v, CellBudgetFile) @@ -177,7 +177,7 @@ def test_cellbudgetfile_position(tmpdir, zonbud_model_path): length = os.path.getsize(fpth) - ipos buffsize = 32 - opth = str(tmpdir / "end.cbc") + opth = str(function_tmpdir / "end.cbc") with open(opth, "wb") as fout: while length: chunk = min(buffsize, length) @@ -205,7 +205,7 @@ def test_cellbudgetfile_position(tmpdir, zonbud_model_path): assert np.array_equal(d1, d2), msg # Check error when reading empty file - fname = str(tmpdir / "empty.gitcbc") + fname = str(function_tmpdir / "empty.gitcbc") with open(fname, "w"): pass with pytest.raises(ValueError): diff --git a/autotest/test_gage.py b/autotest/test_gage.py index 181c4d07d5..35a2778981 100644 --- a/autotest/test_gage.py +++ b/autotest/test_gage.py @@ -41,10 +41,10 @@ def get_namefile_entries(fpth): return data -def test_gage(tmpdir): +def test_gage(function_tmpdir): mnam = "gage_test" - m = Modflow(modelname=mnam, model_ws=str(tmpdir)) + m = Modflow(modelname=mnam, model_ws=str(function_tmpdir)) dis = ModflowDis(m) spd = { (0, 0): ["print head"], @@ -65,7 +65,7 @@ def test_gage(tmpdir): m.write_input() # check that the gage output units entries are in the name file - fpth = os.path.join(str(tmpdir), f"{mnam}.nam") + fpth = os.path.join(str(function_tmpdir), f"{mnam}.nam") entries = get_namefile_entries(fpth) for idx, g in enumerate(gages): if g[0] < 0: @@ -82,10 +82,10 @@ def test_gage(tmpdir): assert found, f"{iu} not in name file entries" -def test_gage_files(tmpdir): +def test_gage_files(function_tmpdir): mnam = "gage_test_files" - m = Modflow(modelname=mnam, model_ws=str(tmpdir)) + m = Modflow(modelname=mnam, model_ws=str(function_tmpdir)) dis = ModflowDis(m) spd = { (0, 0): ["print head"], @@ -107,7 +107,7 @@ def test_gage_files(tmpdir): m.write_input() # check that the gage output file entries are in the name file - fpth = os.path.join(str(tmpdir), f"{mnam}.nam") + fpth = os.path.join(str(function_tmpdir), f"{mnam}.nam") entries = get_namefile_entries(fpth) for idx, f in enumerate(files): found = False @@ -126,10 +126,10 @@ def test_gage_files(tmpdir): ), f"{f} unit not equal to {iu} - name file unit = {iun}" -def test_gage_filenames0(tmpdir): +def test_gage_filenames0(function_tmpdir): mnam = "gage_test_filenames0" - m = Modflow(modelname=mnam, model_ws=str(tmpdir)) + m = Modflow(modelname=mnam, model_ws=str(function_tmpdir)) dis = ModflowDis(m) spd = { (0, 0): ["print head"], @@ -151,7 +151,7 @@ def test_gage_filenames0(tmpdir): m.write_input() # check that the gage output units entries are in the name file - fpth = os.path.join(str(tmpdir), f"{mnam}.nam") + fpth = os.path.join(str(function_tmpdir), f"{mnam}.nam") entries = get_namefile_entries(fpth) for idx, g in enumerate(gages): if g[0] < 0: @@ -168,10 +168,10 @@ def test_gage_filenames0(tmpdir): assert found, f"{iu} not in name file entries" -def test_gage_filenames(tmpdir): +def test_gage_filenames(function_tmpdir): mnam = "gage_test_filenames" - m = Modflow(modelname=mnam, model_ws=str(tmpdir)) + m = Modflow(modelname=mnam, model_ws=str(function_tmpdir)) dis = ModflowDis(m) spd = { (0, 0): ["print head"], @@ -193,7 +193,7 @@ def test_gage_filenames(tmpdir): m.write_input() # check that the gage output file entries are in the name file - fpth = os.path.join(str(tmpdir), f"{mnam}.nam") + fpth = os.path.join(str(function_tmpdir), f"{mnam}.nam") entries = get_namefile_entries(fpth) for idx, f in enumerate(filenames[1:]): found = False diff --git a/autotest/test_geospatial_util.py b/autotest/test_geospatial_util.py index 04a0954d8d..2ddc085184 100644 --- a/autotest/test_geospatial_util.py +++ b/autotest/test_geospatial_util.py @@ -1,5 +1,5 @@ import pytest -from autotest.conftest import requires_pkg +from modflow_devtools.markers import requires_pkg from flopy.utils.geometry import ( Collection, diff --git a/autotest/test_get_modflow.py b/autotest/test_get_modflow.py index 4ba9aaa836..ffa16ee09c 100644 --- a/autotest/test_get_modflow.py +++ b/autotest/test_get_modflow.py @@ -8,12 +8,10 @@ from urllib.error import HTTPError import pytest -from autotest.conftest import ( - get_project_root_path, - requires_github, - run_py_script, -) +from autotest.conftest import get_project_root_path from flaky import flaky +from modflow_devtools.markers import requires_github +from modflow_devtools.misc import run_py_script from flopy.utils import get_modflow from flopy.utils.get_modflow import get_release, get_releases, select_bindir @@ -134,13 +132,13 @@ def test_get_release(repo): @pytest.mark.parametrize("bindir", bindir_options.keys()) -def test_select_bindir(bindir, tmpdir): +def test_select_bindir(bindir, function_tmpdir): expected_path = bindir_options[bindir] if not os.access(expected_path, os.W_OK): pytest.skip(f"{expected_path} is not writable") selected = select_bindir(f":{bindir}") - if system() != 'Darwin': + if system() != "Darwin": assert selected == expected_path else: # for some reason sys.prefix can return different python @@ -162,8 +160,9 @@ def test_script_help(): @flaky @requires_github -def test_script_options(tmpdir, downloads_dir): - bindir = tmpdir / "bin1" +@pytest.mark.slow +def test_script_options(function_tmpdir, downloads_dir): + bindir = function_tmpdir / "bin1" assert not bindir.exists() stdout, stderr, returncode = run_get_modflow_script(bindir) @@ -196,7 +195,7 @@ def test_script_options(tmpdir, downloads_dir): assert len(files) > 20 # take only a few files using --subset, starting with invalid - bindir = tmpdir / "bin2" + bindir = function_tmpdir / "bin2" bindir.mkdir() stdout, stderr, returncode = run_get_modflow_script( bindir, "--subset", "mfnwt,mpx", "--downloads-dir", downloads_dir @@ -216,7 +215,7 @@ def test_script_options(tmpdir, downloads_dir): assert sorted(files) == ["mfnwt", "mfnwtdbl", "mp6"] # similar as before, but also specify a ostag - bindir = tmpdir / "bin3" + bindir = function_tmpdir / "bin3" bindir.mkdir() stdout, stderr, returncode = run_get_modflow_script( @@ -241,8 +240,8 @@ def test_script_options(tmpdir, downloads_dir): @requires_github @pytest.mark.slow @pytest.mark.parametrize("repo", repo_options.keys()) -def test_script(tmpdir, repo, downloads_dir): - bindir = str(tmpdir) +def test_script(function_tmpdir, repo, downloads_dir): + bindir = str(function_tmpdir) stdout, stderr, returncode = run_get_modflow_script( bindir, "--repo", @@ -253,7 +252,7 @@ def test_script(tmpdir, repo, downloads_dir): if rate_limit_msg in stderr: pytest.skip(f"GitHub {rate_limit_msg}") - paths = list(tmpdir.glob("*")) + paths = list(function_tmpdir.glob("*")) names = [p.name for p in paths] expected_names = [append_ext(p) for p in repo_options[repo]] assert set(names) >= set(expected_names) @@ -263,15 +262,15 @@ def test_script(tmpdir, repo, downloads_dir): @requires_github @pytest.mark.slow @pytest.mark.parametrize("repo", repo_options.keys()) -def test_python_api(tmpdir, repo, downloads_dir): - bindir = str(tmpdir) +def test_python_api(function_tmpdir, repo, downloads_dir): + bindir = str(function_tmpdir) try: get_modflow(bindir, repo=repo, downloads_dir=downloads_dir) except HTTPError as err: if err.code == 403: pytest.skip(f"GitHub {rate_limit_msg}") - paths = list(tmpdir.glob("*")) + paths = list(function_tmpdir.glob("*")) names = [p.name for p in paths] expected_names = [append_ext(p) for p in repo_options[repo]] assert set(names) >= set(expected_names) diff --git a/autotest/test_grid.py b/autotest/test_grid.py index 4da5125d29..4c824fabb6 100644 --- a/autotest/test_grid.py +++ b/autotest/test_grid.py @@ -4,11 +4,11 @@ import matplotlib import numpy as np import pytest -from autotest.conftest import requires_exe, requires_pkg from autotest.test_dis_cases import case_dis, case_disv from autotest.test_grid_cases import GridCases from flaky import flaky from matplotlib import pyplot as plt +from modflow_devtools.markers import requires_exe, requires_pkg from pytest_cases import parametrize_with_cases from flopy.discretization import StructuredGrid, UnstructuredGrid, VertexGrid @@ -452,7 +452,9 @@ def test_unstructured_from_argus_mesh(example_data_path): print(f" Number of nodes: {g.nnodes}") -def test_unstructured_from_verts_and_iverts(tmpdir, example_data_path): +def test_unstructured_from_verts_and_iverts( + function_tmpdir, example_data_path +): datapth = str(example_data_path / "unstructured") # simple functions to load vertices and incidence lists @@ -784,7 +786,7 @@ def test_unstructured_complete_grid_ctor(): @requires_pkg("shapely") @requires_exe("triangle") -def test_triangle_unstructured_grid(tmpdir): +def test_triangle_unstructured_grid(function_tmpdir): maximum_area = 30000.0 extent = (214270.0, 221720.0, 4366610.0, 4373510.0) domainpoly = [ @@ -796,7 +798,7 @@ def test_triangle_unstructured_grid(tmpdir): tri = Triangle( maximum_area=maximum_area, angle=30, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) tri.add_polygon(domainpoly) tri.build(verbose=False) @@ -817,13 +819,15 @@ def test_triangle_unstructured_grid(tmpdir): @requires_pkg("shapely", "scipy") @requires_exe("triangle") -def test_voronoi_vertex_grid(tmpdir): +def test_voronoi_vertex_grid(function_tmpdir): xmin = 0.0 xmax = 2.0 ymin = 0.0 ymax = 1.0 area_max = 0.05 - tri = Triangle(maximum_area=area_max, angle=30, model_ws=str(tmpdir)) + tri = Triangle( + maximum_area=area_max, angle=30, model_ws=str(function_tmpdir) + ) poly = np.array(((xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax))) tri.add_polygon(poly) tri.build(verbose=False) @@ -847,7 +851,7 @@ def test_voronoi_vertex_grid(tmpdir): @requires_exe("triangle") @requires_pkg("shapely", "scipy") @parametrize_with_cases("grid_info", cases=GridCases, prefix="voronoi") -def test_voronoi_grid(request, tmpdir, grid_info): +def test_voronoi_grid(request, function_tmpdir, grid_info): name = ( request.node.name.replace("/", "_") .replace("\\", "_") @@ -877,7 +881,7 @@ def test_voronoi_grid(request, tmpdir, grid_info): grid.ycellcenters[invalid_cells], "ro", ) - plt.savefig(os.path.join(str(tmpdir), f"{name}.png")) + plt.savefig(os.path.join(str(function_tmpdir), f"{name}.png")) assert ncpl == gridprops["ncpl"] or almost_right assert ( diff --git a/autotest/test_grid_cases.py b/autotest/test_grid_cases.py index 8dcea84d23..b546c83674 100644 --- a/autotest/test_grid_cases.py +++ b/autotest/test_grid_cases.py @@ -215,7 +215,7 @@ def unstructured_medium(self): return UnstructuredGrid(verts, iverts, ncpl=[len(iverts)]) - def voronoi_polygon(self, tmpdir): + def voronoi_polygon(self, function_tmpdir): ncpl = 3803 domain = [ [1831.381546, 6335.543757], @@ -242,7 +242,7 @@ def voronoi_polygon(self, tmpdir): angle = 30 tri = Triangle( - maximum_area=max_area, angle=angle, model_ws=str(tmpdir) + maximum_area=max_area, angle=angle, model_ws=str(function_tmpdir) ) tri.add_polygon(poly) tri.build(verbose=False) @@ -252,7 +252,7 @@ def voronoi_polygon(self, tmpdir): return ncpl, vor, gridprops, grid - def voronoi_rectangle(self, tmpdir): + def voronoi_rectangle(self, function_tmpdir): ncpl = 1679 xmin = 0.0 xmax = 2.0 @@ -265,7 +265,7 @@ def voronoi_rectangle(self, tmpdir): angle = 30 tri = Triangle( - maximum_area=max_area, angle=angle, model_ws=str(tmpdir) + maximum_area=max_area, angle=angle, model_ws=str(function_tmpdir) ) tri.add_polygon(poly) tri.build(verbose=False) @@ -275,7 +275,7 @@ def voronoi_rectangle(self, tmpdir): return ncpl, vor, gridprops, grid - def voronoi_circle(self, tmpdir): + def voronoi_circle(self, function_tmpdir): ncpl = 538 theta = np.arange(0.0, 2 * np.pi, 0.2) radius = 100.0 @@ -286,7 +286,7 @@ def voronoi_circle(self, tmpdir): angle = 30 tri = Triangle( - maximum_area=max_area, angle=angle, model_ws=str(tmpdir) + maximum_area=max_area, angle=angle, model_ws=str(function_tmpdir) ) tri.add_polygon(poly) tri.build(verbose=False) @@ -296,7 +296,7 @@ def voronoi_circle(self, tmpdir): return ncpl, vor, gridprops, grid - def voronoi_nested_circles(self, tmpdir): + def voronoi_nested_circles(self, function_tmpdir): ncpl = 300 theta = np.arange(0.0, 2 * np.pi, 0.2) @@ -316,7 +316,7 @@ def voronoi_nested_circles(self, tmpdir): angle = 30 tri = Triangle( - maximum_area=max_area, angle=angle, model_ws=str(tmpdir) + maximum_area=max_area, angle=angle, model_ws=str(function_tmpdir) ) for poly in polys: tri.add_polygon(poly) @@ -328,12 +328,12 @@ def voronoi_nested_circles(self, tmpdir): return ncpl, vor, gridprops, grid - def voronoi_polygons(self, tmpdir): + def voronoi_polygons(self, function_tmpdir): ncpl = 410 active_domain = [(0, 0), (100, 0), (100, 100), (0, 100)] area1 = [(10, 10), (40, 10), (40, 40), (10, 40)] area2 = [(60, 60), (80, 60), (80, 80), (60, 80)] - tri = Triangle(angle=30, model_ws=str(tmpdir)) + tri = Triangle(angle=30, model_ws=str(function_tmpdir)) tri.add_polygon(active_domain) tri.add_polygon(area1) tri.add_polygon(area2) @@ -349,13 +349,13 @@ def voronoi_polygons(self, tmpdir): return ncpl, vor, gridprops, grid - def voronoi_many_polygons(self, tmpdir): + def voronoi_many_polygons(self, function_tmpdir): ncpl = 1305 active_domain = [(0, 0), (100, 0), (100, 100), (0, 100)] area1 = [(10, 10), (40, 10), (40, 40), (10, 40)] area2 = [(70, 70), (90, 70), (90, 90), (70, 90)] - tri = Triangle(angle=30, model_ws=str(tmpdir)) + tri = Triangle(angle=30, model_ws=str(function_tmpdir)) # requirement that active_domain is first polygon to be added tri.add_polygon(active_domain) diff --git a/autotest/test_gridgen.py b/autotest/test_gridgen.py index c573b7fae9..b1c690f512 100644 --- a/autotest/test_gridgen.py +++ b/autotest/test_gridgen.py @@ -5,8 +5,9 @@ import matplotlib.pyplot as plt import numpy as np import pytest -from autotest.conftest import has_pkg, requires_exe, requires_pkg from matplotlib.collections import LineCollection, PathCollection, QuadMesh +from modflow_devtools.markers import requires_exe, requires_pkg +from modflow_devtools.misc import has_pkg import flopy from flopy.utils.gridgen import Gridgen @@ -15,7 +16,7 @@ @pytest.mark.slow @requires_exe("mf6", "gridgen") @requires_pkg("shapely") -def test_mf6disv(tmpdir): +def test_mf6disv(function_tmpdir): from shapely.geometry import Polygon name = "dummy" @@ -30,7 +31,7 @@ def test_mf6disv(tmpdir): # Create a dummy model and regular grid to use as the base grid for gridgen sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=str(tmpdir), exe_name="mf6" + sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" ) gwf = flopy.mf6.ModflowGwf(sim, modelname=name) @@ -46,7 +47,7 @@ def test_mf6disv(tmpdir): ) # Create and build the gridgen model with a refined area in the middle - g = Gridgen(gwf.modelgrid, model_ws=str(tmpdir)) + g = Gridgen(gwf.modelgrid, model_ws=str(function_tmpdir)) polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])] g.add_refinement_features(polys, "polygon", 3, range(nlay)) g.build() @@ -63,7 +64,7 @@ def test_mf6disv(tmpdir): # build run and post-process the MODFLOW 6 model name = "mymodel" sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=str(tmpdir), exe_name="mf6" + sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" ) tdis = flopy.mf6.ModflowTdis(sim) ims = flopy.mf6.ModflowIms(sim, linear_acceleration="bicgstab") @@ -87,9 +88,9 @@ def test_mf6disv(tmpdir): gwf.modelgrid.set_coord_info(angrot=15) # write grid and model shapefiles - fname = os.path.join(str(tmpdir), "grid.shp") + fname = os.path.join(str(function_tmpdir), "grid.shp") gwf.modelgrid.write_shapefile(fname) - fname = os.path.join(str(tmpdir), "model.shp") + fname = os.path.join(str(function_tmpdir), "model.shp") gwf.export(fname) sim.run_simulation(silent=True) @@ -115,7 +116,7 @@ def test_mf6disv(tmpdir): ax.set_title(f"Layer {ilay + 1}") pmv.plot_vector(spdis["qx"], spdis["qy"], color="white") fname = "results.png" - fname = os.path.join(str(tmpdir), fname) + fname = os.path.join(str(function_tmpdir), fname) plt.savefig(fname) plt.close("all") @@ -123,7 +124,10 @@ def test_mf6disv(tmpdir): # load up the vertex example problem name = "mymodel" sim = flopy.mf6.MFSimulation.load( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=str(tmpdir) + sim_name=name, + version="mf6", + exe_name="mf6", + sim_ws=str(function_tmpdir), ) # get gwf model gwf = sim.get_model(name) @@ -151,7 +155,7 @@ def test_mf6disv(tmpdir): @pytest.mark.slow @requires_exe("mf6", "gridgen") @requires_pkg("shapely", "shapefile") -def test_mf6disu(tmpdir): +def test_mf6disu(function_tmpdir): from shapely.geometry import Polygon name = "dummy" @@ -166,7 +170,7 @@ def test_mf6disu(tmpdir): # Create a dummy model and regular grid to use as the base grid for gridgen sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=str(tmpdir), exe_name="mf6" + sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" ) gwf = flopy.mf6.ModflowGwf(sim, modelname=name) @@ -182,7 +186,7 @@ def test_mf6disu(tmpdir): ) # Create and build the gridgen model with a refined area in the middle - g = Gridgen(gwf.modelgrid, model_ws=str(tmpdir)) + g = Gridgen(gwf.modelgrid, model_ws=str(function_tmpdir)) polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])] g.add_refinement_features(polys, "polygon", 3, layers=[0]) g.build() @@ -197,7 +201,7 @@ def test_mf6disu(tmpdir): # build run and post-process the MODFLOW 6 model name = "mymodel" sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=str(tmpdir), exe_name="mf6" + sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" ) tdis = flopy.mf6.ModflowTdis(sim) ims = flopy.mf6.ModflowIms(sim, linear_acceleration="bicgstab") @@ -227,9 +231,9 @@ def test_mf6disu(tmpdir): assert np.allclose(gwf.modelgrid.ncpl, np.array([436, 184, 112])) # write grid and model shapefiles - fname = os.path.join(str(tmpdir), "grid.shp") + fname = os.path.join(str(function_tmpdir), "grid.shp") gwf.modelgrid.write_shapefile(fname) - fname = os.path.join(str(tmpdir), "model.shp") + fname = os.path.join(str(function_tmpdir), "model.shp") gwf.export(fname) sim.run_simulation(silent=True) @@ -256,7 +260,7 @@ def test_mf6disu(tmpdir): ax.set_title(f"Layer {ilay + 1}") pmv.plot_vector(spdis["qx"], spdis["qy"], color="white") fname = "results.png" - fname = os.path.join(str(tmpdir), fname) + fname = os.path.join(str(function_tmpdir), fname) plt.savefig(fname) plt.close("all") @@ -288,7 +292,10 @@ def test_mf6disu(tmpdir): # load up the disu example problem name = "mymodel" sim = flopy.mf6.MFSimulation.load( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=str(tmpdir) + sim_name=name, + version="mf6", + exe_name="mf6", + sim_ws=str(function_tmpdir), ) gwf = sim.get_model(name) @@ -319,7 +326,7 @@ def test_mf6disu(tmpdir): @pytest.mark.slow @requires_exe("mfusg", "gridgen") @requires_pkg("shapely", "shapefile") -def test_mfusg(tmpdir): +def test_mfusg(function_tmpdir): from shapely.geometry import Polygon name = "dummy" @@ -333,7 +340,7 @@ def test_mfusg(tmpdir): botm = [top - k * dz for k in range(1, nlay + 1)] # create dummy model and dis package for gridgen - m = flopy.modflow.Modflow(modelname=name, model_ws=str(tmpdir)) + m = flopy.modflow.Modflow(modelname=name, model_ws=str(function_tmpdir)) dis = flopy.modflow.ModflowDis( m, nlay=nlay, @@ -346,7 +353,7 @@ def test_mfusg(tmpdir): ) # Create and build the gridgen model with a refined area in the middle - g = Gridgen(m.modelgrid, model_ws=str(tmpdir)) + g = Gridgen(m.modelgrid, model_ws=str(function_tmpdir)) polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])] g.add_refinement_features(polys, "polygon", 3, layers=[0]) g.build() @@ -364,7 +371,7 @@ def test_mfusg(tmpdir): name = "mymodel" m = flopy.mfusg.MfUsg( modelname=name, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), exe_name="mfusg", structured=False, ) @@ -386,7 +393,7 @@ def test_mfusg(tmpdir): m.run_model() # head is returned as a list of head arrays for each layer - head_file = os.path.join(str(tmpdir), f"{name}.hds") + head_file = os.path.join(str(function_tmpdir), f"{name}.hds") head = flopy.utils.HeadUFile(head_file).get_data() f = plt.figure(figsize=(10, 10)) @@ -404,7 +411,7 @@ def test_mfusg(tmpdir): ax.set_title(f"Layer {ilay + 1}") # pmv.plot_specific_discharge(spdis, color='white') fname = "results.png" - fname = os.path.join(str(tmpdir), fname) + fname = os.path.join(str(function_tmpdir), fname) plt.savefig(fname) plt.close("all") @@ -440,7 +447,7 @@ def test_mfusg(tmpdir): # also test load of unstructured LPF with keywords lpf2 = flopy.mfusg.MfUsgLpf.load( - os.path.join(str(tmpdir), f"{name}.lpf"), m, check=False + os.path.join(str(function_tmpdir), f"{name}.lpf"), m, check=False ) msg = "NOCVCORRECTION and NOVFC should be in lpf options but at least one is not." assert ( @@ -449,16 +456,16 @@ def test_mfusg(tmpdir): ), msg # test disu, bas6, lpf shapefile export for mfusg unstructured models - m.disu.export(os.path.join(str(tmpdir), f"{name}_disu.shp")) - m.bas6.export(os.path.join(str(tmpdir), f"{name}_bas6.shp")) - m.lpf.export(os.path.join(str(tmpdir), f"{name}_lpf.shp")) - m.export(os.path.join(str(tmpdir), f"{name}.shp")) + m.disu.export(os.path.join(str(function_tmpdir), f"{name}_disu.shp")) + m.bas6.export(os.path.join(str(function_tmpdir), f"{name}_bas6.shp")) + m.lpf.export(os.path.join(str(function_tmpdir), f"{name}_lpf.shp")) + m.export(os.path.join(str(function_tmpdir), f"{name}.shp")) @pytest.mark.slow @requires_exe("mfusg", "gridgen") @requires_pkg("shapely") -def test_gridgen(tmpdir): +def test_gridgen(function_tmpdir): # define the base grid and then create a couple levels of nested # refinement Lx = 10000.0 @@ -499,7 +506,7 @@ def test_gridgen(tmpdir): ms_u = flopy.mfusg.MfUsg( modelname="mymfusgmodel", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) dis_usg = flopy.modflow.ModflowDis( ms_u, @@ -513,7 +520,7 @@ def test_gridgen(tmpdir): ) gridgen = Path(which("gridgen")).name - ws = str(tmpdir) + ws = str(function_tmpdir) g = Gridgen(ms.modelgrid, model_ws=ws, exe_name=gridgen) g6 = Gridgen(gwf.modelgrid, model_ws=ws, exe_name=gridgen) gu = Gridgen( diff --git a/autotest/test_gridintersect.py b/autotest/test_gridintersect.py index 7469e8f67a..43adebd80b 100644 --- a/autotest/test_gridintersect.py +++ b/autotest/test_gridintersect.py @@ -3,7 +3,8 @@ import matplotlib.pyplot as plt import numpy as np import pytest -from autotest.conftest import has_pkg, requires_pkg +from modflow_devtools.markers import requires_pkg +from modflow_devtools.misc import has_pkg import flopy.discretization as fgrid import flopy.plot as fplot diff --git a/autotest/test_gridutil.py b/autotest/test_gridutil.py index 810d2a4a5f..3b66cb4fd7 100644 --- a/autotest/test_gridutil.py +++ b/autotest/test_gridutil.py @@ -3,7 +3,7 @@ import numpy as np import pytest -from flopy.utils.gridutil import get_lni, get_disu_kwargs, uniform_flow_field +from flopy.utils.gridutil import get_disu_kwargs, get_lni, uniform_flow_field @pytest.mark.parametrize( @@ -56,15 +56,36 @@ def test_get_lni_infers_layer_count_when_int_ncpl(ncpl, nodes, expected): assert ln == expected[i] -@pytest.mark.parametrize("nlay, nrow, ncol, delr, delc, tp, botm", - [ - (1, 61, 61, np.array(61 * [50]), np.array(61 * [50]), np.array([-10]), np.array([-30.0, -50.0])), - (2, 61, 61, np.array(61 * [50]), np.array(61 * [50]), np.array([-10]), np.array([-30.0, -50.0])), - ]) +@pytest.mark.parametrize( + "nlay, nrow, ncol, delr, delc, tp, botm", + [ + ( + 1, + 61, + 61, + np.array(61 * [50]), + np.array(61 * [50]), + np.array([-10]), + np.array([-30.0, -50.0]), + ), + ( + 2, + 61, + 61, + np.array(61 * [50]), + np.array(61 * [50]), + np.array([-10]), + np.array([-30.0, -50.0]), + ), + ], +) def test_get_disu_kwargs(nlay, nrow, ncol, delr, delc, tp, botm): - kwargs = get_disu_kwargs(nlay=nlay, nrow=nrow, ncol=ncol, delr=delr, delc=delc, tp=tp, botm=botm) + kwargs = get_disu_kwargs( + nlay=nlay, nrow=nrow, ncol=ncol, delr=delr, delc=delc, tp=tp, botm=botm + ) from pprint import pprint + pprint(kwargs["area"]) assert kwargs["nodes"] == nlay * nrow * ncol @@ -81,16 +102,19 @@ def test_get_disu_kwargs(nlay, nrow, ncol, delr, delc, tp, botm): # print(kwargs["nja"]) -@pytest.mark.parametrize("qx, qy, qz, nlay, nrow, ncol", [ - (1, 0, 0, 1, 1, 10), - (0, 1, 0, 1, 1, 10), - (0, 0, 1, 1, 1, 10), - (1, 0, 0, 1, 10, 10), - (1, 0, 0, 2, 10, 10), - (1, 1, 0, 2, 10, 10), - (1, 1, 1, 2, 10, 10), - (2, 1, 1, 2, 10, 10) -]) +@pytest.mark.parametrize( + "qx, qy, qz, nlay, nrow, ncol", + [ + (1, 0, 0, 1, 1, 10), + (0, 1, 0, 1, 1, 10), + (0, 0, 1, 1, 1, 10), + (1, 0, 0, 1, 10, 10), + (1, 0, 0, 2, 10, 10), + (1, 1, 0, 2, 10, 10), + (1, 1, 1, 2, 10, 10), + (2, 1, 1, 2, 10, 10), + ], +) def test_uniform_flow_field(qx, qy, qz, nlay, nrow, ncol): shape = nlay, nrow, ncol spdis, flowja = uniform_flow_field(qx, qy, qz, shape) diff --git a/autotest/test_headufile.py b/autotest/test_headufile.py index 8b71a61b20..7f767c5f97 100644 --- a/autotest/test_headufile.py +++ b/autotest/test_headufile.py @@ -1,7 +1,7 @@ from pathlib import Path import pytest -from autotest.conftest import requires_exe, requires_pkg +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.discretization import UnstructuredGrid from flopy.mfusg import MfUsg, MfUsgDisU, MfUsgLpf, MfUsgSms diff --git a/autotest/test_hydmodfile.py b/autotest/test_hydmodfile.py index 6f8ddef5aa..25f33afeb7 100644 --- a/autotest/test_hydmodfile.py +++ b/autotest/test_hydmodfile.py @@ -2,7 +2,8 @@ import numpy as np import pytest -from autotest.conftest import has_pkg, requires_pkg +from modflow_devtools.markers import requires_pkg +from modflow_devtools.misc import has_pkg from flopy.modflow import Modflow, ModflowHyd from flopy.utils import HydmodObs, Mf6Obs @@ -18,11 +19,11 @@ def hydmod_model_path(example_data_path): return example_data_path / "hydmod_test" -def test_hydmodfile_create(tmpdir): - m = Modflow("test", model_ws=str(tmpdir)) +def test_hydmodfile_create(function_tmpdir): + m = Modflow("test", model_ws=str(function_tmpdir)) hyd = ModflowHyd(m) m.hyd.write_file() - pth = str(tmpdir / "test.hyd") + pth = str(function_tmpdir / "test.hyd") hydload = ModflowHyd.load(pth, m) assert np.array_equal( hyd.obsdata, hydload.obsdata @@ -51,7 +52,7 @@ def test_hydmodfile_create(tmpdir): hyd = ModflowHyd(m, obsdata=obsdata) -def test_hydmodfile_load(tmpdir, hydmod_model_path): +def test_hydmodfile_load(function_tmpdir, hydmod_model_path): model = "test1tr.nam" m = Modflow.load( model, version="mf2005", model_ws=str(hydmod_model_path), verbose=True @@ -61,7 +62,7 @@ def test_hydmodfile_load(tmpdir, hydmod_model_path): hydref, ModflowHyd ), "Did not load hydmod package...test1tr.hyd" - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) m.hyd.write_file() pth = str(hydmod_model_path / "test1tr.hyd") diff --git a/autotest/test_lake_connections.py b/autotest/test_lake_connections.py index 681522f5c9..6ff9a0fe17 100644 --- a/autotest/test_lake_connections.py +++ b/autotest/test_lake_connections.py @@ -2,7 +2,7 @@ import numpy as np import pytest -from autotest.conftest import requires_exe, requires_pkg +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.discretization import StructuredGrid from flopy.mf6 import ( @@ -139,7 +139,7 @@ def get_lake_connection_data( @requires_exe("mf6") -def test_base_run(tmpdir, example_data_path): +def test_base_run(function_tmpdir, example_data_path): mpath = example_data_path / "mf6-freyberg" sim = MFSimulation().load( sim_name="freyberg", @@ -147,7 +147,7 @@ def test_base_run(tmpdir, example_data_path): exe_name="mf6", verbosity_level=0, ) - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # remove the well package gwf = sim.get_model("freyberg") @@ -162,27 +162,27 @@ def test_base_run(tmpdir, example_data_path): bot = gwf.dis.botm.array.squeeze() export_ascii_grid( gwf.modelgrid, - str(tmpdir / "bot.asc"), + str(function_tmpdir / "bot.asc"), bot, ) top = gwf.output.head().get_data().squeeze() + 2.0 top = np.where(gwf.dis.idomain.array.squeeze() < 1.0, 0.0, top) export_ascii_grid( gwf.modelgrid, - str(tmpdir / "top.asc"), + str(function_tmpdir / "top.asc"), top, ) k11 = gwf.npf.k.array.squeeze() export_ascii_grid( gwf.modelgrid, - str(tmpdir / "k11.asc"), + str(function_tmpdir / "k11.asc"), k11, ) @requires_exe("mf6") @requires_pkg("rasterio", "rasterstats") -def test_lake(tmpdir, example_data_path): +def test_lake(function_tmpdir, example_data_path): mpath = example_data_path / "mf6-freyberg" top = Raster.load(str(mpath / "top.asc")) bot = Raster.load(str(mpath / "bot.asc")) @@ -196,7 +196,7 @@ def test_lake(tmpdir, example_data_path): ) # change the workspace - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # get groundwater flow model gwf = sim.get_model("freyberg") @@ -301,7 +301,7 @@ def test_lake(tmpdir, example_data_path): @requires_exe("mf6") -def test_embedded_lak_ex01(tmpdir, example_data_path): +def test_embedded_lak_ex01(function_tmpdir, example_data_path): nper = 1 nlay, nrow, ncol = 5, 17, 17 shape3d = (nlay, nrow, ncol) @@ -395,7 +395,7 @@ def test_embedded_lak_ex01(tmpdir, example_data_path): sim = MFSimulation( sim_name=name, exe_name="mf6", - sim_ws=str(tmpdir), + sim_ws=str(function_tmpdir), ) tdis = ModflowTdis( sim, diff --git a/autotest/test_lgr.py b/autotest/test_lgr.py index c9646c9fc0..9fd64dcdd6 100644 --- a/autotest/test_lgr.py +++ b/autotest/test_lgr.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from autotest.conftest import requires_exe from flaky import flaky +from modflow_devtools.markers import requires_exe import flopy @@ -165,7 +165,7 @@ def singleModel( # https://github.com/w-bonelli/flopy/runs/7744805897?check_suite_focus=true#step:8:1832 @flaky @requires_exe("mflgr") -def test_simple_lgrmodel_from_scratch(tmpdir): +def test_simple_lgrmodel_from_scratch(function_tmpdir): # coordinates and extend Mother Lx_m = 1500.0 Ly_m = 2500.0 @@ -238,7 +238,7 @@ def test_simple_lgrmodel_from_scratch(tmpdir): yul_c, proj4_str, "mflgr", - rundir=str(tmpdir), + rundir=str(function_tmpdir), welInfo=welInfo, startingHead=-2.0, ) @@ -268,7 +268,7 @@ def test_simple_lgrmodel_from_scratch(tmpdir): yul_m, proj4_str, "mflgr", - rundir=str(tmpdir), + rundir=str(function_tmpdir), welInfo=welInfo, startingHead=-2.0, ) @@ -310,7 +310,7 @@ def test_simple_lgrmodel_from_scratch(tmpdir): parent=mother, children=[child], children_data=childData, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), external_path=None, verbose=False, ) diff --git a/autotest/test_listbudget.py b/autotest/test_listbudget.py index 815699f220..e8060c1fbf 100644 --- a/autotest/test_listbudget.py +++ b/autotest/test_listbudget.py @@ -3,7 +3,8 @@ import numpy as np import pytest -from autotest.conftest import has_pkg, requires_pkg +from modflow_devtools.markers import requires_pkg +from modflow_devtools.misc import has_pkg from flopy.utils import ( Mf6ListBudget, diff --git a/autotest/test_mf6.py b/autotest/test_mf6.py index 4655515708..a07fbaae74 100644 --- a/autotest/test_mf6.py +++ b/autotest/test_mf6.py @@ -2,7 +2,7 @@ import numpy as np import pytest -from autotest.conftest import requires_exe +from modflow_devtools.markers import requires_exe import flopy from flopy.mf6 import ( @@ -261,8 +261,8 @@ def test_string_to_file_path(): assert rel_path == new_path, "Relative path error" -def test_subdir(tmpdir): - sim = MFSimulation(sim_ws=str(tmpdir)) +def test_subdir(function_tmpdir): + sim = MFSimulation(sim_ws=str(function_tmpdir)) tdis = ModflowTdis(sim) gwf = ModflowGwf(sim, model_rel_path="level2") ims = ModflowIms(sim) @@ -296,7 +296,7 @@ def test_subdir(tmpdir): ), "Something wrong with model external paths" -def test_binary_read(tmpdir): +def test_binary_read(function_tmpdir): test_ex_name = "binary_read" nlay = 3 nrow = 10 @@ -330,7 +330,7 @@ def test_binary_read(tmpdir): pd = PackageDimensions([md], None, "integration") dd = DataDimensions(pd, mfstruct) - binfile = str(tmpdir / "structured_layered.hds") + binfile = str(function_tmpdir / "structured_layered.hds") with open(binfile, "wb") as foo: for ix, a in enumerate(arr): write_head(foo, a, ilay=ix) @@ -342,7 +342,7 @@ def test_binary_read(tmpdir): assert np.allclose(arr, arr2), "Binary read for layered Structured failed" - binfile = str(tmpdir / "structured_flat.hds") + binfile = str(function_tmpdir / "structured_flat.hds") with open(binfile, "wb") as foo: a = np.expand_dims(np.ravel(arr), axis=0) write_head(foo, a, ilay=1) @@ -360,7 +360,7 @@ def test_binary_read(tmpdir): fa = MFFileAccessArray(mfstruct, dd, sim_data, None, None) - binfile = str(tmpdir / "vertex_layered.hds") + binfile = str(function_tmpdir / "vertex_layered.hds") with open(binfile, "wb") as foo: tarr = arr.reshape((nlay, 1, ncpl)) for ix, a in enumerate(tarr): @@ -372,7 +372,7 @@ def test_binary_read(tmpdir): assert np.allclose(arr, arr2), "Binary read for layered Vertex failed" - binfile = str(tmpdir / "vertex_flat.hds") + binfile = str(function_tmpdir / "vertex_flat.hds") with open(binfile, "wb") as foo: a = np.expand_dims(np.ravel(arr), axis=0) write_head(foo, a, ilay=1) @@ -391,7 +391,7 @@ def test_binary_read(tmpdir): fa = MFFileAccessArray(mfstruct, dd, sim_data, None, None) - binfile = str(tmpdir / "unstructured.hds") + binfile = str(function_tmpdir / "unstructured.hds") with open(binfile, "wb") as foo: a = np.expand_dims(arr, axis=0) write_head(foo, a, ilay=1) @@ -404,8 +404,8 @@ def test_binary_read(tmpdir): @requires_exe("mf6") -def test_write_simulation(tmpdir): - sim = MFSimulation(sim_ws=str(tmpdir)) +def test_write_simulation(function_tmpdir): + sim = MFSimulation(sim_ws=str(function_tmpdir)) assert isinstance(sim, MFSimulation) tdis = ModflowTdis(sim) @@ -493,7 +493,7 @@ def test_write_simulation(tmpdir): sim.write_simulation() # Verify files were written - assert os.path.isfile(os.path.join(str(tmpdir), "mfsim.nam")) + assert os.path.isfile(os.path.join(str(function_tmpdir), "mfsim.nam")) exts_model = [ "nam", "dis", @@ -520,15 +520,15 @@ def test_write_simulation(tmpdir): ] exts_sim = ["gwfgwf", "ims", "tdis"] for ext in exts_model: - fname = os.path.join(str(tmpdir), f"model.{ext}") + fname = os.path.join(str(function_tmpdir), f"model.{ext}") assert os.path.isfile(fname), f"{fname} not found" for ext in exts_sim: - fname = os.path.join(str(tmpdir), f"sim.{ext}") + fname = os.path.join(str(function_tmpdir), f"sim.{ext}") assert os.path.isfile(fname), f"{fname} not found" @requires_exe("mf6") -def test_create_and_run_model(tmpdir): +def test_create_and_run_model(function_tmpdir): # names sim_name = "testsim" model_name = "testmodel" @@ -537,7 +537,10 @@ def test_create_and_run_model(tmpdir): # set up simulation tdis_name = f"{sim_name}.tdis" sim = MFSimulation( - sim_name=sim_name, version="mf6", exe_name=exe_name, sim_ws=str(tmpdir) + sim_name=sim_name, + version="mf6", + exe_name=exe_name, + sim_ws=str(function_tmpdir), ) tdis_rc = [(6.0, 2, 1.0), (6.0, 3, 1.0)] tdis = mftdis.ModflowTdis( @@ -652,7 +655,7 @@ def test_create_and_run_model(tmpdir): @requires_exe("mf6") -def test_get_set_data_record(tmpdir): +def test_get_set_data_record(function_tmpdir): # names sim_name = "testrecordsim" model_name = "testrecordmodel" @@ -661,7 +664,10 @@ def test_get_set_data_record(tmpdir): # set up simulation tdis_name = f"{sim_name}.tdis" sim = MFSimulation( - sim_name=sim_name, version="mf6", exe_name=exe_name, sim_ws=str(tmpdir) + sim_name=sim_name, + version="mf6", + exe_name=exe_name, + sim_ws=str(function_tmpdir), ) tdis_rc = [(10.0, 4, 1.0), (6.0, 3, 1.0)] tdis = mftdis.ModflowTdis( @@ -932,11 +938,11 @@ def test_get_set_data_record(tmpdir): @requires_exe("mf6") -def test_output(tmpdir, example_data_path): +def test_output(function_tmpdir, example_data_path): ex_name = "test001e_UZF_3lay" sim_ws = str(example_data_path / "mf6" / ex_name) sim = MFSimulation.load(sim_ws=sim_ws, exe_name="mf6") - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) sim.write_simulation() success, buff = sim.run_simulation() assert success, f"simulation {sim.name} did not run" @@ -988,7 +994,7 @@ def test_output(tmpdir, example_data_path): @requires_exe("mf6") @pytest.mark.slow -def test_output_add_observation(tmpdir, example_data_path): +def test_output_add_observation(function_tmpdir, example_data_path): model_name = "lakeex2a" sim_ws = str(example_data_path / "mf6" / "test045_lake2tr") sim = MFSimulation.load(sim_ws=sim_ws, exe_name="mf6") @@ -1010,7 +1016,7 @@ def test_output_add_observation(tmpdir, example_data_path): filename=obs_file, digits=10, print_input=True, continuous=obs_dict ) - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) sim.write_simulation() success, buff = sim.run_simulation() @@ -1025,7 +1031,7 @@ def test_output_add_observation(tmpdir, example_data_path): @requires_exe("mf6") -def test_array(tmpdir): +def test_array(function_tmpdir): # get_data # empty data in period block vs data repeating # array @@ -1035,7 +1041,7 @@ def test_array(tmpdir): sim_name = "test_array" model_name = "test_array" - out_dir = str(tmpdir) + out_dir = str(function_tmpdir) tdis_name = "{}.tdis".format(sim_name) sim = MFSimulation( sim_name=sim_name, version="mf6", exe_name="mf6", sim_ws=out_dir @@ -1342,7 +1348,7 @@ def test_array(tmpdir): @requires_exe("mf6") -def test_multi_model(tmpdir): +def test_multi_model(function_tmpdir): # init paths test_ex_name = "test_multi_model" model_names = ["gwf_model_1", "gwf_model_2", "gwt_model_1", "gwt_model_2"] @@ -1361,7 +1367,7 @@ def test_multi_model(tmpdir): sim_name=test_ex_name, version="mf6", exe_name="mf6", - sim_ws=str(tmpdir), + sim_ws=str(function_tmpdir), ) # create tdis package tdis = ModflowTdis( @@ -1536,7 +1542,7 @@ def test_multi_model(tmpdir): sim.run_simulation() # reload simulation - sim2 = MFSimulation.load(sim_ws=str(tmpdir)) + sim2 = MFSimulation.load(sim_ws=str(function_tmpdir)) # check ims registration solution_recarray = sim2.name_file.solutiongroup diff --git a/autotest/test_mfnwt.py b/autotest/test_mfnwt.py index 790d8f95a1..cc2c23dad9 100644 --- a/autotest/test_mfnwt.py +++ b/autotest/test_mfnwt.py @@ -3,8 +3,9 @@ import numpy as np import pytest -from autotest.conftest import get_example_data_path, requires_exe +from autotest.conftest import get_example_data_path from matplotlib import pyplot as plt +from modflow_devtools.markers import requires_exe from flopy.modflow import ( Modflow, @@ -40,7 +41,7 @@ def fnwt_model_files(pattern): @pytest.mark.parametrize("nwtfile", fnwt_model_files(".nwt")) -def test_nwt_pack_load(tmpdir, nwtfile): +def test_nwt_pack_load(function_tmpdir, nwtfile): ws = os.path.dirname(nwtfile) ml = Modflow(model_ws=ws, version="mfnwt") if "fmt." in nwtfile.lower(): @@ -53,14 +54,14 @@ def test_nwt_pack_load(tmpdir, nwtfile): assert isinstance(nwt, ModflowNwt), msg # write the new file in the working directory - ml.change_model_ws(str(tmpdir)) + ml.change_model_ws(str(function_tmpdir)) nwt.write_file() - fn = os.path.join(str(tmpdir), ml.name + ".nwt") + fn = os.path.join(str(function_tmpdir), ml.name + ".nwt") msg = f"{os.path.basename(nwtfile)} write unsuccessful" assert os.path.isfile(fn), msg - ml2 = Modflow(model_ws=str(tmpdir), version="mfnwt") + ml2 = Modflow(model_ws=str(function_tmpdir), version="mfnwt") nwt2 = ModflowNwt.load(fn, ml2) lst = [ a @@ -76,7 +77,7 @@ def test_nwt_pack_load(tmpdir, nwtfile): @pytest.mark.parametrize("namfile", fnwt_model_files(".nam")) -def test_nwt_model_load(tmpdir, namfile): +def test_nwt_model_load(function_tmpdir, namfile): f = os.path.basename(namfile) model_ws = os.path.dirname(namfile) ml = Modflow.load(f, model_ws=model_ws) @@ -84,11 +85,11 @@ def test_nwt_model_load(tmpdir, namfile): assert isinstance(ml, Modflow), msg # change the model work space and rewrite the files - ml.change_model_ws(str(tmpdir)) + ml.change_model_ws(str(function_tmpdir)) ml.write_input() # reload the model that was just written - ml2 = Modflow.load(f, model_ws=str(tmpdir)) + ml2 = Modflow.load(f, model_ws=str(function_tmpdir)) # check that the data are the same for pn in ml.get_package_list(): @@ -102,13 +103,13 @@ def test_nwt_model_load(tmpdir, namfile): for l in lst: msg = ( "{}.{} data instantiated from {} load is not the same as " - "written to {}".format(pn, l, model_ws, str(tmpdir)) + "written to {}".format(pn, l, model_ws, str(function_tmpdir)) ) assert p[l] == p2[l], msg @requires_exe("mfnwt") -def test_mfnwt_run(tmpdir): +def test_mfnwt_run(function_tmpdir): modelname = "watertable" # model dimensions @@ -175,7 +176,7 @@ def test_mfnwt_run(tmpdir): mf = Modflow( modelname=modelname, exe_name="mfnwt", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), version="mfnwt", ) dis = ModflowDis( @@ -201,7 +202,7 @@ def test_mfnwt_run(tmpdir): # remove existing heads results, if necessary try: - Path(tmpdir / f"{modelname}.hds").unlink() + Path(function_tmpdir / f"{modelname}.hds").unlink() except: pass @@ -210,7 +211,7 @@ def test_mfnwt_run(tmpdir): # Read the simulated MODFLOW-2005 model results # Create the headfile object - headfile = str(tmpdir / f"{modelname}.hds") + headfile = str(function_tmpdir / f"{modelname}.hds") headobj = HeadFile(headfile, precision="single") times = headobj.get_times() head = headobj.get_data(totim=times[-1]) @@ -239,4 +240,4 @@ def test_mfnwt_run(tmpdir): ax.set_xlabel("Horizontal distance, in m") ax.set_ylabel("Percent Error") - fig.savefig(str(tmpdir / f"{modelname}.png")) + fig.savefig(str(function_tmpdir / f"{modelname}.png")) diff --git a/autotest/test_mfreadnam.py b/autotest/test_mfreadnam.py index 98a42799b8..412b2423a4 100644 --- a/autotest/test_mfreadnam.py +++ b/autotest/test_mfreadnam.py @@ -1,15 +1,19 @@ import pytest from autotest.conftest import get_example_data_path + from flopy.utils.mfreadnam import get_entries_from_namefile _example_data_path = get_example_data_path() -@pytest.mark.parametrize("path", [ - _example_data_path / "mf6" / "test001a_Tharmonic" / "mfsim.nam", - _example_data_path / "mf6" / "test001e_UZF_3lay" / "mfsim.nam", - _example_data_path / "mf6-freyberg" / "mfsim.nam", -]) +@pytest.mark.parametrize( + "path", + [ + _example_data_path / "mf6" / "test001a_Tharmonic" / "mfsim.nam", + _example_data_path / "mf6" / "test001e_UZF_3lay" / "mfsim.nam", + _example_data_path / "mf6-freyberg" / "mfsim.nam", + ], +) def test_get_entries_from_namefile_mf6(path): package = "IMS6" entries = get_entries_from_namefile(path, ftype=package) @@ -21,9 +25,12 @@ def test_get_entries_from_namefile_mf6(path): @pytest.mark.skip(reason="only supports mf6 namefiles") -@pytest.mark.parametrize("path", [ - _example_data_path / "mf6-freyberg" / "freyberg.nam", -]) +@pytest.mark.parametrize( + "path", + [ + _example_data_path / "mf6-freyberg" / "freyberg.nam", + ], +) def test_get_entries_from_namefile_mf2005(path): package = "IC6" entries = get_entries_from_namefile(path, ftype=package) @@ -31,4 +38,4 @@ def test_get_entries_from_namefile_mf2005(path): entry = entries[0] assert path.parent.name in entry[0] - assert entry[1] == package \ No newline at end of file + assert entry[1] == package diff --git a/autotest/test_mnw.py b/autotest/test_mnw.py index fb5420c912..a08a32c1f3 100644 --- a/autotest/test_mnw.py +++ b/autotest/test_mnw.py @@ -3,7 +3,7 @@ import numpy as np import pytest -from autotest.conftest import requires_pkg +from modflow_devtools.markers import requires_pkg from flopy.modflow import Mnw, Modflow, ModflowDis, ModflowMnw2 @@ -22,7 +22,7 @@ def mnw1_path(example_data_path): return example_data_path / "mf2005_test" -def test_load(tmpdir, example_data_path, mnw2_examples_path): +def test_load(function_tmpdir, example_data_path, mnw2_examples_path): """t027 test load of MNW2 Package""" # load in the test problem (1 well, 3 stress periods) m = Modflow.load( @@ -31,7 +31,7 @@ def test_load(tmpdir, example_data_path, mnw2_examples_path): verbose=True, forgive=False, ) - ws = str(tmpdir) + ws = str(function_tmpdir) m.change_model_ws(ws) assert m.has_package("MNW2") assert m.has_package("MNWI") @@ -59,7 +59,7 @@ def test_load(tmpdir, example_data_path, mnw2_examples_path): ) -def test_mnw1_load_write(tmpdir, mnw1_path): +def test_mnw1_load_write(function_tmpdir, mnw1_path): m = Modflow.load( "mnw1.nam", model_ws=mnw1_path, @@ -67,7 +67,7 @@ def test_mnw1_load_write(tmpdir, mnw1_path): verbose=True, forgive=False, ) - ws = str(tmpdir) + ws = str(function_tmpdir) assert m.has_package("MNW1") assert m.mnw1.mxmnw == 120 for i in range(3): @@ -93,9 +93,9 @@ def test_mnw1_load_write(tmpdir, mnw1_path): assert np.array_equal(v, m2.mnw1.stress_period_data[k]) -def test_make_package(tmpdir): +def test_make_package(function_tmpdir): """t027 test make MNW2 Package""" - ws = str(tmpdir) + ws = str(function_tmpdir) m4 = Modflow("mnw2example", model_ws=ws) dis = ModflowDis(nrow=5, ncol=5, nlay=3, nper=3, top=10, botm=0, model=m4) @@ -294,7 +294,7 @@ def test_make_package(tmpdir): @requires_pkg("pandas") -def test_mnw2_create_file(tmpdir): +def test_mnw2_create_file(function_tmpdir): """ Test for issue #556, Mnw2 crashed if wells have multiple node lengths @@ -302,7 +302,7 @@ def test_mnw2_create_file(tmpdir): import pandas as pd mf = Modflow("test_mfmnw2", exe_name="mf2005") - ws = str(tmpdir) + ws = str(function_tmpdir) wellids = [1, 2] nlayers = [2, 4] stress_period_data = pd.DataFrame([[0, 1]], columns=["per", "qdes"]) @@ -367,11 +367,11 @@ def test_mnw2_create_file(tmpdir): @requires_pkg("netCDF4") @pytest.mark.slow -def test_export(tmpdir, mnw2_examples_path): +def test_export(function_tmpdir, mnw2_examples_path): """t027 test export of MNW2 Package to netcdf files""" import netCDF4 - ws = str(tmpdir) + ws = str(function_tmpdir) m = Modflow.load( "MNW2-Fig28.nam", model_ws=mnw2_examples_path, @@ -398,7 +398,7 @@ def test_export(tmpdir, mnw2_examples_path): # TODO need to add shapefile test -def test_blank_lines(tmpdir): +def test_blank_lines(function_tmpdir): mnw2str = """3 50 0 EB-33 -3 SKIN -1 0 0 0 @@ -428,7 +428,7 @@ def test_blank_lines(tmpdir): eb-36 -534.72 """ - ws = str(tmpdir) + ws = str(function_tmpdir) fpth = os.path.join(ws, "mymnw2.mnw2") f = open(fpth, "w") f.write(mnw2str) diff --git a/autotest/test_modflow.py b/autotest/test_modflow.py index 3f88a2fc3a..5975397d90 100644 --- a/autotest/test_modflow.py +++ b/autotest/test_modflow.py @@ -6,11 +6,8 @@ import numpy as np import pytest -from autotest.conftest import ( - excludes_platform, - get_example_data_path, - requires_exe, -) +from autotest.conftest import get_example_data_path +from modflow_devtools.markers import excludes_platform, requires_exe from flopy.discretization import StructuredGrid from flopy.mf6 import MFSimulation @@ -69,7 +66,7 @@ def test_modflow_load_when_nam_dne(): Modflow.load("nonexistent.nam", check=False) -def test_mbase_modelgrid(tmpdir): +def test_mbase_modelgrid(function_tmpdir): ml = Modflow( modelname="test", xll=500.0, rotation=12.5, start_datetime="1/1/2016" ) @@ -85,7 +82,7 @@ def test_mbase_modelgrid(tmpdir): assert ml.modelgrid.xoffset == 500 assert ml.modelgrid.yoffset == 0.0 assert ml.modelgrid.proj4 is None - ml.model_ws = tmpdir + ml.model_ws = function_tmpdir ml.write_input() ml1 = Modflow.load("test.nam", model_ws=ml.model_ws) @@ -94,7 +91,7 @@ def test_mbase_modelgrid(tmpdir): assert ml1.modelgrid.proj4 is None -def test_mt_modelgrid(tmpdir): +def test_mt_modelgrid(function_tmpdir): ml = Modflow( modelname="test", xll=500.0, @@ -108,7 +105,7 @@ def test_mt_modelgrid(tmpdir): assert ml.modelgrid.yoffset == 0.0 assert ml.modelgrid.epsg == 2193 assert ml.modelgrid.idomain is None - ml.model_ws = tmpdir + ml.model_ws = function_tmpdir mt = Mt3dms( modelname="test_mt", @@ -188,7 +185,7 @@ def test_mt_modelgrid(tmpdir): assert np.array_equal(swt.modelgrid.idomain, ml.modelgrid.idomain) -def test_free_format_flag(tmpdir): +def test_free_format_flag(function_tmpdir): Lx = 100.0 Ly = 100.0 nlay = 1 @@ -219,7 +216,7 @@ def test_free_format_flag(tmpdir): bas.ifrefm = True assert ms.free_format_input == bas.ifrefm - ms.model_ws = tmpdir + ms.model_ws = function_tmpdir ms.write_input() ms1 = Modflow.load(ms.namefile, model_ws=ms.model_ws) assert ms1.free_format_input == ms.free_format_input @@ -232,8 +229,8 @@ def test_free_format_flag(tmpdir): assert ms1.free_format_input == ms1.bas6.ifrefm -def test_sr(tmpdir): - ws = str(tmpdir) +def test_sr(function_tmpdir): + ws = str(function_tmpdir) m = Modflow( "test", model_ws=ws, @@ -311,7 +308,7 @@ def test_load_twri_grid(example_data_path): ), f"thickness shape {thick.shape} not equal to {shape}" -def test_mg(tmpdir): +def test_mg(function_tmpdir): from flopy.utils import geometry Lx = 100.0 @@ -383,7 +380,7 @@ def test_mg(tmpdir): assert ms.start_datetime == "1-1-2016" assert ms.dis.start_datetime == "1-1-2016" - ms.model_ws = tmpdir + ms.model_ws = function_tmpdir ms.write_input() ms1 = Modflow.load(ms.namefile, model_ws=ms.model_ws) @@ -419,11 +416,11 @@ def test_dynamic_xll_yll(): assert yll1 == yll, f"modelgrid.yoffset ({yll1}) is not equal to {yll}" -def test_namfile_readwrite(tmpdir, example_data_path): +def test_namfile_readwrite(function_tmpdir, example_data_path): nlay, nrow, ncol = 1, 30, 5 delr, delc = 250, 500 xll, yll = 272300, 5086000 - ws = str(tmpdir) + ws = str(function_tmpdir) m = Modflow(modelname="junk", model_ws=ws) dis = ModflowDis(m, nlay=nlay, nrow=nrow, ncol=ncol, delr=delr, delc=delc) m.modelgrid = StructuredGrid( @@ -466,12 +463,12 @@ def test_namfile_readwrite(tmpdir, example_data_path): assert ml.modelgrid.angrot == 15.0 -def test_read_usgs_model_reference(tmpdir, model_reference_path): +def test_read_usgs_model_reference(function_tmpdir, model_reference_path): nlay, nrow, ncol = 1, 30, 5 delr, delc = 250, 500 # xll, yll = 272300, 5086000 - mrf_path = tmpdir / model_reference_path.name + mrf_path = function_tmpdir / model_reference_path.name shutil.copy(model_reference_path, mrf_path) xul, yul = 0, 0 @@ -484,7 +481,7 @@ def test_read_usgs_model_reference(tmpdir, model_reference_path): else: continue - ws = str(tmpdir) + ws = str(function_tmpdir) m = Modflow(modelname="junk", model_ws=ws) # feet and days dis = ModflowDis( @@ -585,7 +582,7 @@ def test_mf2005_test_models_loadonly(example_data_path, namfile): @pytest.mark.slow -def test_write_irch(tmpdir, example_data_path): +def test_write_irch(function_tmpdir, example_data_path): mpath = example_data_path / "freyberg_multilayer_transient" nam_file = "freyberg.nam" m = Modflow.load( @@ -609,12 +606,12 @@ def test_write_irch(tmpdir, example_data_path): d = arr - aarr assert np.abs(d).sum() == 0 - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) m.write_input() mm = Modflow.load( nam_file, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), forgive=False, verbose=True, check=False, @@ -626,11 +623,11 @@ def test_write_irch(tmpdir, example_data_path): assert np.abs(d).sum() == 0 -def test_mflist_external(tmpdir): - ext = tmpdir / "ws" +def test_mflist_external(function_tmpdir): + ext = function_tmpdir / "ws" ml = Modflow( "mflist_test", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), external_path=ext.name, ) @@ -658,8 +655,8 @@ def test_mflist_external(tmpdir): # ml = Modflow( # "mflist_test", - # model_ws=str(tmpdir), - # external_path=str(tmpdir / "ref"), + # model_ws=str(function_tmpdir), + # external_path=str(function_tmpdir / "ref"), # ) # dis = ModflowDis(ml, 1, 10, 10, nper=3, perlen=1.0) # wel_data = { @@ -684,7 +681,7 @@ def test_mflist_external(tmpdir): @excludes_platform("windows", ci_only=True) -def test_single_mflist_entry_load(tmpdir, example_data_path): +def test_single_mflist_entry_load(function_tmpdir, example_data_path): m = Modflow.load( "freyberg.nam", model_ws=str(example_data_path / "freyberg"), @@ -695,12 +692,12 @@ def test_single_mflist_entry_load(tmpdir, example_data_path): spd = w.stress_period_data ModflowWel(m, stress_period_data={0: [0, 0, 0, 0.0]}) m.external_path = "external" - m.change_model_ws(str(tmpdir), reset_external=True) + m.change_model_ws(str(function_tmpdir), reset_external=True) m.write_input() mm = Modflow.load( "freyberg.nam", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), forgive=False, ) assert mm.wel.stress_period_data @@ -751,8 +748,8 @@ def test_checker_on_load(namfile): assert isinstance(m, Modflow), "Not a Modflow instance" -def test_bcs_check(tmpdir): - mf = Modflow(version="mf2005", model_ws=str(tmpdir)) +def test_bcs_check(function_tmpdir): + mf = Modflow(version="mf2005", model_ws=str(function_tmpdir)) # test check for isolated cells dis = ModflowDis(mf, nlay=2, nrow=3, ncol=3, top=100, botm=95) @@ -788,10 +785,10 @@ def test_bcs_check(tmpdir): assert np.array_equal(chk.summary_array["j"], np.array([0, 1, 1, 1, 1])) -def test_properties_check(tmpdir): +def test_properties_check(function_tmpdir): mf = Modflow( version="mf2005", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) dis = ModflowDis( mf, @@ -898,14 +895,14 @@ def test_oc_check(): assert "OC stress_period_data ignored" in chk.summary_array[0]["desc"] -def test_rchload(tmpdir): +def test_rchload(function_tmpdir): nlay = 2 nrow = 3 ncol = 4 nper = 2 # create model 1 - ws = str(tmpdir) + ws = str(function_tmpdir) m1 = Modflow("rchload1", model_ws=ws) dis1 = ModflowDis(m1, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) a = np.random.random((nrow, ncol)) @@ -941,8 +938,8 @@ def test_rchload(tmpdir): assert np.allclose(a1, a2) -def test_default_oc_stress_period_data(tmpdir): - m = Modflow(model_ws=str(tmpdir), verbose=True) +def test_default_oc_stress_period_data(function_tmpdir): + m = Modflow(model_ws=str(function_tmpdir), verbose=True) dis = ModflowDis(m, nper=10, perlen=10.0, nstp=5) bas = ModflowBas(m) lpf = ModflowLpf(m, ipakcb=100) @@ -960,8 +957,8 @@ def test_default_oc_stress_period_data(tmpdir): m.write_input() -def test_mfcbc(tmpdir): - m = Modflow(verbose=True, model_ws=str(tmpdir)) +def test_mfcbc(function_tmpdir): + m = Modflow(verbose=True, model_ws=str(function_tmpdir)) dis = ModflowDis(m) bas = ModflowBas(m) lpf = ModflowLpf(m, ipakcb=100) @@ -975,7 +972,7 @@ def test_mfcbc(tmpdir): nlay = 3 nrow = 3 ncol = 3 - ml = Modflow(modelname="t1", model_ws=str(tmpdir), verbose=True) + ml = Modflow(modelname="t1", model_ws=str(function_tmpdir), verbose=True) dis = ModflowDis( ml, nlay=nlay, nrow=nrow, ncol=ncol, top=0, botm=[-1.0, -2.0, -3.0] ) @@ -999,7 +996,7 @@ def test_mfcbc(tmpdir): ml.write_input() -def test_load_with_list_reader(tmpdir): +def test_load_with_list_reader(function_tmpdir): # Create an original model and then manually modify to use # advanced list reader capabilities nlay = 1 @@ -1031,7 +1028,7 @@ def test_load_with_list_reader(tmpdir): m = Modflow( modelname="original", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), exe_name="mf2005", ) dis = ModflowDis(m, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) @@ -1047,7 +1044,7 @@ def test_load_with_list_reader(tmpdir): m.write_input() # rewrite ghb - fname = os.path.join(str(tmpdir), "original.ghb") + fname = os.path.join(str(function_tmpdir), "original.ghb") with open(fname, "w") as f: f.write(f"{ghbra.shape[0]} 0\n") for kper in range(nper): @@ -1056,14 +1053,14 @@ def test_load_with_list_reader(tmpdir): # write ghb list sfacghb = 5 - fname = os.path.join(str(tmpdir), "original.ghb.dat") + fname = os.path.join(str(function_tmpdir), "original.ghb.dat") with open(fname, "w") as f: f.write(f"sfac {sfacghb}\n") for k, i, j, stage, cond in ghbra: f.write(f"{k + 1} {i + 1} {j + 1} {stage} {cond}\n") # rewrite drn - fname = os.path.join(str(tmpdir), "original.drn") + fname = os.path.join(str(function_tmpdir), "original.drn") with open(fname, "w") as f: f.write(f"{drnra.shape[0]} 0\n") for kper in range(nper): @@ -1072,7 +1069,7 @@ def test_load_with_list_reader(tmpdir): # write drn list sfacdrn = 1.5 - fname = os.path.join(str(tmpdir), "original.drn.dat") + fname = os.path.join(str(function_tmpdir), "original.drn.dat") with open(fname, "w") as f: for kper in range(nper): f.write(f"sfac {sfacdrn}\n") @@ -1080,7 +1077,7 @@ def test_load_with_list_reader(tmpdir): f.write(f"{k + 1} {i + 1} {j + 1} {stage} {cond}\n") # rewrite wel - fname = os.path.join(str(tmpdir), "original.wel") + fname = os.path.join(str(function_tmpdir), "original.wel") with open(fname, "w") as f: f.write(f"{drnra.shape[0]} 0\n") for kper in range(nper): @@ -1100,7 +1097,7 @@ def test_load_with_list_reader(tmpdir): welra = np.recarray(2, dtype=weldt) welra[0] = (1, 2, 2, -5.0) welra[1] = (1, nrow - 2, ncol - 2, -10.0) - fname = os.path.join(str(tmpdir), "original.wel.bin") + fname = os.path.join(str(function_tmpdir), "original.wel.bin") with open(fname, "wb") as f: welra.tofile(f) welra.tofile(f) @@ -1113,7 +1110,7 @@ def test_load_with_list_reader(tmpdir): # the m2 model will load all of these external files, possibly using sfac # and just create regular list input files for wel, drn, and ghb fname = "original.nam" - m2 = Modflow.load(fname, model_ws=str(tmpdir), verbose=False) + m2 = Modflow.load(fname, model_ws=str(function_tmpdir), verbose=False) m2.name = "new" m2.write_input() @@ -1178,23 +1175,27 @@ def get_basic_modflow_model(ws, name): @pytest.mark.slow -def test_model_init_time(tmpdir, benchmark): +def test_model_init_time(function_tmpdir, benchmark): name = inspect.getframeinfo(inspect.currentframe()).function - benchmark(lambda: get_basic_modflow_model(ws=str(tmpdir), name=name)) + benchmark( + lambda: get_basic_modflow_model(ws=str(function_tmpdir), name=name) + ) @pytest.mark.slow -def test_model_write_time(tmpdir, benchmark): +def test_model_write_time(function_tmpdir, benchmark): name = inspect.getframeinfo(inspect.currentframe()).function - model = get_basic_modflow_model(ws=str(tmpdir), name=name) + model = get_basic_modflow_model(ws=str(function_tmpdir), name=name) benchmark(lambda: model.write_input()) @pytest.mark.slow -def test_model_load_time(tmpdir, benchmark): +def test_model_load_time(function_tmpdir, benchmark): name = inspect.getframeinfo(inspect.currentframe()).function - model = get_basic_modflow_model(ws=str(tmpdir), name=name) + model = get_basic_modflow_model(ws=str(function_tmpdir), name=name) model.write_input() benchmark( - lambda: Modflow.load(f"{name}.nam", model_ws=str(tmpdir), check=False) + lambda: Modflow.load( + f"{name}.nam", model_ws=str(function_tmpdir), check=False + ) ) diff --git a/autotest/test_modpathfile.py b/autotest/test_modpathfile.py index 288cd11456..06dd3dfad2 100644 --- a/autotest/test_modpathfile.py +++ b/autotest/test_modpathfile.py @@ -5,7 +5,7 @@ import numpy as np import pytest -from autotest.conftest import requires_exe +from modflow_devtools.markers import requires_exe from flopy.mf6 import ( MFSimulation, @@ -236,9 +236,11 @@ def mp7_large(module_tmpdir): @requires_exe("mf6") -def test_pathline_file_sorts_in_ctor(tmpdir, module_tmpdir, mp7_small): +def test_pathline_file_sorts_in_ctor( + function_tmpdir, module_tmpdir, mp7_small +): sim, forward_model_name, backward_model_name, nodew, nodesr = mp7_small - ws = tmpdir / "ws" + ws = function_tmpdir / "ws" # copytree(sim.simulation_data.mfpath.get_sim_path(), ws) copytree(str(module_tmpdir / "mp7_small"), ws) @@ -258,10 +260,10 @@ def test_pathline_file_sorts_in_ctor(tmpdir, module_tmpdir, mp7_small): @pytest.mark.parametrize("direction", ["forward", "backward"]) @pytest.mark.parametrize("locations", ["well", "river"]) def test_get_destination_pathline_data( - tmpdir, mp7_large, direction, locations, benchmark + function_tmpdir, mp7_large, direction, locations, benchmark ): sim, forward_model_name, backward_model_name, nodew, nodesr = mp7_large - ws = tmpdir / "ws" + ws = function_tmpdir / "ws" copytree(sim.simulation_data.mfpath.get_sim_path(), ws) @@ -285,10 +287,10 @@ def test_get_destination_pathline_data( @pytest.mark.parametrize("direction", ["forward", "backward"]) @pytest.mark.parametrize("locations", ["well", "river"]) def test_get_destination_endpoint_data( - tmpdir, mp7_large, direction, locations, benchmark + function_tmpdir, mp7_large, direction, locations, benchmark ): sim, forward_model_name, backward_model_name, nodew, nodesr = mp7_large - ws = tmpdir / "ws" + ws = function_tmpdir / "ws" copytree(sim.simulation_data.mfpath.get_sim_path(), ws) diff --git a/autotest/test_mp5.py b/autotest/test_mp5.py index b17bec40d5..6e93c20aaf 100644 --- a/autotest/test_mp5.py +++ b/autotest/test_mp5.py @@ -1,9 +1,9 @@ import os import numpy as np -from autotest.conftest import requires_pkg from autotest.test_mp6 import eval_timeseries from matplotlib import pyplot as plt +from modflow_devtools.markers import requires_pkg from flopy.modflow import Modflow from flopy.plot import PlotMapView @@ -11,7 +11,7 @@ @requires_pkg("pandas") -def test_mp5_load(tmpdir, example_data_path): +def test_mp5_load(function_tmpdir, example_data_path): # load the base freyberg model freyberg_ws = example_data_path / "freyberg" # load the modflow files for model map @@ -63,7 +63,7 @@ def test_mp5_load(tmpdir, example_data_path): mm.plot_grid(lw=0.5) mm.plot_ibound() - fpth = os.path.join(str(tmpdir), "mp5.pathline.png") + fpth = os.path.join(str(function_tmpdir), "mp5.pathline.png") plt.savefig(fpth, dpi=300) plt.close() diff --git a/autotest/test_mp6.py b/autotest/test_mp6.py index 2e4acdbd9c..4b470e42cc 100644 --- a/autotest/test_mp6.py +++ b/autotest/test_mp6.py @@ -4,8 +4,9 @@ import matplotlib.pyplot as plt import numpy as np import pytest -from autotest.conftest import get_example_data_path, requires_exe, requires_pkg +from autotest.conftest import get_example_data_path from autotest.test_mp6_cases import Mp6Cases1, Mp6Cases2 +from modflow_devtools.markers import requires_exe, requires_pkg from pytest_cases import parametrize_with_cases import flopy @@ -41,17 +42,17 @@ def copy_modpath_files(source, model_ws, baseName): shutil.copy(src, dst) -def test_mpsim(tmpdir, mp6_test_path): - copy_modpath_files(str(mp6_test_path), str(tmpdir), "EXAMPLE.") +def test_mpsim(function_tmpdir, mp6_test_path): + copy_modpath_files(str(mp6_test_path), str(function_tmpdir), "EXAMPLE.") - m = Modflow.load("EXAMPLE.nam", model_ws=str(tmpdir)) + m = Modflow.load("EXAMPLE.nam", model_ws=str(function_tmpdir)) m.get_package_list() mp = Modpath6( modelname="ex6", exe_name="mp6", modflowmodel=m, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), dis_file=f"{m.name}.dis", head_file=f"{m.name}.hed", budget_file=f"{m.name}.bud", @@ -121,18 +122,18 @@ def test_mpsim(tmpdir, mp6_test_path): stldata[1]["yloc0"] = 0.2 stl.data = stldata mp.write_input() - stllines = open(os.path.join(str(tmpdir), "ex6.loc")).readlines() + stllines = open(os.path.join(str(function_tmpdir), "ex6.loc")).readlines() assert stllines[3].strip() == "group1" assert int(stllines[4].strip()) == 2 assert stllines[6].strip().split()[-1] == "p2" @requires_pkg("pandas", "shapefile") -def test_get_destination_data(tmpdir, mp6_test_path): - copy_modpath_files(str(mp6_test_path), str(tmpdir), "EXAMPLE.") - copy_modpath_files(str(mp6_test_path), str(tmpdir), "EXAMPLE-3.") +def test_get_destination_data(function_tmpdir, mp6_test_path): + copy_modpath_files(str(mp6_test_path), str(function_tmpdir), "EXAMPLE.") + copy_modpath_files(str(mp6_test_path), str(function_tmpdir), "EXAMPLE-3.") - m = Modflow.load("EXAMPLE.nam", model_ws=str(tmpdir)) + m = Modflow.load("EXAMPLE.nam", model_ws=str(function_tmpdir)) mg1 = m.modelgrid mg1.set_coord_info( @@ -149,10 +150,10 @@ def test_get_destination_data(tmpdir, mp6_test_path): ) # test deprecation - m.dis.export(str(tmpdir / "dis.shp")) + m.dis.export(str(function_tmpdir / "dis.shp")) - pthld = PathlineFile(str(tmpdir / "EXAMPLE-3.pathline")) - epd = EndpointFile(str(tmpdir / "EXAMPLE-3.endpoint")) + pthld = PathlineFile(str(function_tmpdir / "EXAMPLE-3.pathline")) + epd = EndpointFile(str(function_tmpdir / "EXAMPLE-3.endpoint")) well_epd = epd.get_destination_endpoint_data(dest_cells=[(4, 12, 12)]) well_pthld = pthld.get_destination_pathline_data( @@ -177,12 +178,12 @@ def test_get_destination_data(tmpdir, mp6_test_path): epd.write_shapefile( well_epd, direction="starting", - shpname=str(tmpdir / "starting_locs.shp"), + shpname=str(function_tmpdir / "starting_locs.shp"), mg=m.modelgrid, ) # test writing shapefile of pathlines - fpth = str(tmpdir / "pathlines_1per.shp") + fpth = str(function_tmpdir / "pathlines_1per.shp") pthld.write_shapefile( well_pthld, one_per_particle=True, @@ -190,7 +191,7 @@ def test_get_destination_data(tmpdir, mp6_test_path): mg=m.modelgrid, shpname=fpth, ) - fpth = str(tmpdir / "pathlines_1per_end.shp") + fpth = str(function_tmpdir / "pathlines_1per_end.shp") pthld.write_shapefile( well_pthld, one_per_particle=True, @@ -199,7 +200,7 @@ def test_get_destination_data(tmpdir, mp6_test_path): shpname=fpth, ) # test writing shapefile of pathlines - fpth = str(tmpdir / "pathlines_1per2.shp") + fpth = str(function_tmpdir / "pathlines_1per2.shp") pthld.write_shapefile( well_pthld, one_per_particle=True, @@ -208,7 +209,7 @@ def test_get_destination_data(tmpdir, mp6_test_path): shpname=fpth, ) # test writing shapefile of pathlines - fpth = str(tmpdir / "pathlines_1per2_ll.shp") + fpth = str(function_tmpdir / "pathlines_1per2_ll.shp") pthld.write_shapefile( well_pthld, one_per_particle=True, @@ -216,13 +217,13 @@ def test_get_destination_data(tmpdir, mp6_test_path): mg=mg, shpname=fpth, ) - fpth = str(tmpdir / "pathlines.shp") + fpth = str(function_tmpdir / "pathlines.shp") pthld.write_shapefile( well_pthld, one_per_particle=False, mg=m.modelgrid, shpname=fpth ) # test that endpoints were rotated and written correctly - ra = shp2recarray(str(tmpdir / "starting_locs.shp")) + ra = shp2recarray(str(function_tmpdir / "starting_locs.shp")) p3 = ra.geometry[ra.particleid == 4][0] xorig, yorig = m.modelgrid.get_coords(well_epd.x0[0], well_epd.y0[0]) assert p3.x - xorig + p3.y - yorig < 1e-4 @@ -232,16 +233,16 @@ def test_get_destination_data(tmpdir, mp6_test_path): ) # this also checks for 1-based # test that particle attribute information is consistent with pathline file - ra = shp2recarray(str(tmpdir / "pathlines.shp")) + ra = shp2recarray(str(function_tmpdir / "pathlines.shp")) inds = (ra.particleid == 8) & (ra.i == 12) & (ra.j == 12) assert ra.time[inds][0] - 20181.7 < 0.1 assert ra.xloc[inds][0] - 0.933 < 0.01 # test that k, i, j are correct for single geometry pathlines, forwards # and backwards - ra = shp2recarray(str(tmpdir / "pathlines_1per.shp")) + ra = shp2recarray(str(function_tmpdir / "pathlines_1per.shp")) assert ra.i[0] == 4, ra.j[0] == 5 - ra = shp2recarray(str(tmpdir / "pathlines_1per_end.shp")) + ra = shp2recarray(str(function_tmpdir / "pathlines_1per_end.shp")) assert ra.i[0] == 13, ra.j[0] == 13 # test use of arbitrary spatial reference and offset @@ -252,7 +253,7 @@ def test_get_destination_data(tmpdir, mp6_test_path): epsg=mg.epsg, proj4=mg.proj4, ) - ra = shp2recarray(str(tmpdir / "pathlines_1per2.shp")) + ra = shp2recarray(str(function_tmpdir / "pathlines_1per2.shp")) p3_2 = ra.geometry[ra.particleid == 4][0] test1 = mg1.xcellcenters[3, 4] test2 = mg1.ycellcenters[3, 4] @@ -267,7 +268,7 @@ def test_get_destination_data(tmpdir, mp6_test_path): ) # arbitrary spatial reference with ll specified instead of ul - ra = shp2recarray(str(tmpdir / "pathlines_1per2_ll.shp")) + ra = shp2recarray(str(function_tmpdir / "pathlines_1per2_ll.shp")) p3_2 = ra.geometry[ra.particleid == 4][0] mg.set_coord_info(xoff=mg.xoffset, yoff=mg.yoffset, angrot=30.0) assert ( @@ -283,7 +284,7 @@ def test_get_destination_data(tmpdir, mp6_test_path): xul = 3628793 yul = 21940389 - m = Modflow.load("EXAMPLE.nam", model_ws=str(tmpdir)) + m = Modflow.load("EXAMPLE.nam", model_ws=str(function_tmpdir)) mg4 = m.modelgrid mg4.set_coord_info( @@ -294,18 +295,18 @@ def test_get_destination_data(tmpdir, mp6_test_path): proj4=mg4.proj4, ) - fpth = str(tmpdir / "dis2.shp") + fpth = str(function_tmpdir / "dis2.shp") m.dis.export(fpth) - pthobj = PathlineFile(str(tmpdir / "EXAMPLE-3.pathline")) - fpth = str(tmpdir / "pathlines_1per3.shp") + pthobj = PathlineFile(str(function_tmpdir / "EXAMPLE-3.pathline")) + fpth = str(function_tmpdir / "pathlines_1per3.shp") pthobj.write_shapefile(shpname=fpth, direction="ending", mg=mg4) @requires_pkg("pandas") -def test_loadtxt(tmpdir, mp6_test_path): - copy_modpath_files(str(mp6_test_path), str(tmpdir), "EXAMPLE-3.") +def test_loadtxt(function_tmpdir, mp6_test_path): + copy_modpath_files(str(mp6_test_path), str(function_tmpdir), "EXAMPLE-3.") - pthfile = str(tmpdir / "EXAMPLE-3.pathline") + pthfile = str(function_tmpdir / "EXAMPLE-3.pathline") pthld = PathlineFile(pthfile) ra = loadtxt(pthfile, delimiter=" ", skiprows=3, dtype=pthld.dtype) ra2 = loadtxt( @@ -319,7 +320,7 @@ def test_loadtxt(tmpdir, mp6_test_path): @requires_exe("mf2005") @requires_pkg("pandas") -def test_modpath(tmpdir, example_data_path): +def test_modpath(function_tmpdir, example_data_path): pth = example_data_path / "freyberg" mfnam = "freyberg.nam" @@ -332,7 +333,7 @@ def test_modpath(tmpdir, example_data_path): ) assert m.load_fail is False - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) m.write_input() success, buff = m.run_model(silent=False) @@ -344,7 +345,7 @@ def test_modpath(tmpdir, example_data_path): mpnam, exe_name="mp6", modflowmodel=m, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) mpbas = Modpath6Bas( mp, @@ -372,7 +373,7 @@ def test_modpath(tmpdir, example_data_path): mpnam, exe_name="mp6", modflowmodel=m, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) mpbas = Modpath6Bas( mpp, @@ -397,8 +398,8 @@ def test_modpath(tmpdir, example_data_path): # load modpath output files if success: - endfile = os.path.join(str(tmpdir), mp.sim.endpoint_file) - pthfile = os.path.join(str(tmpdir), mpp.sim.pathline_file) + endfile = os.path.join(str(function_tmpdir), mp.sim.endpoint_file) + pthfile = os.path.join(str(function_tmpdir), mpp.sim.pathline_file) # load the endpoint data try: @@ -422,14 +423,14 @@ def test_modpath(tmpdir, example_data_path): mfnam = "freyberg.nam" m = Modflow.load( mfnam, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), verbose=True, forgive=False, exe_name="mf2005", ) # load modpath output files - pthfile = os.path.join(str(tmpdir), "freybergmpp.mppth") + pthfile = os.path.join(str(function_tmpdir), "freybergmpp.mppth") # load the pathline data pthobj = PathlineFile(pthfile) @@ -447,7 +448,7 @@ def test_modpath(tmpdir, example_data_path): # plot the grid and ibound array mm.plot_grid() mm.plot_ibound() - fpth = os.path.join(str(tmpdir), "pathline.png") + fpth = os.path.join(str(function_tmpdir), "pathline.png") plt.savefig(fpth) plt.close() @@ -458,7 +459,7 @@ def test_modpath(tmpdir, example_data_path): mm.plot_grid() mm.plot_ibound() - fpth = os.path.join(str(tmpdir), "pathline2.png") + fpth = os.path.join(str(function_tmpdir), "pathline2.png") plt.savefig(fpth) plt.close() @@ -469,7 +470,7 @@ def test_modpath(tmpdir, example_data_path): mm.plot_grid() mm.plot_ibound() - fpth = os.path.join(str(tmpdir), "pathline3.png") + fpth = os.path.join(str(function_tmpdir), "pathline3.png") plt.savefig(fpth) plt.close() diff --git a/autotest/test_mp6_cases.py b/autotest/test_mp6_cases.py index 4cebd68724..907a94fda3 100644 --- a/autotest/test_mp6_cases.py +++ b/autotest/test_mp6_cases.py @@ -31,13 +31,13 @@ class Mp6Cases1: botm = np.concatenate((bt1, bt2), axis=0) ipakcb = 740 - def case_1(self, tmpdir): + def case_1(self, function_tmpdir): m = flopy.modflow.Modflow( modelname="mf1", namefile_ext="nam", version="mf2005", exe_name="mf2005", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) # dis @@ -111,13 +111,13 @@ def case_1(self, tmpdir): assert success return m - def case_2(self, tmpdir): + def case_2(self, function_tmpdir): m = flopy.modflow.Modflow( modelname="mf2", namefile_ext="nam", version="mf2005", exe_name="mf2005", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) # dis @@ -219,13 +219,13 @@ class Mp6Cases2: botm = np.concatenate((bt1, bt2), axis=0) ipakcb = 740 - def case_1(self, tmpdir): + def case_1(self, function_tmpdir): m = flopy.modflow.Modflow( modelname=f"mf1", namefile_ext="nam", version="mf2005", exe_name="mf2005", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) # dis diff --git a/autotest/test_mp7.py b/autotest/test_mp7.py index e9614fc19c..c0158620df 100644 --- a/autotest/test_mp7.py +++ b/autotest/test_mp7.py @@ -3,8 +3,8 @@ import matplotlib.pyplot as plt import numpy as np import pytest -from autotest.conftest import requires_exe, requires_pkg from autotest.test_mp7_cases import Mp7Cases +from modflow_devtools.markers import requires_exe, requires_pkg from pytest_cases import parametrize_with_cases from flopy.mf6 import ( @@ -42,7 +42,7 @@ @pytest.fixture -def ex01b_mf6_model(tmpdir): +def ex01b_mf6_model(function_tmpdir): """ MODPATH 7 example 1 for MODFLOW 6 """ @@ -68,7 +68,7 @@ def ex01b_mf6_model(tmpdir): sim_name=ex01b_mf6_model_name, exe_name="mf6", version="mf6", - sim_ws=str(tmpdir), + sim_ws=str(function_tmpdir), ) # Create the Flopy temporal discretization object @@ -134,7 +134,7 @@ def ex01b_mf6_model(tmpdir): # Write the datasets sim.write_simulation() - return sim, tmpdir + return sim, function_tmpdir def build_modpath(ws, mpn, particlegroups, grid): @@ -238,7 +238,7 @@ def endpoint_compare(fpth0, epf): @requires_exe("mf6", "mp7") def test_default_modpath(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model success, buff = sim.run_simulation() assert success, "mf6 model did not run" @@ -246,14 +246,17 @@ def test_default_modpath(ex01b_mf6_model): mpnam = f"{ex01b_mf6_model_name}_mp_default" pg = ParticleGroup(particlegroupname="DEFAULT") build_modpath( - str(tmpdir), mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid + str(function_tmpdir), + mpnam, + pg, + sim.get_model(ex01b_mf6_model_name).modelgrid, ) @requires_exe("mf6", "mp7") @requires_pkg("pandas") def test_faceparticles_is1(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model local = np.array( [ @@ -292,16 +295,21 @@ def test_faceparticles_is1(ex01b_mf6_model): particlegroupname="T1NODEPG", particledata=p, filename=fpth ) build_modpath( - str(tmpdir), mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid + str(function_tmpdir), + mpnam, + pg, + sim.get_model(ex01b_mf6_model_name).modelgrid, ) # set base file name - fpth0 = os.path.join(str(tmpdir), "ex01b_mf6_mp_face_t1node.mpend") + fpth0 = os.path.join( + str(function_tmpdir), "ex01b_mf6_mp_face_t1node.mpend" + ) # get list of node endpath files epf = [ - os.path.join(str(tmpdir), name) - for name in os.listdir(str(tmpdir)) + os.path.join(str(function_tmpdir), name) + for name in os.listdir(str(function_tmpdir)) if ".mpend" in name and "_face_" in name and "_t2a" not in name ] epf.remove(fpth0) @@ -311,7 +319,7 @@ def test_faceparticles_is1(ex01b_mf6_model): @requires_exe("mf6", "mp7") def test_facenode_is3(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model grid = sim.get_model(ex01b_mf6_model_name).modelgrid success, buff = sim.run_simulation() assert success, "mf6 model did not run" @@ -343,13 +351,16 @@ def test_facenode_is3(ex01b_mf6_model): particlegroupname="T3NODEPG", particledata=p, filename=fpth ) build_modpath( - str(tmpdir), mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid + str(function_tmpdir), + mpnam, + pg, + sim.get_model(ex01b_mf6_model_name).modelgrid, ) @requires_exe("mf6", "mp7") def test_facenode_is3a(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model grid = sim.get_model(ex01b_mf6_model_name).modelgrid success, buff = sim.run_simulation() assert success, "mf6 model did not run" @@ -386,13 +397,16 @@ def test_facenode_is3a(ex01b_mf6_model): particlegroupname="T3ANODEPG", particledata=p, filename=fpth ) build_modpath( - str(tmpdir), mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid + str(function_tmpdir), + mpnam, + pg, + sim.get_model(ex01b_mf6_model_name).modelgrid, ) @requires_exe("mf6", "mp7") def test_facenode_is2a(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model grid = sim.get_model(ex01b_mf6_model_name).modelgrid success, buff = sim.run_simulation() assert success, "mf6 model did not run" @@ -421,14 +435,17 @@ def test_facenode_is2a(ex01b_mf6_model): particlegroupname="T2ANODEPG", particledata=p, filename=fpth ) build_modpath( - str(tmpdir), mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid + str(function_tmpdir), + mpnam, + pg, + sim.get_model(ex01b_mf6_model_name).modelgrid, ) @requires_exe("mf6", "mp7") @requires_pkg("pandas") def test_cellparticles_is1(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model grid = sim.get_model(ex01b_mf6_model_name).modelgrid success, buff = sim.run_simulation() assert success, "mf6 model did not run" @@ -448,16 +465,21 @@ def test_cellparticles_is1(ex01b_mf6_model): particlegroupname="T1NODEPG", particledata=p, filename=fpth ) build_modpath( - str(tmpdir), mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid + str(function_tmpdir), + mpnam, + pg, + sim.get_model(ex01b_mf6_model_name).modelgrid, ) # set base file name - fpth0 = os.path.join(str(tmpdir), "ex01b_mf6_mp_cell_t1node.mpend") + fpth0 = os.path.join( + str(function_tmpdir), "ex01b_mf6_mp_cell_t1node.mpend" + ) # get list of node endpath files epf = [ - os.path.join(str(tmpdir), name) - for name in os.listdir(str(tmpdir)) + os.path.join(str(function_tmpdir), name) + for name in os.listdir(str(function_tmpdir)) if ".mpend" in name and "_cell_" in name and "_t2a" not in name ] epf.remove(fpth0) @@ -467,7 +489,7 @@ def test_cellparticles_is1(ex01b_mf6_model): @requires_exe("mf6", "mp7") def test_cellparticleskij_is1(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model grid = sim.get_model(ex01b_mf6_model_name).modelgrid success, buff = sim.run_simulation() assert success, "mf6 model did not run" @@ -486,13 +508,16 @@ def test_cellparticleskij_is1(ex01b_mf6_model): particlegroupname="T1KIJPG", particledata=p, filename=fpth ) build_modpath( - str(tmpdir), mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid + str(function_tmpdir), + mpnam, + pg, + sim.get_model(ex01b_mf6_model_name).modelgrid, ) @requires_exe("mf6", "mp7") def test_cellnode_is3(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model grid = sim.get_model(ex01b_mf6_model_name).modelgrid success, buff = sim.run_simulation() assert success, "mf6 model did not run" @@ -516,13 +541,16 @@ def test_cellnode_is3(ex01b_mf6_model): particlegroupname="T3CELLPG", particledata=p, filename=fpth ) build_modpath( - str(tmpdir), mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid + str(function_tmpdir), + mpnam, + pg, + sim.get_model(ex01b_mf6_model_name).modelgrid, ) @requires_exe("mf6", "mp7") def test_cellnode_is3a(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model grid = sim.get_model(ex01b_mf6_model_name).modelgrid success, buff = sim.run_simulation() assert success, "mf6 model did not run" @@ -560,13 +588,16 @@ def test_cellnode_is3a(ex01b_mf6_model): particlegroupname="T3ACELLPG", particledata=p, filename=fpth ) build_modpath( - str(tmpdir), mpnam, pg, sim.get_model(ex01b_mf6_model_name).modelgrid + str(function_tmpdir), + mpnam, + pg, + sim.get_model(ex01b_mf6_model_name).modelgrid, ) @requires_exe("mf6", "mp7") def test_cellnode_is2a(ex01b_mf6_model): - sim, tmpdir = ex01b_mf6_model + sim, function_tmpdir = ex01b_mf6_model grid = sim.get_model(ex01b_mf6_model_name).modelgrid success, buff = sim.run_simulation() @@ -590,14 +621,14 @@ def test_cellnode_is2a(ex01b_mf6_model): particlegroupname="T2ACELLPG", particledata=p, filename=fpth ) - build_modpath(str(tmpdir), mpnam, pg, grid) + build_modpath(str(function_tmpdir), mpnam, pg, grid) ex01_mf6_model_name = "ex01_mf6" @pytest.fixture -def ex01_mf6_model(tmpdir): +def ex01_mf6_model(function_tmpdir): """ MODPATH 7 example 1 for MODFLOW 6 """ @@ -607,7 +638,7 @@ def ex01_mf6_model(tmpdir): sim_name=ex01_mf6_model_name, exe_name="mf6", version="mf6", - sim_ws=str(tmpdir), + sim_ws=str(function_tmpdir), ) # model data @@ -690,13 +721,13 @@ def ex01_mf6_model(tmpdir): # Write the datasets sim.write_simulation() - return sim, tmpdir + return sim, function_tmpdir @pytest.mark.slow @requires_exe("mf6", "mp7") def test_forward(ex01_mf6_model): - sim, tmpdir = ex01_mf6_model + sim, function_tmpdir = ex01_mf6_model # Run the simulation success, buff = sim.run_simulation() assert success, "mf6 model did not run" @@ -704,7 +735,7 @@ def test_forward(ex01_mf6_model): mpnam = f"{ex01_mf6_model_name}_mp_forward" # load the MODFLOW 6 model - sim = MFSimulation.load("mf6mod", "mf6", "mf6", str(tmpdir)) + sim = MFSimulation.load("mf6mod", "mf6", "mf6", str(function_tmpdir)) gwf = sim.get_model(ex01_mf6_model_name) mp = Modpath7.create_mp7( @@ -712,7 +743,7 @@ def test_forward(ex01_mf6_model): trackdir="forward", flowmodel=gwf, exe_name="mp7", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), rowcelldivisions=1, columncelldivisions=1, layercelldivisions=1, @@ -729,14 +760,14 @@ def test_forward(ex01_mf6_model): @pytest.mark.slow @requires_exe("mf6", "mp7") def test_backward(ex01_mf6_model): - sim, tmpdir = ex01_mf6_model + sim, function_tmpdir = ex01_mf6_model success, buff = sim.run_simulation() assert success, "mf6 model did not run" mpnam = f"{ex01_mf6_model_name}_mp_backward" # load the MODFLOW 6 model - sim = MFSimulation.load("mf6mod", "mf6", "mf6", str(tmpdir)) + sim = MFSimulation.load("mf6mod", "mf6", "mf6", str(function_tmpdir)) gwf = sim.get_model(ex01_mf6_model_name) mp = Modpath7.create_mp7( @@ -744,7 +775,7 @@ def test_backward(ex01_mf6_model): trackdir="backward", flowmodel=gwf, exe_name="mp7", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), rowcelldivisions=1, columncelldivisions=1, layercelldivisions=1, @@ -759,9 +790,9 @@ def test_backward(ex01_mf6_model): @requires_exe("mf2005", "mf6", "mp7") -def test_pathline_output(tmpdir): - case_mf2005 = Mp7Cases.mf2005(tmpdir) - case_mf6 = Mp7Cases.mf6(tmpdir) +def test_pathline_output(function_tmpdir): + case_mf2005 = Mp7Cases.mf2005(function_tmpdir) + case_mf6 = Mp7Cases.mf6(function_tmpdir) success, buff = case_mf2005.run_model() assert success, f"modpath model ({case_mf2005.name}) did not run" @@ -790,9 +821,9 @@ def test_pathline_output(tmpdir): @requires_pkg("pandas") @requires_exe("mf2005", "mf6", "mp7") -def test_endpoint_output(tmpdir): - case_mf2005 = Mp7Cases.mf2005(tmpdir) - case_mf6 = Mp7Cases.mf6(tmpdir) +def test_endpoint_output(function_tmpdir): + case_mf2005 = Mp7Cases.mf2005(function_tmpdir) + case_mf6 = Mp7Cases.mf6(function_tmpdir) success, buff = case_mf2005.run_model() assert success, f"modpath model ({case_mf2005.name}) did not run" @@ -842,8 +873,8 @@ def test_endpoint_output(tmpdir): @requires_exe("mf6") -def test_pathline_plotting(tmpdir): - ml = Mp7Cases.mf6(tmpdir) +def test_pathline_plotting(function_tmpdir): + ml = Mp7Cases.mf6(function_tmpdir) success, buff = ml.run_model() assert success, f"modpath model ({ml.name}) did not run" diff --git a/autotest/test_mp7_cases.py b/autotest/test_mp7_cases.py index 8d7ca557dd..42ef384b50 100644 --- a/autotest/test_mp7_cases.py +++ b/autotest/test_mp7_cases.py @@ -76,12 +76,12 @@ class Mp7Cases: particlegroups = [pg0, pg1] @staticmethod - def mf6(tmpdir): + def mf6(function_tmpdir): """ MODPATH 7 example 1 for MODFLOW 6 """ - ws = join(str(tmpdir), "mf6") + ws = join(str(function_tmpdir), "mf6") nm = "ex01_mf6" # Create the Flopy simulation object @@ -213,12 +213,12 @@ def mf6(tmpdir): return mp @staticmethod - def mf2005(tmpdir): + def mf2005(function_tmpdir): """ MODPATH 7 example 1 for MODFLOW-2005 """ - ws = join(str(tmpdir), "mf2005") + ws = join(str(function_tmpdir), "mf2005") nm = "ex01_mf2005" iu_cbc = 130 m = Modflow(nm, model_ws=ws, exe_name="mf2005") @@ -307,8 +307,8 @@ def mf2005(tmpdir): mp.write_input() return mp - def case_mf6(self, tmpdir): - return Mp7Cases.mf6(tmpdir) + def case_mf6(self, function_tmpdir): + return Mp7Cases.mf6(function_tmpdir) - def case_mf2005(self, tmpdir): - return Mp7Cases.mf2005(tmpdir) + def case_mf2005(self, function_tmpdir): + return Mp7Cases.mf2005(function_tmpdir) diff --git a/autotest/test_mt3d.py b/autotest/test_mt3d.py index fd0ad1a627..b3991299f4 100644 --- a/autotest/test_mt3d.py +++ b/autotest/test_mt3d.py @@ -3,8 +3,8 @@ import numpy as np import pytest -from autotest.conftest import excludes_platform, requires_exe from flaky import flaky +from modflow_devtools.markers import excludes_platform, requires_exe from flopy.modflow import ( Modflow, @@ -60,11 +60,11 @@ def mfnwtmt3d_model_path(mt3d_test_model_path): @requires_exe("mf2005", "mt3dms") -def test_mf2005_p07(tmpdir, mf2005mt3d_model_path): +def test_mf2005_p07(function_tmpdir, mf2005mt3d_model_path): pth = str(mf2005mt3d_model_path / "P07") namfile = "p7mf2005.nam" mf = Modflow.load(namfile, model_ws=pth, verbose=True, exe_name="mf2005") - cpth = str(tmpdir / "P07") + cpth = str(function_tmpdir / "P07") mf.model_ws = cpth mf.write_input() @@ -91,12 +91,12 @@ def test_mf2005_p07(tmpdir, mf2005mt3d_model_path): @requires_exe("mf2000", "mt3dms") -def test_mf2000_p07(tmpdir, mf2kmt3d_model_path): +def test_mf2000_p07(function_tmpdir, mf2kmt3d_model_path): pth = str(mf2kmt3d_model_path / "P07") namfile = "p7mf2k.nam" mf = Modflow.load(namfile, model_ws=pth, verbose=True, exe_name="mf2000") - cpth = str(tmpdir / "P07_2K") + cpth = str(function_tmpdir / "P07_2K") mf.model_ws = cpth mf.write_input() @@ -116,14 +116,14 @@ def test_mf2000_p07(tmpdir, mf2kmt3d_model_path): @requires_exe("mf2000", "mt3dms") -def test_mf2000_HSSTest(tmpdir, mf2kmt3d_model_path): +def test_mf2000_HSSTest(function_tmpdir, mf2kmt3d_model_path): pth = str(mf2kmt3d_model_path / "HSSTest") namfile = "hsstest_mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(tmpdir / "HSSTest") + cpth = str(function_tmpdir / "HSSTest") mf.model_ws = cpth mf.write_input() @@ -143,7 +143,7 @@ def test_mf2000_HSSTest(tmpdir, mf2kmt3d_model_path): @requires_exe("mf2000", "mt3dms") -def test_mf2000_mnw(tmpdir, mf2kmt3d_model_path): +def test_mf2000_mnw(function_tmpdir, mf2kmt3d_model_path): # cannot run this model because it uses mnw1 and there is no load for mnw1 # this model includes block format data in the btn file @@ -151,7 +151,7 @@ def test_mf2000_mnw(tmpdir, mf2kmt3d_model_path): namfile = "t5mf2k.nam" mf = Modflow.load(namfile, model_ws=pth, verbose=True) - cpth = str(tmpdir / "MNW") + cpth = str(function_tmpdir / "MNW") mf.model_ws = cpth namfile = "t5mt.nam" @@ -162,14 +162,14 @@ def test_mf2000_mnw(tmpdir, mf2kmt3d_model_path): @requires_exe("mf2000", "mt3dms") -def test_mf2000_MultiDiffusion(tmpdir, mf2kmt3d_model_path): +def test_mf2000_MultiDiffusion(function_tmpdir, mf2kmt3d_model_path): pth = str(mf2kmt3d_model_path / "MultiDiffusion") namfile = "p7mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(tmpdir / "MultiDiffusion") + cpth = str(function_tmpdir / "MultiDiffusion") mf.model_ws = cpth mf.write_input() @@ -187,14 +187,14 @@ def test_mf2000_MultiDiffusion(tmpdir, mf2kmt3d_model_path): @requires_exe("mf2000", "mt3dms") -def test_mf2000_reinject(tmpdir, mf2kmt3d_model_path): +def test_mf2000_reinject(function_tmpdir, mf2kmt3d_model_path): pth = str(mf2kmt3d_model_path / "reinject") namfile = "p3mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(tmpdir / "reinject") + cpth = str(function_tmpdir / "reinject") mf.model_ws = cpth mf.write_input() @@ -214,14 +214,14 @@ def test_mf2000_reinject(tmpdir, mf2kmt3d_model_path): @requires_exe("mf2000", "mt3dms") -def test_mf2000_SState(tmpdir, mf2kmt3d_model_path): +def test_mf2000_SState(function_tmpdir, mf2kmt3d_model_path): pth = str(mf2kmt3d_model_path / "SState") namfile = "SState_mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(tmpdir / "SState") + cpth = str(function_tmpdir / "SState") mf.model_ws = cpth mf.write_input() @@ -241,14 +241,14 @@ def test_mf2000_SState(tmpdir, mf2kmt3d_model_path): @requires_exe("mf2000", "mt3dms") -def test_mf2000_tob(tmpdir, mf2kmt3d_model_path): +def test_mf2000_tob(function_tmpdir, mf2kmt3d_model_path): pth = str(mf2kmt3d_model_path / "tob") namfile = "p7mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(tmpdir / "tob") + cpth = str(function_tmpdir / "tob") mf.model_ws = cpth mf.lmt6.output_file_header = "extended" @@ -271,14 +271,14 @@ def test_mf2000_tob(tmpdir, mf2kmt3d_model_path): @requires_exe("mf2000", "mt3dms") -def test_mf2000_zeroth(tmpdir, mf2kmt3d_model_path): +def test_mf2000_zeroth(function_tmpdir, mf2kmt3d_model_path): pth = str(mf2kmt3d_model_path / "zeroth") namfile = "z0mf2k.nam" mf = Modflow.load( namfile, model_ws=pth, version="mf2k", verbose=True, exe_name="mf2000" ) - cpth = str(tmpdir / "zeroth") + cpth = str(function_tmpdir / "zeroth") mf.model_ws = cpth mf.write_input() @@ -301,7 +301,7 @@ def test_mf2000_zeroth(tmpdir, mf2kmt3d_model_path): @excludes_platform( "Windows", ci_only=True ) # TODO remove once fixed in MT3D-USGS -def test_mfnwt_CrnkNic(tmpdir, mfnwtmt3d_model_path): +def test_mfnwt_CrnkNic(function_tmpdir, mfnwtmt3d_model_path): pth = str(mfnwtmt3d_model_path / "sft_crnkNic") namefile = "CrnkNic.nam" mf = Modflow.load( @@ -312,7 +312,7 @@ def test_mfnwt_CrnkNic(tmpdir, mfnwtmt3d_model_path): exe_name="mfnwt", ) - cpth = str(tmpdir / "SFT_CRNKNIC") + cpth = str(function_tmpdir / "SFT_CRNKNIC") mf.model_ws = cpth mf.write_input() @@ -340,7 +340,7 @@ def test_mfnwt_CrnkNic(tmpdir, mfnwtmt3d_model_path): @pytest.mark.slow @requires_exe("mfnwt", "mt3dusgs") -def test_mfnwt_LKT(tmpdir, mfnwtmt3d_model_path): +def test_mfnwt_LKT(function_tmpdir, mfnwtmt3d_model_path): pth = str(mfnwtmt3d_model_path / "lkt") namefile = "lkt_mf.nam" mf = Modflow.load( @@ -354,7 +354,7 @@ def test_mfnwt_LKT(tmpdir, mfnwtmt3d_model_path): assert not mf.load_fail, "MODFLOW model did not load" - cpth = str(tmpdir / "LKT") + cpth = str(function_tmpdir / "LKT") mf.model_ws = cpth # write modflow-nwt files @@ -388,7 +388,7 @@ def test_mfnwt_LKT(tmpdir, mfnwtmt3d_model_path): @pytest.mark.slow @requires_exe("mfnwt", "mt3dusgs") -def test_mfnwt_keat_uzf(tmpdir, mfnwtmt3d_model_path): +def test_mfnwt_keat_uzf(function_tmpdir, mfnwtmt3d_model_path): pth = str(mfnwtmt3d_model_path / "keat_uzf") namefile = "Keat_UZF_mf.nam" mf = Modflow.load( @@ -399,7 +399,7 @@ def test_mfnwt_keat_uzf(tmpdir, mfnwtmt3d_model_path): exe_name="mfnwt", ) - cpth = str(tmpdir / "KEAT_UZF") + cpth = str(function_tmpdir / "KEAT_UZF") mf.model_ws = cpth mf.write_input() @@ -430,8 +430,8 @@ def test_mfnwt_keat_uzf(tmpdir, mfnwtmt3d_model_path): os.remove(os.path.join(cpth, ftlfile)) -def test_mt3d_create_withmfmodel(tmpdir): - model_ws = str(tmpdir) +def test_mt3d_create_withmfmodel(function_tmpdir): + model_ws = str(function_tmpdir) # Create a MODFLOW model mf = Modflow(model_ws=model_ws) @@ -484,8 +484,8 @@ def test_mt3d_create_withmfmodel(tmpdir): return -def test_mt3d_create_woutmfmodel(tmpdir): - model_ws = str(tmpdir) +def test_mt3d_create_woutmfmodel(function_tmpdir): + model_ws = str(function_tmpdir) # Create MT3D model mt = Mt3dms(model_ws=model_ws) @@ -567,9 +567,9 @@ def test_mt3d_create_woutmfmodel(tmpdir): return -def test_mt3d_pht3d(tmpdir): +def test_mt3d_pht3d(function_tmpdir): # Note: this test is incomplete! - model_ws = str(tmpdir) + model_ws = str(function_tmpdir) # Create MT3D model mt = Mt3dms(model_ws=model_ws) @@ -584,7 +584,7 @@ def test_mt3d_pht3d(tmpdir): ) -def test_mt3d_multispecies(tmpdir): +def test_mt3d_multispecies(function_tmpdir): # modflow model modelname = "multispecies" @@ -594,7 +594,7 @@ def test_mt3d_multispecies(tmpdir): nper = 10 mf = Modflow( modelname=modelname, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) dis = ModflowDis(mf, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) lpf = ModflowLpf(mf) @@ -607,7 +607,7 @@ def test_mt3d_multispecies(tmpdir): mt = Mt3dms( modelname=modelname, modflowmodel=mf, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), verbose=True, ) sconc3 = np.random.random((nrow, ncol)) @@ -639,7 +639,7 @@ def test_mt3d_multispecies(tmpdir): modelname2 = "multispecies2" mf2 = Modflow( modelname=modelname2, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) dis2 = ModflowDis(mf2, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) @@ -647,7 +647,7 @@ def test_mt3d_multispecies(tmpdir): fname = f"{modelname}.nam" mt2 = Mt3dms.load( fname, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), verbose=True, ) # check obs I/O @@ -657,14 +657,14 @@ def test_mt3d_multispecies(tmpdir): @requires_exe("mfnwt", "mt3dusgs") -def test_lkt_with_multispecies(tmpdir): +def test_lkt_with_multispecies(function_tmpdir): # Bug discovered in LKT with multi-species. Adding test to check this functionality modelname = "lkttest" mf = Modflow( modelname=modelname, exe_name="mfnwt", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), version="mfnwt", ) @@ -17782,7 +17782,7 @@ def test_lkt_with_multispecies(tmpdir): mt = Mt3dms( modflowmodel=mf, modelname=modelname, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), version="mt3d-usgs", namefile_ext="mtnam", exe_name="mt3dusgs", @@ -17903,7 +17903,7 @@ def test_lkt_with_multispecies(tmpdir): namfile = f"{modelname}.nam" mf = Modflow.load( namfile, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), version="mfnwt", verbose=True, exe_name="mfnwt", @@ -17911,7 +17911,7 @@ def test_lkt_with_multispecies(tmpdir): namfile = f"{modelname}.mtnam" mt = Mt3dms.load( namfile, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), verbose=True, version="mt3d-usgs", exe_name="mt3dusgs", @@ -17924,7 +17924,7 @@ def test_mt3dms_load_when_nam_dne(): @requires_exe("mf2005") -def test_mt3d_ssm_with_nodata_in_1st_sp(tmpdir): +def test_mt3d_ssm_with_nodata_in_1st_sp(function_tmpdir): nlay, nrow, ncol = 3, 5, 5 perlen = np.zeros((10), dtype=float) + 10 nper = len(perlen) @@ -17936,7 +17936,7 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(tmpdir): # creating MODFLOW model modelname = "model_mf" - mf = Modflow(modelname, model_ws=str(tmpdir), exe_name="mf2005") + mf = Modflow(modelname, model_ws=str(function_tmpdir), exe_name="mf2005") dis = ModflowDis( mf, nlay=nlay, @@ -17995,7 +17995,7 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(tmpdir): mt = Mt3dms( modflowmodel=mf, modelname=modelname, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), exe_name="mt3dms", ) btn = Mt3dBtn(mt, sconc=0, ncomp=2, sconc2=50.0) @@ -18013,11 +18013,16 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(tmpdir): success, buff = mt.run_model(report=True, normal_msg="Program completed.") assert success, "MT3D did not run" - ws = str(tmpdir / "ws2") - mf2 = Modflow.load("model_mf.nam", model_ws=str(tmpdir), exe_name="mf2005") + ws = str(function_tmpdir / "ws2") + mf2 = Modflow.load( + "model_mf.nam", model_ws=str(function_tmpdir), exe_name="mf2005" + ) mf2.change_model_ws(ws) mt2 = Mt3dms.load( - "model_mt.nam", model_ws=str(tmpdir), verbose=True, exe_name="mt3dms" + "model_mt.nam", + model_ws=str(function_tmpdir), + verbose=True, + exe_name="mt3dms", ) mt2.change_model_ws(ws) mf2.write_input() @@ -18027,18 +18032,20 @@ def test_mt3d_ssm_with_nodata_in_1st_sp(tmpdir): success, buff = mt2.run_model(report=True, normal_msg="Program completed.") assert success, "MT3D did not run" - conca = UcnFile(os.path.join(str(tmpdir), "MT3D001.UCN")).get_alldata() + conca = UcnFile( + os.path.join(str(function_tmpdir), "MT3D001.UCN") + ).get_alldata() concb = UcnFile(os.path.join(ws, "MT3D001.UCN")).get_alldata() assert np.allclose(conca, concb) @requires_exe("mf2005") -def test_none_spdtype(tmpdir): +def test_none_spdtype(function_tmpdir): # ensure that -1 and None work as valid list entries in the # stress period dictionary - mf = Modflow(model_ws=str(tmpdir), exe_name="mf2005") + mf = Modflow(model_ws=str(function_tmpdir), exe_name="mf2005") dis = ModflowDis(mf, nper=2) bas = ModflowBas(mf) lpf = ModflowLpf(mf) @@ -18046,12 +18053,14 @@ def test_none_spdtype(tmpdir): wel = ModflowWel(mf, stress_period_data=spd) pcg = ModflowPcg(mf) mf.write_input() - mf2 = Modflow.load("modflowtest.nam", model_ws=str(tmpdir), verbose=True) + mf2 = Modflow.load( + "modflowtest.nam", model_ws=str(function_tmpdir), verbose=True + ) success, buff = mf.run_model(report=True) assert success -def test_ssm_readwrite(tmpdir, example_data_path): +def test_ssm_readwrite(function_tmpdir, example_data_path): # Instantiate MODFLOW model mf = Modflow() @@ -18073,7 +18082,7 @@ def test_ssm_readwrite(tmpdir, example_data_path): # (file comes from: https://github.com/modflowpy/flopy/issues/743) ssm = Mt3dSsm.load(fl, mt) - mt.change_model_ws(str(tmpdir)) + mt.change_model_ws(str(function_tmpdir)) # Ensure file is writeable ssm.write_file() diff --git a/autotest/test_nwt_ag.py b/autotest/test_nwt_ag.py index 980adbe260..3da5146151 100644 --- a/autotest/test_nwt_ag.py +++ b/autotest/test_nwt_ag.py @@ -4,13 +4,13 @@ from flopy.pakbase import Package -def test_empty_ag_package(tmpdir): +def test_empty_ag_package(function_tmpdir): ml = Modflow("agtest", version="mfnwt") ag = ModflowAg(ml) assert isinstance(ag, Package) -def test_load_write_agwater(tmpdir, example_data_path): +def test_load_write_agwater(function_tmpdir, example_data_path): agfile = "Agwater1.ag" ml = Modflow("Agwater1", version="mfnwt") mpath = example_data_path / "ag_test" @@ -24,20 +24,20 @@ def test_load_write_agwater(tmpdir, example_data_path): assert loaded - ml.change_model_ws(str(tmpdir)) + ml.change_model_ws(str(function_tmpdir)) ag1.write_file() ml2 = Modflow( "Agwater1", version="mfnwt", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) - ag2 = ModflowAg.load(str(tmpdir / agfile), ml2, nper=49) + ag2 = ModflowAg.load(str(function_tmpdir / agfile), ml2, nper=49) assert repr(ag1) == repr(ag2), "comparison failed" -def test_load_write_agwater_uzf(tmpdir, example_data_path): +def test_load_write_agwater_uzf(function_tmpdir, example_data_path): uzffile = "Agwater1.uzf" ml = Modflow("Agwater1", version="mfnwt") dis = ModflowDis(ml, nlay=1, nrow=15, ncol=10, nper=49) @@ -52,16 +52,16 @@ def test_load_write_agwater_uzf(tmpdir, example_data_path): assert loaded - ml.change_model_ws(str(tmpdir)) + ml.change_model_ws(str(function_tmpdir)) uzf1.write_file() ml2 = Modflow( "Agwater1", version="mfnwt", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) dis2 = ModflowDis(ml2, nlay=1, nrow=15, ncol=10, nper=49) - uzf2 = ModflowUzf1.load(str(tmpdir / uzffile), ml2) + uzf2 = ModflowUzf1.load(str(function_tmpdir / uzffile), ml2) assert np.allclose( uzf1.air_entry.array, uzf2.air_entry.array diff --git a/autotest/test_obs.py b/autotest/test_obs.py index 3c1374b040..828c120c55 100644 --- a/autotest/test_obs.py +++ b/autotest/test_obs.py @@ -3,7 +3,7 @@ import numpy as np import pytest -from autotest.conftest import requires_exe +from modflow_devtools.markers import requires_exe from flopy.modflow import ( HeadObservation, @@ -20,12 +20,12 @@ @requires_exe("mf2005") -def test_hob_simple(tmpdir): +def test_hob_simple(function_tmpdir): """ test041 create and run a simple MODFLOW-2005 OBS example """ modelname = "hob_simple" - ws = str(tmpdir) + ws = str(function_tmpdir) nlay, nrow, ncol = 1, 11, 11 shape3d = (nlay, nrow, ncol) shape2d = (nrow, ncol) @@ -107,13 +107,13 @@ def test_hob_simple(tmpdir): @requires_exe("mf2005") -def test_obs_load_and_write(tmpdir, example_data_path): +def test_obs_load_and_write(function_tmpdir, example_data_path): """ test041 load and write of MODFLOW-2005 OBS example problem """ pth = str(example_data_path / "mf2005_obs") - ws = str(tmpdir) + ws = str(function_tmpdir) # copy the original files files = os.listdir(pth) @@ -249,12 +249,12 @@ def test_obs_load_and_write(tmpdir, example_data_path): assert np.array_equal(drob.column, m.drob.column), s -def test_obs_single_time(tmpdir): +def test_obs_single_time(function_tmpdir): """ test reading a mf6 observation file with a single time """ - pth = str(tmpdir / "single.csv") + pth = str(function_tmpdir / "single.csv") with open(pth, "w") as file: file.write("time,obs01,obs02\n1.0,10.0,20.0\n") @@ -268,13 +268,13 @@ def test_obs_single_time(tmpdir): @requires_exe("mf2005") -def test_obs_create_and_write(tmpdir, example_data_path): +def test_obs_create_and_write(function_tmpdir, example_data_path): """ test041 create and write of MODFLOW-2005 OBS example problem """ pth = str(example_data_path / "mf2005_obs") - ws = str(tmpdir) + ws = str(function_tmpdir) # copy the original files files = os.listdir(pth) diff --git a/autotest/test_plot.py b/autotest/test_plot.py index f742ab80a2..300b9b62bb 100644 --- a/autotest/test_plot.py +++ b/autotest/test_plot.py @@ -2,7 +2,6 @@ import numpy as np import pytest -from autotest.conftest import requires_exe, requires_pkg from flaky import flaky from matplotlib import pyplot as plt from matplotlib import rcParams @@ -12,6 +11,7 @@ PathCollection, QuadMesh, ) +from modflow_devtools.markers import requires_exe, requires_pkg import flopy from flopy.discretization import StructuredGrid @@ -242,7 +242,7 @@ def test_cross_section_bc_UZF_3lay(example_data_path): ), f"Unexpected collection type: {type(col)}" -def test_map_view_contour(tmpdir): +def test_map_view_contour(function_tmpdir): arr = np.random.rand(10, 10) * 100 arr[-1, :] = np.nan delc = np.array([10] * 10, dtype=float) @@ -272,7 +272,7 @@ def test_map_view_contour(tmpdir): pmv = PlotMapView(modelgrid=grid, layer=0) contours = pmv.contour_array(a=arr) - plt.savefig(tmpdir / "map_view_contour.png") + plt.savefig(function_tmpdir / "map_view_contour.png") # if we ever revert from standard contours to tricontours, restore this nan check # for ix, lev in enumerate(contours.levels): @@ -297,7 +297,7 @@ def test_vertex_model_dot_plot(example_data_path): # occasional _tkinter.TclError: Can't find a usable tk.tcl (or init.tcl) # similar: https://github.com/microsoft/azure-pipelines-tasks/issues/16426 @flaky -def test_model_dot_plot(tmpdir, example_data_path): +def test_model_dot_plot(function_tmpdir, example_data_path): loadpth = example_data_path / "mf2005_test" ml = flopy.modflow.Modflow.load( "ibs2k.nam", "mf2k", model_ws=str(loadpth), check=False @@ -307,7 +307,7 @@ def test_model_dot_plot(tmpdir, example_data_path): assert len(ax) == 18, f"number of axes ({len(ax)}) is not equal to 18" -def test_dataset_dot_plot(tmpdir, example_data_path): +def test_dataset_dot_plot(function_tmpdir, example_data_path): loadpth = example_data_path / "mf2005_test" ml = flopy.modflow.Modflow.load( "ibs2k.nam", "mf2k", model_ws=str(loadpth), check=False @@ -319,7 +319,9 @@ def test_dataset_dot_plot(tmpdir, example_data_path): assert len(ax) == 2, f"number of hy axes ({len(ax)}) is not equal to 2" -def test_dataset_dot_plot_nlay_ne_plottable(tmpdir, example_data_path): +def test_dataset_dot_plot_nlay_ne_plottable( + function_tmpdir, example_data_path +): import matplotlib.pyplot as plt loadpth = example_data_path / "mf2005_test" @@ -333,15 +335,15 @@ def test_dataset_dot_plot_nlay_ne_plottable(tmpdir, example_data_path): ), "ml.bcf6.vcont.plot() ax is is not of type plt.Axes" -def test_model_dot_plot_export(tmpdir, example_data_path): +def test_model_dot_plot_export(function_tmpdir, example_data_path): loadpth = example_data_path / "mf2005_test" ml = flopy.modflow.Modflow.load( "ibs2k.nam", "mf2k", model_ws=str(loadpth), check=False ) - fh = os.path.join(tmpdir, "ibs2k") + fh = os.path.join(function_tmpdir, "ibs2k") ml.plot(mflay=0, filename_base=fh, file_extension="png") - files = [f for f in os.listdir(tmpdir) if f.endswith(".png")] + files = [f for f in os.listdir(function_tmpdir) if f.endswith(".png")] if len(files) < 10: raise AssertionError( "ml.plot did not properly export all supported data types" @@ -355,12 +357,12 @@ def test_model_dot_plot_export(tmpdir, example_data_path): @requires_pkg("pandas") @requires_exe("mf2005") -def test_pathline_plot_xc(tmpdir, example_data_path): +def test_pathline_plot_xc(function_tmpdir, example_data_path): # test with multi-layer example load_ws = example_data_path / "mp6" ml = Modflow.load("EXAMPLE.nam", model_ws=str(load_ws), exe_name="mf2005") - ml.change_model_ws(str(tmpdir)) + ml.change_model_ws(str(function_tmpdir)) ml.write_input() ml.run_model() @@ -368,7 +370,7 @@ def test_pathline_plot_xc(tmpdir, example_data_path): modelname="ex6", exe_name="mp6", modflowmodel=ml, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) mpb = Modpath6Bas( @@ -385,7 +387,7 @@ def test_pathline_plot_xc(tmpdir, example_data_path): mp.run_model(silent=False) - pthobj = PathlineFile(os.path.join(str(tmpdir), "ex6.mppth")) + pthobj = PathlineFile(os.path.join(str(function_tmpdir), "ex6.mppth")) well_pathlines = pthobj.get_destination_pathline_data( dest_cells=[(4, 12, 12)] ) @@ -402,8 +404,8 @@ def test_pathline_plot_xc(tmpdir, example_data_path): @pytest.fixture -def quasi3d_model(tmpdir): - mf = Modflow("model_mf", model_ws=str(tmpdir), exe_name="mf2005") +def quasi3d_model(function_tmpdir): + mf = Modflow("model_mf", model_ws=str(function_tmpdir), exe_name="mf2005") # Model domain and grid definition Lx = 1000.0 diff --git a/autotest/test_postprocessing.py b/autotest/test_postprocessing.py index 680f9a9c18..0b67cd6113 100644 --- a/autotest/test_postprocessing.py +++ b/autotest/test_postprocessing.py @@ -2,7 +2,7 @@ import matplotlib.pyplot as plt import numpy as np import pytest -from autotest.conftest import requires_exe +from modflow_devtools.markers import requires_exe from flopy.mf6 import ( MFSimulation, @@ -33,7 +33,7 @@ def mf6_freyberg_path(example_data_path): @pytest.mark.mf6 @requires_exe("mf6") -def test_faceflows(tmpdir, mf6_freyberg_path): +def test_faceflows(function_tmpdir, mf6_freyberg_path): sim = MFSimulation.load( sim_name="freyberg", exe_name="mf6", @@ -41,7 +41,7 @@ def test_faceflows(tmpdir, mf6_freyberg_path): ) # change the simulation workspace - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write the model simulation files sim.write_simulation() @@ -59,7 +59,7 @@ def test_faceflows(tmpdir, mf6_freyberg_path): frf, fff, flf = get_structured_faceflows( flowja, - grb_file=str(tmpdir / "freyberg.dis.grb"), + grb_file=str(function_tmpdir / "freyberg.dis.grb"), ) Qx, Qy, Qz = get_specific_discharge( (frf, fff, flf), @@ -101,7 +101,7 @@ def test_faceflows(tmpdir, mf6_freyberg_path): @pytest.mark.mf6 @requires_exe("mf6") -def test_flowja_residuals(tmpdir, mf6_freyberg_path): +def test_flowja_residuals(function_tmpdir, mf6_freyberg_path): sim = MFSimulation.load( sim_name="freyberg", exe_name="mf6", @@ -109,7 +109,7 @@ def test_flowja_residuals(tmpdir, mf6_freyberg_path): ) # change the simulation workspace - sim.set_sim_path(str(tmpdir)) + sim.set_sim_path(str(function_tmpdir)) # write the model simulation files sim.write_simulation() @@ -119,7 +119,7 @@ def test_flowja_residuals(tmpdir, mf6_freyberg_path): # get output gwf = sim.get_model("freyberg") - grb_file = str(tmpdir / "freyberg.dis.grb") + grb_file = str(function_tmpdir / "freyberg.dis.grb") cbc = gwf.output.budget() spdis = cbc.get_data(text="DATA-SPDIS")[0] @@ -149,9 +149,11 @@ def test_flowja_residuals(tmpdir, mf6_freyberg_path): @pytest.mark.mf6 @requires_exe("mf6") -def test_structured_faceflows_3d(tmpdir): +def test_structured_faceflows_3d(function_tmpdir): name = "mymodel" - sim = MFSimulation(sim_name=name, sim_ws=str(tmpdir), exe_name="mf6") + sim = MFSimulation( + sim_name=name, sim_ws=str(function_tmpdir), exe_name="mf6" + ) tdis = ModflowTdis(sim) ims = ModflowIms(sim) gwf = ModflowGwf(sim, modelname=name, save_flows=True) @@ -179,7 +181,7 @@ def test_structured_faceflows_3d(tmpdir): flowja = bud.get_data(text="FLOW-JA-FACE")[0] frf, fff, flf = get_structured_faceflows( flowja, - grb_file=str(tmpdir / "mymodel.dis.grb"), + grb_file=str(function_tmpdir / "mymodel.dis.grb"), ) assert ( frf.shape == head.shape @@ -192,7 +194,7 @@ def test_structured_faceflows_3d(tmpdir): ), f"frf.shape {frf.shape} != head.shape {head.shape}" -def test_get_transmissivities(tmpdir): +def test_get_transmissivities(function_tmpdir): sctop = [-0.25, 0.5, 1.7, 1.5, 3.0, 2.5, 3.0, -10.0] scbot = [-1.0, -0.5, 1.2, 0.5, 1.5, -0.2, 2.5, -11.0] heads = np.array( @@ -210,7 +212,7 @@ def test_get_transmissivities(tmpdir): for i in range(nl): botm[nl - i - 1, :, :] = i - m = Modflow("junk", version="mfnwt", model_ws=str(tmpdir)) + m = Modflow("junk", version="mfnwt", model_ws=str(function_tmpdir)) dis = ModflowDis(m, nlay=nl, nrow=nr, ncol=nc, botm=botm, top=top) upw = ModflowUpw(m, hk=hk) @@ -270,7 +272,7 @@ def test_get_water_table(): assert np.sum(wt) == 34.0 -def test_get_sat_thickness_gradients(tmpdir): +def test_get_sat_thickness_gradients(function_tmpdir): nodata = -9999.0 hds = np.ones((3, 3, 3), dtype=float) * nodata hds[1, :, :] = 2.4 @@ -285,7 +287,7 @@ def test_get_sat_thickness_gradients(tmpdir): botm[0, :, :] = 3.0 botm[1, :, :] = 2.0 - m = Modflow("junk", version="mfnwt", model_ws=str(tmpdir)) + m = Modflow("junk", version="mfnwt", model_ws=str(function_tmpdir)) dis = ModflowDis(m, nlay=nl, nrow=nr, ncol=nc, botm=botm, top=top) lpf = ModflowLpf(m, laytyp=np.ones(nl)) diff --git a/autotest/test_seawat.py b/autotest/test_seawat.py index b7f0a39720..46aa59f37b 100644 --- a/autotest/test_seawat.py +++ b/autotest/test_seawat.py @@ -2,7 +2,8 @@ import numpy as np import pytest -from autotest.conftest import get_example_data_path, requires_exe +from autotest.conftest import get_example_data_path +from modflow_devtools.markers import requires_exe from flopy.modflow import ( Modflow, @@ -48,10 +49,10 @@ @pytest.mark.slow @requires_exe("swtv4") -def test_seawat_henry(tmpdir): +def test_seawat_henry(function_tmpdir): # SEAWAT model from a modflow model and an mt3d model modelname = "henry" - mf = Modflow(modelname, exe_name="swtv4", model_ws=str(tmpdir)) + mf = Modflow(modelname, exe_name="swtv4", model_ws=str(function_tmpdir)) # shortened perlen to 0.1 to make this run faster -- should be about 0.5 dis = ModflowDis( mf, @@ -78,7 +79,7 @@ def test_seawat_henry(tmpdir): ) # Create the basic MT3DMS model structure - mt = Mt3dms(modelname, "nam_mt3dms", mf, model_ws=str(tmpdir)) + mt = Mt3dms(modelname, "nam_mt3dms", mf, model_ws=str(function_tmpdir)) btn = Mt3dBtn( mt, nprs=-5, @@ -101,7 +102,7 @@ def test_seawat_henry(tmpdir): "nam_swt", mf, mt, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), exe_name="swtv4", ) vdf = SeawatVdf( @@ -125,13 +126,13 @@ def test_seawat_henry(tmpdir): @pytest.mark.slow @requires_exe("swtv4") -def test_seawat2_henry(tmpdir): +def test_seawat2_henry(function_tmpdir): # SEAWAT model directly by adding packages modelname = "henry2" m = Seawat( modelname, "nam", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), exe_name="swtv4", ) dis = ModflowDis( @@ -202,12 +203,12 @@ def swt4_namfiles(): @requires_exe("swtv4") @pytest.mark.parametrize("namfile", swt4_namfiles()) @pytest.mark.parametrize("binary", [True, False]) -def test_seawat_load_and_write(tmpdir, namfile, binary): +def test_seawat_load_and_write(function_tmpdir, namfile, binary): model_name = Path(namfile).name m = Seawat.load( model_name, model_ws=str(Path(namfile).parent), verbose=True ) - m.change_model_ws(str(tmpdir), reset_external=True) + m.change_model_ws(str(function_tmpdir), reset_external=True) if binary: skip_bcf6 = False @@ -237,12 +238,12 @@ def test_seawat_load_and_write(tmpdir, namfile, binary): assert success -def test_vdf_vsc(tmpdir): +def test_vdf_vsc(function_tmpdir): nlay = 3 nrow = 4 ncol = 5 nper = 3 - m = Seawat(modelname="vdftest", model_ws=str(tmpdir)) + m = Seawat(modelname="vdftest", model_ws=str(function_tmpdir)) dis = ModflowDis(m, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper) vdf = SeawatVdf(m) diff --git a/autotest/test_sfr.py b/autotest/test_sfr.py index 81c5ef1123..85a706cb10 100644 --- a/autotest/test_sfr.py +++ b/autotest/test_sfr.py @@ -8,7 +8,8 @@ import matplotlib.pyplot as plt import numpy as np import pytest -from autotest.conftest import get_example_data_path, requires_exe, requires_pkg +from autotest.conftest import get_example_data_path +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.discretization import StructuredGrid from flopy.modflow import Modflow, ModflowDis, ModflowSfr2, ModflowStr @@ -129,7 +130,7 @@ def test_load_sfr(case, mf2005_model_path): sfr = ModflowSfr2.load(str(mf2005_model_path / case["sfrfile"]), m) -def test_sfr(tmpdir, mf2005_model_path, sfr_test_model_path): +def test_sfr(function_tmpdir, mf2005_model_path, sfr_test_model_path): def sfr_process(mfnam, sfrfile, model_ws, outfolder): m = Modflow.load(mfnam, model_ws=model_ws, verbose=False) sfr = m.get_package("SFR") @@ -154,11 +155,11 @@ def sfr_process(mfnam, sfrfile, model_ws, outfolder): return m, sfr m, sfr = sfr_process( - "test1ss.nam", "test1ss.sfr", mf2005_model_path, tmpdir + "test1ss.nam", "test1ss.sfr", mf2005_model_path, function_tmpdir ) m, sfr = sfr_process( - "test1tr.nam", "test1tr.sfr", mf2005_model_path, tmpdir + "test1tr.nam", "test1tr.sfr", mf2005_model_path, function_tmpdir ) # assert list(sfr.dataset_5.keys()) == [0, 1] @@ -167,7 +168,7 @@ def sfr_process(mfnam, sfrfile, model_ws, outfolder): "testsfr2_tab.nam", "testsfr2_tab_ICALC1.sfr", mf2005_model_path, - tmpdir, + function_tmpdir, ) assert list(sfr.dataset_5.keys()) == list(range(0, 50)) @@ -176,7 +177,7 @@ def sfr_process(mfnam, sfrfile, model_ws, outfolder): "testsfr2_tab.nam", "testsfr2_tab_ICALC2.sfr", mf2005_model_path, - tmpdir, + function_tmpdir, ) assert sfr.channel_geometry_data[0][1] == [ @@ -185,13 +186,13 @@ def sfr_process(mfnam, sfrfile, model_ws, outfolder): ] m, sfr = sfr_process( - "testsfr2.nam", "testsfr2.sfr", mf2005_model_path, tmpdir + "testsfr2.nam", "testsfr2.sfr", mf2005_model_path, function_tmpdir ) assert round(sum(sfr.segment_data[49][0]), 7) == 3.9700007 m, sfr = sfr_process( - "UZFtest2.nam", "UZFtest2.sfr", mf2005_model_path, tmpdir + "UZFtest2.nam", "UZFtest2.sfr", mf2005_model_path, function_tmpdir ) assert isinstance( @@ -373,29 +374,31 @@ def test_const(sfr_data): @requires_pkg("pandas", "shapefile") -def test_export(tmpdir, sfr_data): +def test_export(function_tmpdir, sfr_data): m = Modflow() dis = ModflowDis(m, 1, 10, 10, lenuni=2, itmuni=4) - m.export(str(tmpdir / "grid.shp")) + m.export(str(function_tmpdir / "grid.shp")) r, d = sfr_data sfr = ModflowSfr2(m, reach_data=r, segment_data={0: d}) sfr.segment_data[0]["flow"][-1] = 1e4 - sfr.stress_period_data.export(str(tmpdir / "sfr.shp"), sparse=True) - sfr.export_linkages(str(tmpdir / "linkages.shp")) - sfr.export_outlets(str(tmpdir / "outlets.shp")) - sfr.export_transient_variable(str(tmpdir / "inlets.shp"), "flow") + sfr.stress_period_data.export( + str(function_tmpdir / "sfr.shp"), sparse=True + ) + sfr.export_linkages(str(function_tmpdir / "linkages.shp")) + sfr.export_outlets(str(function_tmpdir / "outlets.shp")) + sfr.export_transient_variable(str(function_tmpdir / "inlets.shp"), "flow") from flopy.export.shapefile_utils import shp2recarray - ra = shp2recarray(str(tmpdir / "inlets.shp")) + ra = shp2recarray(str(function_tmpdir / "inlets.shp")) assert ra.flow0[0] == 1e4 - ra = shp2recarray(str(tmpdir / "outlets.shp")) + ra = shp2recarray(str(function_tmpdir / "outlets.shp")) assert ra.iseg[0] + ra.ireach[0] == 5 - ra = shp2recarray(str(tmpdir / "linkages.shp")) + ra = shp2recarray(str(function_tmpdir / "linkages.shp")) crds = np.array(list(ra.geometry[2].coords)) assert np.array_equal(crds, np.array([[2.5, 4.5], [3.5, 5.5]])) - ra = shp2recarray(str(tmpdir / "sfr.shp")) + ra = shp2recarray(str(function_tmpdir / "sfr.shp")) assert ra.iseg.sum() == sfr.reach_data.iseg.sum() assert ra.ireach.sum() == sfr.reach_data.ireach.sum() y = np.concatenate([np.array(g.exterior)[:, 1] for g in ra.geometry]) @@ -525,7 +528,7 @@ def test_example(mf2005_model_path): assert sfr2.dataset_5[i][0] == -1 -def test_no_ds_6bc(tmpdir): +def test_no_ds_6bc(function_tmpdir): """Test case where datasets 6b and 6c aren't read (e.g., see table at https://water.usgs.gov/ogw/modflow-nwt/MODFLOW-NWT-Guide/sfr.htm) """ @@ -543,7 +546,7 @@ def test_no_ds_6bc(tmpdir): "2.77 1.11 0.83 0 0.28 0.83 1.11 2.77\n" ) sfrfile = io.StringIO(sfrfiletxt) - m = Modflow("junk", model_ws=str(tmpdir)) + m = Modflow("junk", model_ws=str(function_tmpdir)) sfr = ModflowSfr2.load(sfrfile, model=m) assert len(sfr.segment_data[0]) == 2 assert len(sfr.channel_geometry_data[0]) == 2 @@ -552,7 +555,7 @@ def test_no_ds_6bc(tmpdir): assert len(sfr.channel_geometry_data[0][1][i]) == 8 assert sum(sfr.channel_geometry_data[0][1][i]) > 0.0 - sfrfile2 = str(tmpdir / "junk.sfr") + sfrfile2 = str(function_tmpdir / "junk.sfr") sfr.write_file() sfr = ModflowSfr2.load(sfrfile2, model=m) assert len(sfr.segment_data[0]) == 2 @@ -563,12 +566,12 @@ def test_no_ds_6bc(tmpdir): assert sum(sfr.channel_geometry_data[0][1][i]) > 0.0 -def test_ds_6d_6e_disordered(tmpdir, hydmod_model_path): +def test_ds_6d_6e_disordered(function_tmpdir, hydmod_model_path): m = Modflow.load("test1tr2.nam", model_ws=str(hydmod_model_path)) - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) m.write_input() - m2 = Modflow.load("test1tr2.nam", model_ws=str(tmpdir)) + m2 = Modflow.load("test1tr2.nam", model_ws=str(function_tmpdir)) sfr = m.get_package("SFR") sfr2 = m2.get_package("SFR") @@ -590,7 +593,7 @@ def test_ds_6d_6e_disordered(tmpdir, hydmod_model_path): raise AssertionError -def test_disordered_reachdata_fields(tmpdir, hydmod_model_path): +def test_disordered_reachdata_fields(function_tmpdir, hydmod_model_path): m = Modflow.load("test1tr2.nam", model_ws=str(hydmod_model_path)) sfr = m.get_package("SFR") orig_reach_data = sfr.reach_data @@ -605,28 +608,28 @@ def test_disordered_reachdata_fields(tmpdir, hydmod_model_path): formats.append(orig_reach_data.dtype[field].str) reach_data = np.rec.fromarrays(data, names=names, formats=formats) m.sfr.reach_data = reach_data - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) m.write_input() -def test_transient_example(tmpdir, mf2005_model_path): +def test_transient_example(function_tmpdir, mf2005_model_path): gpth = str(mf2005_model_path / "testsfr2.*") for f in glob.glob(gpth): - shutil.copy(f, tmpdir) - m = Modflow.load("testsfr2.nam", model_ws=str(tmpdir)) + shutil.copy(f, function_tmpdir) + m = Modflow.load("testsfr2.nam", model_ws=str(function_tmpdir)) # test handling of unformatted output file m.sfr.istcb2 = -49 m.set_output_attribute(unit=abs(m.sfr.istcb2), attr={"binflag": True}) m.write_input() - m2 = Modflow.load("testsfr2.nam", model_ws=str(tmpdir)) + m2 = Modflow.load("testsfr2.nam", model_ws=str(function_tmpdir)) assert m2.sfr.istcb2 == -49 assert m2.get_output_attribute(unit=abs(m2.sfr.istcb2), attr="binflag") @pytest.mark.skip("Pending https://github.com/modflowpy/flopy/issues/1471") -def test_assign_layers(tmpdir): - m = Modflow(model_ws=str(tmpdir)) +def test_assign_layers(function_tmpdir): + m = Modflow(model_ws=str(function_tmpdir)) m.dis = ModflowDis( nrow=1, ncol=6, @@ -666,7 +669,7 @@ def test_assign_layers(tmpdir): @requires_exe("mf2005") @requires_pkg("pandas") -def test_SfrFile(tmpdir, sfr_examples_path, mf2005_model_path): +def test_SfrFile(function_tmpdir, sfr_examples_path, mf2005_model_path): common_names = [ "layer", "row", @@ -744,11 +747,11 @@ def test_SfrFile(tmpdir, sfr_examples_path, mf2005_model_path): ml = Modflow.load( "test1tr.nam", model_ws=str(mf2005_model_path), exe_name="mf2005" ) - ml.change_model_ws(str(tmpdir)) + ml.change_model_ws(str(function_tmpdir)) ml.write_input() ml.run_model() - sfrout = SfrFile(str(tmpdir / "test1tr.flw")) + sfrout = SfrFile(str(function_tmpdir / "test1tr.flw")) assert sfrout.ncol == 16, sfrout.ncol assert sfrout.names == common_names + ["gradient"], sfrout.names expected_times = [ @@ -810,13 +813,13 @@ def get_test_matrix(): return t -def test_sfrcheck(tmpdir, mf2005_model_path): +def test_sfrcheck(function_tmpdir, mf2005_model_path): m = Modflow.load( "test1tr.nam", model_ws=str(mf2005_model_path), verbose=False ) # run level=0 check - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) fpth = "SFRchecker_results.txt" m.sfr.check(fpth, level=0) @@ -882,10 +885,12 @@ def test_sfrcheck(tmpdir, mf2005_model_path): @pytest.mark.parametrize("i, case", list(sfr_models().items())) -def test_sfrloadcheck(tmpdir, mf2005_model_path, i, case): +def test_sfrloadcheck(function_tmpdir, mf2005_model_path, i, case): m = Modflow.load(case["mfnam"], model_ws=str(mf2005_model_path)) - m.model_ws = str(tmpdir) - checker_outfile = os.path.join(str(tmpdir), f"SFRcheck_{m.name}.txt") + m.model_ws = str(function_tmpdir) + checker_outfile = os.path.join( + str(function_tmpdir), f"SFRcheck_{m.name}.txt" + ) chk = m.sfr.check(checker_outfile, level=1) @@ -897,7 +902,7 @@ def test_sfrloadcheck(tmpdir, mf2005_model_path, i, case): @requires_exe("mfnwt") @pytest.mark.parametrize("isfropt, icalc", get_test_matrix()) -def test_isfropt_icalc(tmpdir, example_data_path, isfropt, icalc): +def test_isfropt_icalc(function_tmpdir, example_data_path, isfropt, icalc): pth = example_data_path / "sfr_test" nam = f"sfrtest{isfropt}{icalc}.nam" ml = Modflow.load(nam, check=False, model_ws=pth, exe_name="mfnwt") @@ -905,7 +910,7 @@ def test_isfropt_icalc(tmpdir, example_data_path, isfropt, icalc): if sfr is None: raise AssertionError() - ws = os.path.join(str(tmpdir), f"sfrtest{isfropt}{icalc}") + ws = os.path.join(str(function_tmpdir), f"sfrtest{isfropt}{icalc}") ml.change_model_ws(ws) ml.write_input() success = ml.run_model()[0] @@ -935,7 +940,7 @@ def test_isfropt_icalc(tmpdir, example_data_path, isfropt, icalc): ), ], ) -def test_mf2005(tmpdir, namfile): +def test_mf2005(function_tmpdir, namfile): m = Modflow.load( namfile, exe_name="mf2005dbl", @@ -947,7 +952,7 @@ def test_mf2005(tmpdir, namfile): assert m.load_fail is False # rewrite files - ws = tmpdir / "ws" + ws = function_tmpdir / "ws" m.model_ws = str(ws) m.write_input() diff --git a/autotest/test_specific_discharge.py b/autotest/test_specific_discharge.py index 115b4b4a7f..5043f0ca38 100644 --- a/autotest/test_specific_discharge.py +++ b/autotest/test_specific_discharge.py @@ -124,9 +124,9 @@ @pytest.fixture -def mf2005_model(tmpdir): +def mf2005_model(function_tmpdir): # create modflow model - mf = Modflow("mf2005", model_ws=str(tmpdir), exe_name="mf2005") + mf = Modflow("mf2005", model_ws=str(function_tmpdir), exe_name="mf2005") # cell by cell flow file unit number cbc_unit_nb = 53 @@ -182,14 +182,17 @@ def mf2005_model(tmpdir): # write the MODFLOW model input files mf.write_input() - return mf, tmpdir + return mf, function_tmpdir @pytest.fixture -def mf6_model(tmpdir): +def mf6_model(function_tmpdir): # create simulation sim = MFSimulation( - sim_name="mf6", version="mf6", exe_name="mf6", sim_ws=str(tmpdir) + sim_name="mf6", + version="mf6", + exe_name="mf6", + sim_ws=str(function_tmpdir), ) # create tdis package @@ -300,7 +303,7 @@ def mf6_model(tmpdir): # write input files sim.write_simulation() - return sim, tmpdir + return sim, function_tmpdir def basic_check(Qx_ext, Qy_ext, Qz_ext): @@ -352,11 +355,13 @@ def local_balance_check(Qx_ext, Qy_ext, Qz_ext, hdsfile=None, model=None): @pytest.mark.xfail(reason="occasional Unexpected collection type") def test_extended_budget_default(mf2005_model): # build and run MODFLOW 2005 model - mf, tmpdir = mf2005_model + mf, function_tmpdir = mf2005_model success, buff = mf.run_model() # load and postprocess - Qx_ext, Qy_ext, Qz_ext = get_extended_budget(str(tmpdir / "mf2005.cbc")) + Qx_ext, Qy_ext, Qz_ext = get_extended_budget( + str(function_tmpdir / "mf2005.cbc") + ) # basic check basic_check(Qx_ext, Qy_ext, Qz_ext) @@ -366,17 +371,17 @@ def test_extended_budget_default(mf2005_model): assert np.allclose(overall, -1122.4931640625) # call other evaluations - specific_discharge_default(tmpdir) - specific_discharge_comprehensive(tmpdir) + specific_discharge_default(function_tmpdir) + specific_discharge_comprehensive(function_tmpdir) -def extended_budget_comprehensive(tmpdir): +def extended_budget_comprehensive(function_tmpdir): # load and postprocess - mf = Modflow.load(str(tmpdir / "mf2005.nam"), check=False) + mf = Modflow.load(str(function_tmpdir / "mf2005.nam"), check=False) Qx_ext, Qy_ext, Qz_ext = get_extended_budget( - str(tmpdir / "mf2005.cbc"), + str(function_tmpdir / "mf2005.cbc"), boundary_ifaces=boundary_ifaces, - hdsfile=str(tmpdir / "mf2005.hds"), + hdsfile=str(function_tmpdir / "mf2005.hds"), model=mf, ) @@ -384,17 +389,19 @@ def extended_budget_comprehensive(tmpdir): basic_check(Qx_ext, Qy_ext, Qz_ext) # local balance check - local_balance_check(Qx_ext, Qy_ext, Qz_ext, str(tmpdir / "mf2005.hds"), mf) + local_balance_check( + Qx_ext, Qy_ext, Qz_ext, str(function_tmpdir / "mf2005.hds"), mf + ) # overall check overall = np.sum(Qx_ext) + np.sum(Qy_ext) + np.sum(Qz_ext) assert np.allclose(overall, -1110.646240234375) -def specific_discharge_default(tmpdir): +def specific_discharge_default(function_tmpdir): # load and postprocess - mf = Modflow.load(str(tmpdir / "mf2005.nam"), check=False) - cbc = bf.CellBudgetFile(str(tmpdir / "mf2005.cbc")) + mf = Modflow.load(str(function_tmpdir / "mf2005.nam"), check=False) + cbc = bf.CellBudgetFile(str(function_tmpdir / "mf2005.cbc")) keys = ["FLOW RIGHT FACE", "FLOW FRONT FACE", "FLOW LOWER FACE"] vectors = [cbc.get_data(text=t)[0] for t in keys] qx, qy, qz = get_specific_discharge(vectors, mf) @@ -404,16 +411,16 @@ def specific_discharge_default(tmpdir): assert np.allclose(overall, -1.7959892749786377) -def specific_discharge_comprehensive(tmpdir): +def specific_discharge_comprehensive(function_tmpdir): - hds = bf.HeadFile(str(tmpdir / "mf2005.hds")) + hds = bf.HeadFile(str(function_tmpdir / "mf2005.hds")) head = hds.get_data() # load and postprocess - mf = Modflow.load(str(tmpdir / "mf2005.nam"), check=False) + mf = Modflow.load(str(function_tmpdir / "mf2005.nam"), check=False) Qx_ext, Qy_ext, Qz_ext = get_extended_budget( - str(tmpdir / "mf2005.cbc"), + str(function_tmpdir / "mf2005.cbc"), boundary_ifaces=boundary_ifaces, - hdsfile=str(tmpdir / "mf2005.hds"), + hdsfile=str(function_tmpdir / "mf2005.hds"), model=mf, ) @@ -450,7 +457,7 @@ def specific_discharge_comprehensive(tmpdir): plt.close() # plot discharge in cross-section view - hds = bf.HeadFile(str(tmpdir / "mf2005.hds"), precision="single") + hds = bf.HeadFile(str(function_tmpdir / "mf2005.hds"), precision="single") head = hds.get_data() row = 0 xsect = PlotCrossSection(model=mf, line={"row": row}) @@ -491,17 +498,17 @@ def specific_discharge_comprehensive(tmpdir): ) def test_specific_discharge_mf6(mf6_model): # build and run MODFLOW 6 model - sim, tmpdir = mf6_model + sim, function_tmpdir = mf6_model sim.run_simulation() # load and postprocess sim = MFSimulation.load( - sim_name="mf6", sim_ws=str(tmpdir), verbosity_level=0 + sim_name="mf6", sim_ws=str(function_tmpdir), verbosity_level=0 ) gwf = sim.get_model("mf6") - hds = bf.HeadFile(str(tmpdir / "mf6.hds")) + hds = bf.HeadFile(str(function_tmpdir / "mf6.hds")) head = hds.get_data() - cbc = bf.CellBudgetFile(str(tmpdir / "mf6.cbc")) + cbc = bf.CellBudgetFile(str(function_tmpdir / "mf6.cbc")) spdis = cbc.get_data(text="SPDIS")[0] qx, qy, qz = get_specific_discharge(spdis, gwf, head) @@ -535,7 +542,7 @@ def test_specific_discharge_mf6(mf6_model): plt.close() # plot discharge in cross-section view - hds = bf.HeadFile(str(tmpdir / "mf6.hds"), precision="double") + hds = bf.HeadFile(str(function_tmpdir / "mf6.hds"), precision="double") head = hds.get_data() row = 0 xsect = PlotCrossSection(model=gwf, line={"row": row}) diff --git a/autotest/test_str.py b/autotest/test_str.py index 3e90baf24d..8a6cec82eb 100644 --- a/autotest/test_str.py +++ b/autotest/test_str.py @@ -1,5 +1,5 @@ import matplotlib -from autotest.conftest import requires_exe, requires_pkg +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.modflow import Modflow from flopy.utils import MfListBudget @@ -15,7 +15,7 @@ @requires_exe("mf2005") @requires_pkg("pandas") -def test_str_issue1164(tmpdir, example_data_path): +def test_str_issue1164(function_tmpdir, example_data_path): mf2005_model_path = example_data_path / "mf2005_test" m = Modflow.load( str_items[0]["mfnam"], @@ -25,7 +25,7 @@ def test_str_issue1164(tmpdir, example_data_path): check=False, ) - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) # adjust stress period data spd0 = m.str.stress_period_data[0] @@ -38,7 +38,7 @@ def test_str_issue1164(tmpdir, example_data_path): assert success, "could not run base model" # get the budget - lst_pth = str(tmpdir / str_items[0]["lstfile"]) + lst_pth = str(function_tmpdir / str_items[0]["lstfile"]) base_wb = MfListBudget(lst_pth).get_dataframes()[0] # set the model to free format diff --git a/autotest/test_subwt.py b/autotest/test_subwt.py index 9aeeab0639..5b436919e5 100644 --- a/autotest/test_subwt.py +++ b/autotest/test_subwt.py @@ -3,8 +3,8 @@ import numpy as np import pytest -from autotest.conftest import requires_exe from matplotlib import pyplot as plt +from modflow_devtools.markers import requires_exe from flopy.modflow import ( Modflow, @@ -26,8 +26,8 @@ def ibound_path(example_data_path): @pytest.mark.slow @requires_exe("mf2005") -def test_subwt(tmpdir, ibound_path): - ws = str(tmpdir) +def test_subwt(function_tmpdir, ibound_path): + ws = str(function_tmpdir) ml = Modflow("subwt_mf2005", model_ws=ws, exe_name="mf2005") perlen = [1.0, 60.0 * 365.25, 60 * 365.25] nstp = [1, 60, 60] @@ -111,24 +111,24 @@ def test_subwt(tmpdir, ibound_path): ml.run_model() - # contents = [f for f in tmpdir.glob("*.hds")] + # contents = [f for f in function_tmpdir.glob("*.hds")] hds_geo = HeadFile( - str(tmpdir / f"{ml.name}.swt_geostatic_stress.hds"), + str(function_tmpdir / f"{ml.name}.swt_geostatic_stress.hds"), text="stress", ).get_alldata() hds_eff = HeadFile( - str(tmpdir / f"{ml.name}.swt_eff_stress.hds"), + str(function_tmpdir / f"{ml.name}.swt_eff_stress.hds"), text="effective stress", ).get_alldata() hds_sub = HeadFile( - str(tmpdir / f"{ml.name}.swt_subsidence.hds"), + str(function_tmpdir / f"{ml.name}.swt_subsidence.hds"), text="subsidence", ).get_alldata() hds_comp = HeadFile( - str(tmpdir / f"{ml.name}.swt_total_comp.hds"), + str(function_tmpdir / f"{ml.name}.swt_total_comp.hds"), text="layer compaction", ).get_alldata() diff --git a/autotest/test_swr_binaryread.py b/autotest/test_swr_binaryread.py index 844ea45842..a4270da4d5 100644 --- a/autotest/test_swr_binaryread.py +++ b/autotest/test_swr_binaryread.py @@ -1,6 +1,6 @@ # Test SWR binary read functionality import pytest -from autotest.conftest import has_pkg +from modflow_devtools.misc import has_pkg from flopy.utils import ( SwrBudget, diff --git a/autotest/test_template_writer.py b/autotest/test_template_writer.py index 0d6cc7a3e8..52e769c297 100644 --- a/autotest/test_template_writer.py +++ b/autotest/test_template_writer.py @@ -6,14 +6,14 @@ from flopy.pest import Params, TemplateWriter, zonearray2params -def test_tpl_constant(tmpdir): +def test_tpl_constant(function_tmpdir): # Define the model dimensions nlay = 3 nrow = 20 ncol = 20 # Create the flopy model object and add the dis and lpf packages - m = Modflow(modelname="tpl1", model_ws=str(tmpdir)) + m = Modflow(modelname="tpl1", model_ws=str(function_tmpdir)) dis = ModflowDis(m, nlay, nrow, ncol) lpf = ModflowLpf(m, hk=10.0) @@ -38,17 +38,17 @@ def test_tpl_constant(tmpdir): tw = TemplateWriter(m, [p]) tw.write_template() - tplfile = str(tmpdir / "tpl1.lpf.tpl") + tplfile = str(function_tmpdir / "tpl1.lpf.tpl") assert os.path.isfile(tplfile) -def test_tpl_layered(tmpdir): +def test_tpl_layered(function_tmpdir): nlay = 3 nrow = 20 ncol = 20 # Create the flopy model object and add the dis and lpf packages - m = Modflow(modelname="tpl2", model_ws=str(tmpdir)) + m = Modflow(modelname="tpl2", model_ws=str(function_tmpdir)) dis = ModflowDis(m, nlay, nrow, ncol) lpf = ModflowLpf(m, hk=10.0) @@ -69,17 +69,17 @@ def test_tpl_layered(tmpdir): tw = TemplateWriter(m, [p]) tw.write_template() - tplfile = str(tmpdir / "tpl2.lpf.tpl") + tplfile = str(function_tmpdir / "tpl2.lpf.tpl") assert os.path.isfile(tplfile) -def test_tpl_zoned(tmpdir): +def test_tpl_zoned(function_tmpdir): nlay = 3 nrow = 20 ncol = 20 # Create the flopy model object and add the dis and lpf packages - m = Modflow(modelname="tpl3", model_ws=str(tmpdir)) + m = Modflow(modelname="tpl3", model_ws=str(function_tmpdir)) dis = ModflowDis(m, nlay, nrow, ncol) lpf = ModflowLpf(m, hk=10.0) @@ -130,5 +130,5 @@ def test_tpl_zoned(tmpdir): tw = TemplateWriter(m, plist) tw.write_template() - tplfile = str(tmpdir / "tpl3.lpf.tpl") + tplfile = str(function_tmpdir / "tpl3.lpf.tpl") assert os.path.isfile(tplfile) diff --git a/autotest/test_usg.py b/autotest/test_usg.py index 3d669c4e22..9caad568e9 100644 --- a/autotest/test_usg.py +++ b/autotest/test_usg.py @@ -3,8 +3,9 @@ import numpy as np import pytest -from autotest.conftest import get_example_data_path, requires_exe +from autotest.conftest import get_example_data_path from flaky import flaky +from modflow_devtools.markers import requires_exe from flopy.mfusg import MfUsg, MfUsgDisU, MfUsgLpf, MfUsgSms, MfUsgWel from flopy.modflow import ( @@ -33,7 +34,7 @@ def freyberg_usg_model_path(example_data_path): @requires_exe("mfusg") -def test_usg_disu_load(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): +def test_usg_disu_load(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): fname = str(mfusg_01A_nestedgrid_nognc_model_path / "flow.disu") assert os.path.isfile(fname), f"disu file not found {fname}" @@ -45,11 +46,11 @@ def test_usg_disu_load(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): assert isinstance(disu, MfUsgDisU) # Change where model files are written - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) # Write the disu file disu.write_file() - assert Path(tmpdir / f"{m.name}.{m.disu.extension[0]}").is_file() + assert Path(function_tmpdir / f"{m.name}.{m.disu.extension[0]}").is_file() # Load disu file disu2 = MfUsgDisU.load(fname, m) @@ -67,7 +68,7 @@ def test_usg_disu_load(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): @requires_exe("mfusg") -def test_usg_sms_load(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): +def test_usg_sms_load(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): fname = str(mfusg_01A_nestedgrid_nognc_model_path / "flow.sms") assert os.path.isfile(fname), f"sms file not found {fname}" @@ -79,11 +80,11 @@ def test_usg_sms_load(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): assert isinstance(sms, MfUsgSms) # Change where model files are written - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) # Write the sms file sms.write_file() - assert Path(tmpdir / f"{m.name}.{m.sms.extension[0]}").is_file() + assert Path(function_tmpdir / f"{m.name}.{m.sms.extension[0]}").is_file() # Load sms file sms2 = MfUsgSms.load(fname, m) @@ -96,11 +97,11 @@ def test_usg_sms_load(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): @requires_exe("mfusg") -def test_usg_model(tmpdir): +def test_usg_model(function_tmpdir): mf = MfUsg( version="mfusg", structured=True, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), modelname="simple", exe_name="mfusg", ) @@ -135,7 +136,7 @@ def test_usg_model(tmpdir): @requires_exe("mfusg") -def test_usg_load_01B(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): +def test_usg_load_01B(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): print( "testing 1-layer unstructured mfusg model " "loading: 01A_nestedgrid_nognc.nam" @@ -148,11 +149,11 @@ def test_usg_load_01B(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): m = MfUsg( modelname="usgload_1b", verbose=True, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) # Load the model, with checking - m = m.load(fname, check=True, model_ws=str(tmpdir)) + m = m.load(fname, check=True, model_ws=str(function_tmpdir)) # assert disu, lpf, bas packages have been loaded msg = "flopy failed on loading mfusg disu package" @@ -168,7 +169,7 @@ def test_usg_load_01B(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): @requires_exe("mfusg") -def test_usg_load_45usg(tmpdir, example_data_path): +def test_usg_load_45usg(function_tmpdir, example_data_path): print("testing 3-layer unstructured mfusg model loading: 45usg.nam") pthusgtest = str(example_data_path / "mfusg_test" / "45usg") @@ -176,10 +177,10 @@ def test_usg_load_45usg(tmpdir, example_data_path): assert os.path.isfile(fname), f"nam file not found {fname}" # Create the model - m = MfUsg(modelname="45usg", verbose=True, model_ws=str(tmpdir)) + m = MfUsg(modelname="45usg", verbose=True, model_ws=str(function_tmpdir)) # Load the model, with checking. - m = m.load(fname, check=True, model_ws=str(tmpdir)) + m = m.load(fname, check=True, model_ws=str(function_tmpdir)) # assert disu, lpf, bas packages have been loaded msg = "flopy failed on loading mfusg disu package" @@ -199,7 +200,7 @@ def test_usg_load_45usg(tmpdir, example_data_path): @requires_exe("mfusg") -def test_usg_rch_evt_models01(tmpdir, mfusg_rch_evt_model_path): +def test_usg_rch_evt_models01(function_tmpdir, mfusg_rch_evt_model_path): # this test has RCH nrchop == 1, and EVT nevtop == 1 print( "testing unstructured mfusg RCH nrchop == 1, and " @@ -212,14 +213,14 @@ def test_usg_rch_evt_models01(tmpdir, mfusg_rch_evt_model_path): ) m.riv.check() - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) m.write_input() success, buff = m.run_model() assert success @requires_exe("mfusg") -def test_usg_rch_evt_models02(tmpdir, mfusg_rch_evt_model_path): +def test_usg_rch_evt_models02(function_tmpdir, mfusg_rch_evt_model_path): # this test has RCH nrchop == 2, and EVT nevtop == 2 print( "testing unstructured mfusg RCH nrchop == 2, " @@ -231,14 +232,14 @@ def test_usg_rch_evt_models02(tmpdir, mfusg_rch_evt_model_path): nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" ) - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) m.write_input() success, buff = m.run_model() assert success @requires_exe("mfusg") -def test_usg_rch_evt_models02a(tmpdir, mfusg_rch_evt_model_path): +def test_usg_rch_evt_models02a(function_tmpdir, mfusg_rch_evt_model_path): # this test has RCH nrchop == 2, and EVT nevtop == 2 print( "testing unstructured mfusg RCH nrchop == 2, " @@ -251,14 +252,14 @@ def test_usg_rch_evt_models02a(tmpdir, mfusg_rch_evt_model_path): nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" ) - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) m.write_input() success, buff = m.run_model() assert success @requires_exe("mfusg") -def test_usg_ss_to_tr(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): +def test_usg_ss_to_tr(function_tmpdir, mfusg_01A_nestedgrid_nognc_model_path): # Test switching steady model to transient # https://github.com/modflowpy/flopy/issues/1187 @@ -269,19 +270,19 @@ def test_usg_ss_to_tr(tmpdir, mfusg_01A_nestedgrid_nognc_model_path): exe_name="mfusg", ) - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) m.disu.steady = [False] m.write_input() success, buff = m.run_model() assert success - m = MfUsg.load(nam, model_ws=str(tmpdir), exe_name="mfusg") + m = MfUsg.load(nam, model_ws=str(function_tmpdir), exe_name="mfusg") success, buff = m.run_model() assert success @requires_exe("mfusg") -def test_usg_str(tmpdir, mfusg_rch_evt_model_path): +def test_usg_str(function_tmpdir, mfusg_rch_evt_model_path): # test mfusg model with str package print("testing unstructured mfusg with STR: usg_rch_evt_str.nam") @@ -290,14 +291,14 @@ def test_usg_str(tmpdir, mfusg_rch_evt_model_path): nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" ) - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) m.write_input() success, buff = m.run_model() assert success @requires_exe("mfusg") -def test_usg_lak(tmpdir, mfusg_rch_evt_model_path): +def test_usg_lak(function_tmpdir, mfusg_rch_evt_model_path): # test mfusg model with lak package print("testing unstructured mfusg with LAK: usg_rch_evt_lak.nam") @@ -306,7 +307,7 @@ def test_usg_lak(tmpdir, mfusg_rch_evt_model_path): nam, model_ws=str(mfusg_rch_evt_model_path), exe_name="mfusg" ) - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) m.write_input() success, buff = m.run_model() assert success @@ -316,7 +317,7 @@ def test_usg_lak(tmpdir, mfusg_rch_evt_model_path): @flaky @requires_exe("mfusg") @pytest.mark.slow -def test_freyburg_usg(tmpdir, freyberg_usg_model_path): +def test_freyburg_usg(function_tmpdir, freyberg_usg_model_path): # test mfusg model with rch nrchop 3 / freyburg.usg print("testing usg nrchop 3: freyburg.usg.nam") @@ -325,7 +326,7 @@ def test_freyburg_usg(tmpdir, freyberg_usg_model_path): nam, model_ws=str(freyberg_usg_model_path), exe_name="mfusg" ) - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) m.write_input() success, buff = m.run_model() assert success @@ -335,7 +336,7 @@ def test_freyburg_usg(tmpdir, freyberg_usg_model_path): @flaky @requires_exe("mfusg") @pytest.mark.slow -def test_freyburg_usg_external(tmpdir, freyberg_usg_model_path): +def test_freyburg_usg_external(function_tmpdir, freyberg_usg_model_path): # test mfusg model after setting all files to external form print("testing usg external files: freyburg.usg.nam") @@ -344,7 +345,7 @@ def test_freyburg_usg_external(tmpdir, freyberg_usg_model_path): nam, model_ws=str(freyberg_usg_model_path), exe_name="mfusg" ) # convert to all open/close - ext_model_ws = str(tmpdir) + ext_model_ws = str(function_tmpdir) m.external_path = "." # reduce nper to speed this test up a bit m.disu.nper = 3 @@ -356,7 +357,7 @@ def test_freyburg_usg_external(tmpdir, freyberg_usg_model_path): @requires_exe("mfusg") -def test_flat_array_to_util3d_usg(tmpdir, freyberg_usg_model_path): +def test_flat_array_to_util3d_usg(function_tmpdir, freyberg_usg_model_path): # test mfusg model package constructor with flat arrays # for layer-based properties print("testing usg flat arrays to layer property constructor") @@ -379,7 +380,7 @@ def test_flat_array_to_util3d_usg(tmpdir, freyberg_usg_model_path): assert (lpf_new.hk[1][:2] == 999.9).all(), msg # ensure we can still write the lpf file - m.model_ws = str(tmpdir) + m.model_ws = str(function_tmpdir) m.write_input() @@ -389,7 +390,7 @@ def test_flat_array_to_util3d_usg(tmpdir, freyberg_usg_model_path): "fpth", [str(p) for p in (get_example_data_path() / "mfusg_test").rglob("*.nam")], ) -def test_load_usg(tmpdir, fpth): +def test_load_usg(function_tmpdir, fpth): namfile = Path(fpth) m = MfUsg.load( @@ -401,5 +402,5 @@ def test_load_usg(tmpdir, fpth): assert m, f"Could not load namefile {namfile}" assert m.load_fail is False - m.change_model_ws(str(tmpdir)) + m.change_model_ws(str(function_tmpdir)) m.write_input() diff --git a/autotest/test_util_2d_and_3d.py b/autotest/test_util_2d_and_3d.py index c24003b486..105ca77bab 100644 --- a/autotest/test_util_2d_and_3d.py +++ b/autotest/test_util_2d_and_3d.py @@ -2,7 +2,7 @@ import numpy as np import pytest -from autotest.conftest import requires_pkg +from modflow_devtools.markers import requires_pkg from flopy.modflow import ( Modflow, @@ -72,16 +72,16 @@ def test_transient3d(): assert itmp == -1 -def test_util2d(tmpdir): - ml = Modflow(model_ws=str(tmpdir)) +def test_util2d(function_tmpdir): + ml = Modflow(model_ws=str(function_tmpdir)) u2d = Util2d(ml, (10, 10), np.float32, 10.0, "test") a1 = u2d.array a2 = np.ones((10, 10), dtype=np.float32) * 10.0 assert np.array_equal(a1, a2) # test external filenames - ascii and binary - ascii = tmpdir / "test_a.dat" - bin = tmpdir / "test_b.dat" + ascii = function_tmpdir / "test_a.dat" + bin = function_tmpdir / "test_b.dat" np.savetxt(str(ascii), a1, fmt="%15.6E") u2d.write_bin(a1.shape, str(bin), a1, bintype="head") dis = ModflowDis(ml, 2, 10, 10) @@ -91,10 +91,13 @@ def test_util2d(tmpdir): assert np.array_equal(lpf.hk[1].array, a1) # test external filenames - ascii and binary with model_ws and external_path - ml = Modflow(model_ws=str(tmpdir), external_path=str(tmpdir / "ref")) + ml = Modflow( + model_ws=str(function_tmpdir), + external_path=str(function_tmpdir / "ref"), + ) u2d = Util2d(ml, (10, 10), np.float32, 10.0, "test") - ascii = tmpdir / "test_a.dat" - bin = tmpdir / "test_b.dat" + ascii = function_tmpdir / "test_a.dat" + bin = function_tmpdir / "test_b.dat" np.savetxt(str(ascii), a1, fmt="%15.6E") u2d.write_bin(a1.shape, str(bin), a1, bintype="head") dis = ModflowDis(ml, 2, 10, 10) @@ -104,13 +107,13 @@ def test_util2d(tmpdir): assert np.array_equal(lpf.hk[1].array, a1) # bin read write test - bin = tmpdir / "test.bin" + bin = function_tmpdir / "test.bin" u2d.write_bin((10, 10), str(bin), u2d.array) a3 = u2d.load_bin((10, 10), str(bin), u2d.dtype)[1] assert np.array_equal(a3, a1) # ascii read write test - ascii = tmpdir / "text.dat" + ascii = function_tmpdir / "text.dat" u2d.write_txt((10, 10), str(ascii), u2d.array) a4 = u2d.load_txt((10, 10), str(ascii), u2d.dtype, "(FREE)") assert np.array_equal(a1, a4) @@ -252,8 +255,8 @@ def stress_util2d_for_joe_the_file_king(ml, nlay, nrow, ncol): assert np.array_equal(ml.lpf.hk.array, ml1.lpf.hk.array) -def test_util2d_external_free(tmpdir): - ws = str(tmpdir) +def test_util2d_external_free(function_tmpdir): + ws = str(function_tmpdir) ml = Modflow(model_ws=ws) stress_util2d(ws, ml, 1, 1, 1) stress_util2d(ws, ml, 10, 1, 1) @@ -265,8 +268,8 @@ def test_util2d_external_free(tmpdir): stress_util2d(ws, ml, 10, 10, 10) -def test_util2d_external_free_path(tmpdir): - ws = str(tmpdir) +def test_util2d_external_free_path(function_tmpdir): + ws = str(function_tmpdir) ml = Modflow(model_ws=ws, external_path="ref") stress_util2d(ws, ml, 1, 1, 1) @@ -279,8 +282,8 @@ def test_util2d_external_free_path(tmpdir): stress_util2d(ws, ml, 10, 10, 10) -def test_util2d_external_free_path_a(tmpdir): - ml = Modflow(model_ws=str(tmpdir), external_path="ref") +def test_util2d_external_free_path_a(function_tmpdir): + ml = Modflow(model_ws=str(function_tmpdir), external_path="ref") stress_util2d_for_joe_the_file_king(ml, 1, 1, 1) stress_util2d_for_joe_the_file_king(ml, 10, 1, 1) @@ -292,8 +295,8 @@ def test_util2d_external_free_path_a(tmpdir): stress_util2d_for_joe_the_file_king(ml, 10, 10, 10) -def test_util2d_external_fixed(tmpdir): - ws = str(tmpdir) +def test_util2d_external_fixed(function_tmpdir): + ws = str(function_tmpdir) ml = Modflow(model_ws=ws) ml.array_free_format = False @@ -308,8 +311,8 @@ def test_util2d_external_fixed(tmpdir): @pytest.mark.slow -def test_util2d_external_fixed_path(tmpdir): - ws = str(tmpdir) +def test_util2d_external_fixed_path(function_tmpdir): + ws = str(function_tmpdir) ml = Modflow(model_ws=ws, external_path="ref") ml.array_free_format = False @@ -323,8 +326,8 @@ def test_util2d_external_fixed_path(tmpdir): stress_util2d(ws, ml, 10, 10, 10) -def test_util3d(tmpdir): - ml = Modflow(model_ws=str(tmpdir)) +def test_util3d(function_tmpdir): + ml = Modflow(model_ws=str(function_tmpdir)) u3d = Util3d(ml, (10, 10, 10), np.float32, 10.0, "test") a1 = u3d.array a2 = np.ones((10, 10, 10), dtype=np.float32) * 10.0 @@ -343,8 +346,8 @@ def test_util3d(tmpdir): return -def test_arrayformat(tmpdir): - ml = Modflow(model_ws=str(tmpdir)) +def test_arrayformat(function_tmpdir): + ml = Modflow(model_ws=str(function_tmpdir)) u2d = Util2d(ml, (15, 2), np.float32, np.ones((15, 2)), "test") fmt_fort = u2d.format.fortran @@ -398,8 +401,8 @@ def test_arrayformat(tmpdir): assert fmt_fort.upper() == parsed["fmtin"].upper() -def test_new_get_file_entry(tmpdir): - ml = Modflow(model_ws=str(tmpdir)) +def test_new_get_file_entry(function_tmpdir): + ml = Modflow(model_ws=str(function_tmpdir)) u2d = Util2d(ml, (5, 2), np.float32, np.ones((5, 2)), "test", locat=99) print(u2d.get_file_entry(how="internal")) print(u2d.get_file_entry(how="constant")) @@ -420,8 +423,8 @@ def test_new_get_file_entry(tmpdir): print(u2d.get_file_entry(how="external")) -def test_append_mflist(tmpdir): - ml = Modflow(model_ws=str(tmpdir)) +def test_append_mflist(function_tmpdir): + ml = Modflow(model_ws=str(function_tmpdir)) dis = ModflowDis(ml, 10, 10, 10, 10) sp_data1 = {3: [1, 1, 1, 1.0], 5: [1, 2, 4, 4.0]} sp_data2 = {0: [1, 1, 3, 3.0], 8: [9, 2, 4, 4.0]} @@ -437,8 +440,8 @@ def test_append_mflist(tmpdir): @requires_pkg("pandas") -def test_mflist(tmpdir, example_data_path): - model = Modflow(model_ws=str(tmpdir)) +def test_mflist(function_tmpdir, example_data_path): + model = Modflow(model_ws=str(function_tmpdir)) dis = ModflowDis(model, 10, 10, 10, 10) sp_data = { 0: [[1, 1, 1, 1.0], [1, 1, 2, 2.0], [1, 1, 3, 3.0]], @@ -583,8 +586,8 @@ def test_mflist(tmpdir, example_data_path): assert df.groupby(["k", "i", "j"])["rbot"].count()[(1, 2, 4)] == 10 -def test_how(tmpdir): - ml = Modflow(model_ws=str(tmpdir)) +def test_how(function_tmpdir): + ml = Modflow(model_ws=str(function_tmpdir)) ml.array_free_format = False dis = ModflowDis(ml, nlay=2, nrow=10, ncol=10) @@ -607,7 +610,7 @@ def test_util3d_reset(): @requires_pkg("pandas") -def test_mflist_fromfile(tmpdir): +def test_mflist_fromfile(function_tmpdir): """test that when a file is passed to stress period data, the .array attribute will load the file """ @@ -616,7 +619,7 @@ def test_mflist_fromfile(tmpdir): wel_data = pd.DataFrame( [(0, 1, 2, -50.0), (0, 5, 5, -50.0)], columns=["k", "i", "j", "flux"] ) - wpth = os.path.join(tmpdir, "wel_000.dat") + wpth = os.path.join(function_tmpdir, "wel_000.dat") wel_data.to_csv( wpth, index=False, @@ -627,7 +630,7 @@ def test_mflist_fromfile(tmpdir): nwt_model = Modflow( "nwt_testmodel", verbose=True, - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) dis = ModflowDis( nwt_model, diff --git a/autotest/test_util_array.py b/autotest/test_util_array.py index 09a1dc2c50..b8d4539119 100644 --- a/autotest/test_util_array.py +++ b/autotest/test_util_array.py @@ -136,10 +136,10 @@ def test_load_block(): assert fa.dtype == a.dtype -def test_load_bin(tmpdir): +def test_load_bin(function_tmpdir): def temp_file(data): # writable file that is destroyed as soon as it is closed - f = TemporaryFile(dir=tmpdir) + f = TemporaryFile(dir=function_tmpdir) f.write(data) f.seek(0) return f diff --git a/autotest/test_uzf.py b/autotest/test_uzf.py index 830556d32d..ca4e0295a7 100644 --- a/autotest/test_uzf.py +++ b/autotest/test_uzf.py @@ -4,7 +4,7 @@ import numpy as np import pytest -from autotest.conftest import requires_exe +from modflow_devtools.markers import requires_exe from flopy.modflow import ( Modflow, @@ -36,9 +36,9 @@ def options_path(example_data_path): return example_data_path / "options" -def test_create_uzf(tmpdir, mf2005_test_path, uzf_test_path): +def test_create_uzf(function_tmpdir, mf2005_test_path, uzf_test_path): # copy the test files - ws = str(tmpdir) + ws = str(function_tmpdir) for f in mf2005_test_path.glob("UZFtest2.*"): shutil.copy(f, ws) @@ -243,7 +243,7 @@ def test_create_uzf(tmpdir, mf2005_test_path, uzf_test_path): @requires_exe("mfnwt") -def test_uzf_surfk(tmpdir, uzf_test_path): +def test_uzf_surfk(function_tmpdir, uzf_test_path): ws = str(uzf_test_path) uzf_name = "UZFtest4.uzf" dis_name = "UZFtest2.dis" @@ -254,23 +254,25 @@ def test_uzf_surfk(tmpdir, uzf_test_path): assert uzf.options.seepsurfk assert abs(np.unique(uzf.surfk.array)[0] - 0.099) < 1e-06 - ml.change_model_ws(str(tmpdir)) + ml.change_model_ws(str(function_tmpdir)) dis.write_file() uzf.write_file() ml2 = Modflow(version="mfnwt") dis2 = ModflowDis.load( - os.path.join(str(tmpdir), "UZFtest4.dis"), ml2, ext_unit_dict={} + os.path.join(str(function_tmpdir), "UZFtest4.dis"), + ml2, + ext_unit_dict={}, ) uzf2 = ModflowUzf1.load( - os.path.join(str(tmpdir), uzf_name), ml2, ext_unit_dict={} + os.path.join(str(function_tmpdir), uzf_name), ml2, ext_unit_dict={} ) assert uzf2.options.seepsurfk assert np.allclose(uzf.surfk.array, uzf2.surfk.array) -def test_read_write_nwt_options(tmpdir): +def test_read_write_nwt_options(function_tmpdir): welstr = "OPTIONS\nSPECIFY 0.5 10\nTABFILES 2 28\nEND\n" welstr2 = "OPTIONS\nSPECIFY 0.3\nTABFILES 2 28\nEND\n" uzfstr = ( @@ -293,7 +295,7 @@ def test_read_write_nwt_options(tmpdir): assert repr(uzfopt) == uzfstr assert repr(sfropt) == sfrstr - ws = str(tmpdir) + ws = str(function_tmpdir) welopt.write_options(os.path.join(ws, "welopt.txt")) welopt2.write_options(os.path.join(ws, "welopt2.txt")) uzfopt.write_options(os.path.join(ws, "uzfopt.txt")) @@ -318,7 +320,7 @@ def test_read_write_nwt_options(tmpdir): assert repr(sfropt) == sfrstr -def test_load_write_sfr_option_block(tmpdir, options_path): +def test_load_write_sfr_option_block(function_tmpdir, options_path): data_path = str(options_path) sfr_name = "sagehen_ob.sfr" @@ -336,11 +338,14 @@ def test_load_write_sfr_option_block(tmpdir, options_path): ) sfr_name2 = "sagehen_ob2.sfr" - sfr.write_file(filename=os.path.join(str(tmpdir), sfr_name2)) + sfr.write_file(filename=os.path.join(str(function_tmpdir), sfr_name2)) ml.remove_package("SFR") sfr2 = ModflowSfr2.load( - os.path.join(str(tmpdir), sfr_name2), ml, nper=2, ext_unit_dict={} + os.path.join(str(function_tmpdir), sfr_name2), + ml, + nper=2, + ext_unit_dict={}, ) assert sfr.options.reachinput == sfr2.options.reachinput @@ -354,18 +359,21 @@ def test_load_write_sfr_option_block(tmpdir, options_path): sfr2.options.strhc1kh = False sfr2.options.strhc1kv = False - sfr2.write_file(os.path.join(str(tmpdir), sfr_name2)) + sfr2.write_file(os.path.join(str(function_tmpdir), sfr_name2)) ml.remove_package("SFR") sfr3 = ModflowSfr2.load( - os.path.join(str(tmpdir), sfr_name2), ml, nper=2, ext_unit_dict={} + os.path.join(str(function_tmpdir), sfr_name2), + ml, + nper=2, + ext_unit_dict={}, ) assert sfr3.options.strhc1kh == False assert sfr3.options.strhc1kv == False -def test_load_write_sfr_option_line(tmpdir, options_path): +def test_load_write_sfr_option_line(function_tmpdir, options_path): data_path = str(options_path) sfr_name = "sagehen.sfr" @@ -384,11 +392,14 @@ def test_load_write_sfr_option_line(tmpdir, options_path): ) sfr_name2 = "sagehen2.sfr" - sfr.write_file(os.path.join(str(tmpdir), sfr_name2)) + sfr.write_file(os.path.join(str(function_tmpdir), sfr_name2)) ml.remove_package("SFR") sfr2 = ModflowSfr2.load( - os.path.join(str(tmpdir), sfr_name2), ml, nper=2, ext_unit_dict={} + os.path.join(str(function_tmpdir), sfr_name2), + ml, + nper=2, + ext_unit_dict={}, ) assert sfr2.reachinput @@ -411,17 +422,20 @@ def test_load_write_sfr_option_line(tmpdir, options_path): ) sfr_name2 = "sagehen2.sfr" - sfr.write_file(os.path.join(str(tmpdir), sfr_name2)) + sfr.write_file(os.path.join(str(function_tmpdir), sfr_name2)) ml.remove_package("SFR") sfr2 = ModflowSfr2.load( - os.path.join(str(tmpdir), sfr_name2), ml, nper=2, ext_unit_dict={} + os.path.join(str(function_tmpdir), sfr_name2), + ml, + nper=2, + ext_unit_dict={}, ) assert sfr2.reachinput -def test_load_write_uzf_option_block(tmpdir, options_path): +def test_load_write_uzf_option_block(function_tmpdir, options_path): data_path = str(options_path) uzf_name = "sagehen_ob.uzf" @@ -439,11 +453,11 @@ def test_load_write_uzf_option_block(tmpdir, options_path): ) uzf_name2 = "sagehen_ob2.uzf" - uzf.write_file(os.path.join(str(tmpdir), uzf_name2)) + uzf.write_file(os.path.join(str(function_tmpdir), uzf_name2)) ml.remove_package("UZF") uzf2 = ModflowUzf1.load( - os.path.join(str(tmpdir), uzf_name2), + os.path.join(str(function_tmpdir), uzf_name2), ml, ext_unit_dict=None, check=False, @@ -456,11 +470,11 @@ def test_load_write_uzf_option_block(tmpdir, options_path): uzf2.smoothfact = 0.4 - uzf2.write_file(os.path.join(str(tmpdir), uzf_name2)) + uzf2.write_file(os.path.join(str(function_tmpdir), uzf_name2)) ml.remove_package("UZF") uzf3 = ModflowUzf1.load( - os.path.join(str(tmpdir), uzf_name2), ml, check=False + os.path.join(str(function_tmpdir), uzf_name2), ml, check=False ) assert uzf3.options.smoothfact == 0.4 @@ -468,7 +482,7 @@ def test_load_write_uzf_option_block(tmpdir, options_path): ml.remove_package("UZF") -def test_load_write_uzf_option_line(tmpdir, options_path): +def test_load_write_uzf_option_line(function_tmpdir, options_path): data_path = str(options_path) uzf_name = "sagehen.uzf" @@ -490,11 +504,11 @@ def test_load_write_uzf_option_line(tmpdir, options_path): assert uzf.options.savefinf uzf_name2 = "sagehen2.uzf" - uzf.write_file(os.path.join(str(tmpdir), uzf_name2)) + uzf.write_file(os.path.join(str(function_tmpdir), uzf_name2)) ml.remove_package("UZF") uzf2 = ModflowUzf1.load( - os.path.join(str(tmpdir), uzf_name2), ml, check=False + os.path.join(str(function_tmpdir), uzf_name2), ml, check=False ) assert uzf2.nosurfleak @@ -504,7 +518,7 @@ def test_load_write_uzf_option_line(tmpdir, options_path): assert not uzf2.options.block -def test_load_write_wel_option_block(tmpdir, options_path): +def test_load_write_wel_option_block(function_tmpdir, options_path): ws = str(options_path) wel_name = "sagehen_ob.wel" ml = Modflow(modelname="optionblock", version="mfnwt", verbose=False) @@ -514,11 +528,11 @@ def test_load_write_wel_option_block(tmpdir, options_path): ) wel_name2 = "sagehen_ob2.wel" - wel.write_file(os.path.join(str(tmpdir), wel_name2)) + wel.write_file(os.path.join(str(function_tmpdir), wel_name2)) ml.remove_package("WEL") wel2 = ModflowWel.load( - os.path.join(str(tmpdir), wel_name2), + os.path.join(str(function_tmpdir), wel_name2), ml, nper=2, ext_unit_dict={}, @@ -532,11 +546,11 @@ def test_load_write_wel_option_block(tmpdir, options_path): wel2.options.tabfiles = False wel2.phiramp = 0.4 - wel2.write_file(os.path.join(str(tmpdir), wel_name2)) + wel2.write_file(os.path.join(str(function_tmpdir), wel_name2)) ml.remove_package("WEL") wel3 = ModflowWel.load( - os.path.join(str(tmpdir), wel_name2), + os.path.join(str(function_tmpdir), wel_name2), ml, nper=2, ext_unit_dict={}, @@ -548,7 +562,7 @@ def test_load_write_wel_option_block(tmpdir, options_path): assert wel3.options.noprint -def test_load_write_wel_option_line(tmpdir, options_path): +def test_load_write_wel_option_line(function_tmpdir, options_path): ws = str(options_path) wel_name = "sagehen.wel" @@ -566,11 +580,11 @@ def test_load_write_wel_option_line(tmpdir, options_path): wel.iunitramp = 20 wel_name2 = "sagehen2.wel" - wel.write_file(os.path.join(str(tmpdir), wel_name2)) + wel.write_file(os.path.join(str(function_tmpdir), wel_name2)) ml.remove_package("WEL") wel2 = ModflowWel.load( - os.path.join(str(tmpdir), wel_name2), + os.path.join(str(function_tmpdir), wel_name2), ml, nper=2, ext_unit_dict={}, @@ -584,12 +598,12 @@ def test_load_write_wel_option_line(tmpdir, options_path): @requires_exe("mfnwt") -def test_uzf_negative_iuzfopt(tmpdir): +def test_uzf_negative_iuzfopt(function_tmpdir): ml = Modflow( modelname="uzf_neg", version="mfnwt", exe_name="mfnwt", - model_ws=str(tmpdir), + model_ws=str(function_tmpdir), ) dis = ModflowDis( ml, @@ -632,7 +646,9 @@ def test_uzf_negative_iuzfopt(tmpdir): if not success: raise AssertionError("UZF model with -1 iuzfopt failed to run") - ml2 = Modflow.load("uzf_neg.nam", version="mfnwt", model_ws=str(tmpdir)) + ml2 = Modflow.load( + "uzf_neg.nam", version="mfnwt", model_ws=str(function_tmpdir) + ) pet = ml2.uzf.pet.array extpd = ml2.uzf.pet.array diff --git a/autotest/test_zonbud_utility.py b/autotest/test_zonbud_utility.py index 8a99eddd80..b2495b01bc 100644 --- a/autotest/test_zonbud_utility.py +++ b/autotest/test_zonbud_utility.py @@ -2,7 +2,7 @@ import numpy as np import pytest -from autotest.conftest import requires_exe, requires_pkg +from modflow_devtools.markers import requires_exe, requires_pkg from flopy.mf6 import MFSimulation from flopy.utils import ZoneBudget, ZoneBudget6, ZoneFile6 @@ -159,13 +159,13 @@ def test_zonbud_aliases(cbc_f, zon_f): assert bud[bud["name"] == "FROM_Mike"].shape[0] > 0, "No records returned." -def test_zonbud_to_csv(tmpdir, cbc_f, zon_f): +def test_zonbud_to_csv(function_tmpdir, cbc_f, zon_f): """ t039 Test zonbud export to csv file method """ zon = ZoneBudget.read_zone_file(str(zon_f)) zb = ZoneBudget(str(cbc_f), zon, kstpkper=[(0, 1094), (0, 1096)]) - f_out = os.path.join(str(tmpdir), "test.csv") + f_out = os.path.join(str(function_tmpdir), "test.csv") zb.to_csv(f_out) with open(f_out, "r") as f: lines = f.readlines() @@ -194,16 +194,20 @@ def test_zonbud_copy(cbc_f, zon_f): assert cfd is not cfd2, "Copied object is a shallow copy." -def test_zonbud_readwrite_zbarray(tmpdir): +def test_zonbud_readwrite_zbarray(function_tmpdir): """ t039 Test zonbud read write """ x = np.random.randint(100, 200, size=(5, 150, 200)) - ZoneBudget.write_zone_file(os.path.join(str(tmpdir), "randint"), x) ZoneBudget.write_zone_file( - os.path.join(str(tmpdir), "randint"), x, fmtin=35, iprn=2 + os.path.join(str(function_tmpdir), "randint"), x + ) + ZoneBudget.write_zone_file( + os.path.join(str(function_tmpdir), "randint"), x, fmtin=35, iprn=2 + ) + z = ZoneBudget.read_zone_file( + os.path.join(str(function_tmpdir), "randint") ) - z = ZoneBudget.read_zone_file(os.path.join(str(tmpdir), "randint")) assert np.array_equal(x, z), "Input and output arrays do not match." @@ -263,7 +267,7 @@ def test_zonbud_active_areas_zone_zero(loadpth, cbc_f, rtol): assert allclose, s -def test_read_zone_file(tmpdir): +def test_read_zone_file(function_tmpdir): zf = ( "2 2 4\n" "INTERNAL (4I3)\n" @@ -274,7 +278,7 @@ def test_read_zone_file(tmpdir): " 0 1 1 1\n" " 0" ) - name = os.path.join(str(tmpdir), "zonefiletest.txt") + name = os.path.join(str(function_tmpdir), "zonefiletest.txt") with open(name, "w") as foo: foo.write(zf) zones = ZoneBudget.read_zone_file(name) @@ -285,7 +289,7 @@ def test_read_zone_file(tmpdir): @pytest.mark.mf6 @requires_exe("mf6") @requires_pkg("pandas") -def test_zonebudget_6(tmpdir, example_data_path): +def test_zonebudget_6(function_tmpdir, example_data_path): import pandas as pd exe_name = "mf6" @@ -293,17 +297,17 @@ def test_zonebudget_6(tmpdir, example_data_path): sim_ws = example_data_path / "mf6" / "test001e_UZF_3lay" sim = MFSimulation.load(sim_ws=str(sim_ws), exe_name=exe_name) - sim.simulation_data.mfpath.set_sim_path(str(tmpdir)) + sim.simulation_data.mfpath.set_sim_path(str(function_tmpdir)) sim.write_simulation() success, _ = sim.run_simulation() - grb_file = os.path.join(str(tmpdir), "test001e_UZF_3lay.dis.grb") - cbc_file = os.path.join(str(tmpdir), "test001e_UZF_3lay.cbc") + grb_file = os.path.join(str(function_tmpdir), "test001e_UZF_3lay.dis.grb") + cbc_file = os.path.join(str(function_tmpdir), "test001e_UZF_3lay.cbc") ml = sim.get_model("gwf_1") idomain = np.ones(ml.modelgrid.shape, dtype=int) - zb = ZoneBudget6(model_ws=str(tmpdir), exe_name=zb_exe_name) + zb = ZoneBudget6(model_ws=str(function_tmpdir), exe_name=zb_exe_name) zf = ZoneFile6(zb, idomain) zb.grb = grb_file zb.cbc = cbc_file @@ -317,7 +321,7 @@ def test_zonebudget_6(tmpdir, example_data_path): assert isinstance(df, pd.DataFrame) zb_pkg = ml.uzf.output.zonebudget(idomain) - zb_pkg.change_model_ws(str(tmpdir)) + zb_pkg.change_model_ws(str(function_tmpdir)) zb_pkg.name = "uzf_zonebud" zb_pkg.write_input() success, _ = zb_pkg.run_model(exe_name=zb_exe_name) @@ -329,7 +333,7 @@ def test_zonebudget_6(tmpdir, example_data_path): assert isinstance(df, pd.DataFrame) # test aliases - zb = ZoneBudget6(model_ws=str(tmpdir), exe_name=zb_exe_name) + zb = ZoneBudget6(model_ws=str(function_tmpdir), exe_name=zb_exe_name) zf = ZoneFile6(zb, idomain, aliases={1: "test alias", 2: "test pop"}) zb.grb = grb_file zb.cbc = cbc_file @@ -345,13 +349,13 @@ def test_zonebudget_6(tmpdir, example_data_path): @pytest.mark.mf6 @requires_exe("mf6") -def test_zonebudget6_from_output_method(tmpdir, example_data_path): +def test_zonebudget6_from_output_method(function_tmpdir, example_data_path): exe_name = "mf6" zb_exe_name = "zbud6" sim_ws = example_data_path / "mf6" / "test001e_UZF_3lay" sim = MFSimulation.load(sim_ws=str(sim_ws), exe_name=exe_name) - sim.simulation_data.mfpath.set_sim_path(str(tmpdir)) + sim.simulation_data.mfpath.set_sim_path(str(function_tmpdir)) sim.write_simulation() success, _ = sim.run_simulation() diff --git a/etc/environment.yml b/etc/environment.yml index d2faaaaef7..2d33896914 100644 --- a/etc/environment.yml +++ b/etc/environment.yml @@ -19,6 +19,8 @@ dependencies: - filelock - jupyter - jupytext + - pip: + - git+https://github.com/MODFLOW-USGS/modflow-devtools.git - pytest - pytest-cases - pytest-cov diff --git a/flopy/utils/mfreadnam.py b/flopy/utils/mfreadnam.py index 433c223c95..52d54ba111 100644 --- a/flopy/utils/mfreadnam.py +++ b/flopy/utils/mfreadnam.py @@ -10,7 +10,7 @@ import os from os import PathLike from pathlib import Path, PurePosixPath, PureWindowsPath -from typing import Tuple, List +from typing import List, Tuple class NamData: @@ -271,7 +271,9 @@ def attribs_from_namfile_header(namefile): return defaults -def get_entries_from_namefile(path: PathLike, ftype: str = None, unit: int = None, extension: str = None) -> List[Tuple]: +def get_entries_from_namefile( + path: PathLike, ftype: str = None, unit: int = None, extension: str = None +) -> List[Tuple]: """Get entries from an MF6 namefile. Can select using FTYPE, UNIT, or file extension. This function only supports MF6 namefiles. diff --git a/setup.cfg b/setup.cfg index 17b9ab8ab8..03d22cb432 100644 --- a/setup.cfg +++ b/setup.cfg @@ -60,10 +60,12 @@ test = jupyter jupytext mfpymake + modflow-devtools pytest pytest-benchmark pytest-cases pytest-cov + pytest-dotenv pytest-xdist optional = affine