Skip to content

Commit

Permalink
Merge branch 'modflowpy:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
spaulins-usgs committed Sep 12, 2022
2 parents b1e466b + af42e78 commit 2c748b4
Show file tree
Hide file tree
Showing 36 changed files with 2,553 additions and 1,219 deletions.
25 changes: 25 additions & 0 deletions autotest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from urllib import request
from warnings import warn

import matplotlib.pyplot as plt
import pkg_resources
import pytest

Expand Down Expand Up @@ -337,6 +338,22 @@ def session_tmpdir(tmpdir_factory, request) -> Path:
copytree(temp, Path(keep) / temp.name)


# fixture to automatically close any plots (or optionally show them)


@pytest.fixture(autouse=True)
def close_plot(request):
yield

# plots only shown if requested via CLI flag,
# figures are available, and we're not in CI
show = request.config.getoption("--show-plots")
if len(plt.get_fignums()) > 0 and not is_in_ci() and show:
plt.show()
else:
plt.close("all")


# pytest configuration hooks


Expand Down Expand Up @@ -392,6 +409,14 @@ def pytest_addoption(parser):
help="Run only smoke tests (should complete in <1 minute).",
)

parser.addoption(
"--show-plots",
action="store_true",
default=False,
help="Show any figure windows created by test cases. (Useful to display plots for visual inspection, "
"but automated tests should probably also check patch collections or figure & axis properties.)",
)


def pytest_configure(config):
config.addinivalue_line(
Expand Down
3 changes: 2 additions & 1 deletion autotest/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ markers =
slow: tests that don't complete in a few seconds
example: exercise scripts, tutorials and notebooks
regression: tests that compare multiple results
meta: run by other tests (e.g. testing fixtures)
meta: run by other tests (e.g. testing fixtures)
mf6: tests for the mf6 module
2 changes: 2 additions & 0 deletions autotest/regression/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
from flopy.utils import CellBudgetFile
from flopy.utils.datautil import PyListUtil

pytestmark = pytest.mark.mf6


@requires_exe("mf6")
@requires_pkg("pymake")
Expand Down
18 changes: 9 additions & 9 deletions autotest/regression/test_mf6_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

from flopy.mf6 import MFSimulation

pytestmark = pytest.mark.mf6


@requires_exe("mf6")
@requires_pkg("pymake")
@pytest.mark.slow
@pytest.mark.regression
def test_mf6_example_simulations(tmpdir, mf6_example_namfiles):
"""
MF6 examples parametrized by simulation. Arg `mf6_example_namfiles` is a list
of models to run in order provided. Coupled models share the same workspace.
Parameters
----------
tmpdir: function-scoped temporary directory fixture
mf6_example_namfiles: ordered list of namfiles for 1+ coupled models
"""
# 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
# mf6_example_namfiles: ordered list of namfiles for 1+ coupled models

import pymake

Expand Down
2 changes: 2 additions & 0 deletions autotest/test_binarygrid_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from flopy.discretization import StructuredGrid, UnstructuredGrid, VertexGrid
from flopy.mf6.utils import MfGrdFile

pytestmark = pytest.mark.mf6


@pytest.fixture(scope="module")
def mfgrd_test_path(example_data_path):
Expand Down
2 changes: 2 additions & 0 deletions autotest/test_cbc_full3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def load_mf2005(path, ws_out):
return ml


@pytest.mark.mf6
def load_mf6(path, ws_out):
sim = MFSimulation.load(
sim_name=Path(path).name,
Expand Down Expand Up @@ -118,6 +119,7 @@ def cbc_eval(cbcobj, nnodes, shape3d, modelgrid):
cobj_mg.close()


@pytest.mark.mf6
@pytest.mark.parametrize("path", mf6_paths)
def test_cbc_full3D_mf6(tmpdir, path):
sim = load_mf6(path, str(tmpdir))
Expand Down
2 changes: 2 additions & 0 deletions autotest/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import inspect

import numpy as np
import pytest

from flopy.datbase import DataInterface, DataType
from flopy.mbase import ModelInterface
Expand Down Expand Up @@ -226,6 +227,7 @@ def test_mf2005_copy(example_data_path):
assert not model_is_copy(m, m_c)


@pytest.mark.mf6
def test_mf6_copy(example_data_path):
sim = MFSimulation.load(
"mfsim.nam",
Expand Down
38 changes: 37 additions & 1 deletion autotest/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import matplotlib.pyplot as plt
import numpy as np
import pytest
from flaky import flaky
from autotest.conftest import (
SHAPEFILE_EXTENSIONS,
get_example_data_path,
Expand All @@ -16,6 +15,7 @@
requires_pkg,
requires_spatial_reference,
)
from flaky import flaky

import flopy
from flopy.discretization import StructuredGrid, UnstructuredGrid
Expand All @@ -29,6 +29,7 @@
export_array,
export_array_contours,
export_contourf,
export_contours,
)
from flopy.export.vtk import Vtk
from flopy.mf6 import (
Expand Down Expand Up @@ -615,6 +616,35 @@ def test_export_contourf(tmpdir, example_data_path):
)


@pytest.mark.mf6
@requires_pkg("shapefile", "shapely")
def test_export_contours(tmpdir, example_data_path):
from shapefile import Reader

filename = os.path.join(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")
hds = flopy.utils.HeadFile(hds_pth)
head = hds.get_data()
levels = np.arange(10, 30, 0.5)

mapview = flopy.plot.PlotMapView(model=ml)
contour_set = mapview.contour_array(
head, masked_values=[999.0], levels=levels
)

export_contours(filename, contour_set)
plt.close()
if not os.path.isfile(filename):
raise AssertionError("did not create contour shapefile")

with Reader(filename) as r:
shapes = r.shapes()
assert len(shapes) == 65


@pytest.mark.mf6
@requires_pkg("shapely")
def test_mf6_grid_shp_export(tmpdir):
nlay = 2
Expand Down Expand Up @@ -1082,6 +1112,7 @@ def test_vtk_export_packages(tmpdir, example_data_path):
assert os.path.exists(filetocheck)


@pytest.mark.mf6
@requires_pkg("vtk")
def test_vtk_mf6(tmpdir, example_data_path):
# test mf6
Expand Down Expand Up @@ -1344,6 +1375,7 @@ def load_iverts(fname):
assert np.allclose(np.ravel(top), top2), "Field data not properly written"


@pytest.mark.mf6
@requires_pkg("vtk")
def test_vtk_vertex(tmpdir, example_data_path):
from vtkmodules.util.numpy_support import vtk_to_numpy
Expand Down Expand Up @@ -1502,6 +1534,7 @@ def load_iverts(fname, closed=False):
return iverts, np.array(xc), np.array(yc)


@pytest.mark.mf6
@requires_pkg("vtk")
def test_vtk_export_model_without_packages_names(tmpdir):
from vtkmodules.util.numpy_support import vtk_to_numpy
Expand Down Expand Up @@ -1559,6 +1592,7 @@ def test_vtk_export_model_without_packages_names(tmpdir):
assert np.allclose(cell_types, cell_types_answer), errmsg


@pytest.mark.mf6
@requires_pkg("vtk")
def test_vtk_export_disv1_model(tmpdir):
from vtkmodules.util.numpy_support import vtk_to_numpy
Expand Down Expand Up @@ -1631,6 +1665,7 @@ def test_vtk_export_disv1_model(tmpdir):
assert np.allclose(cell_types, cell_types_answer), errmsg


@pytest.mark.mf6
@requires_pkg("vtk")
def test_vtk_export_disv2_model(tmpdir):
from vtkmodules.util.numpy_support import vtk_to_numpy
Expand Down Expand Up @@ -1868,6 +1903,7 @@ def test_vtk_export_disu2_grid(tmpdir, example_data_path):
assert np.allclose(cell_types, cell_types_answer), errmsg


@pytest.mark.mf6
@requires_pkg("vtk", "shapefile")
def test_vtk_export_disu_model(tmpdir):
from vtkmodules.util.numpy_support import vtk_to_numpy
Expand Down
1 change: 1 addition & 0 deletions autotest/test_generate_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from flopy.mf6.utils import generate_classes


@pytest.mark.mf6
@pytest.mark.skip(
reason="TODO: use external copy of the repo, otherwise files are rewritten"
)
Expand Down
Loading

0 comments on commit 2c748b4

Please sign in to comment.