Skip to content

Commit

Permalink
test: split plot tests into more narrowly-scoped files (#1949)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli authored Sep 22, 2023
1 parent 06eefd7 commit 1aa2c45
Show file tree
Hide file tree
Showing 7 changed files with 789 additions and 737 deletions.
76 changes: 76 additions & 0 deletions autotest/test_model_dot_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from os import listdir
from os.path import join

import pytest
from flaky import flaky
from matplotlib import rcParams

from flopy.mf6 import MFSimulation
from flopy.modflow import Modflow


@pytest.mark.mf6
def test_vertex_model_dot_plot(example_data_path):
rcParams["figure.max_open_warning"] = 36

# load up the vertex example problem
sim = MFSimulation.load(
sim_ws=example_data_path / "mf6" / "test003_gwftri_disv"
)
disv_ml = sim.get_model("gwf_1")
ax = disv_ml.plot()
assert isinstance(ax, list)
assert len(ax) == 36


# 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(function_tmpdir, example_data_path):
loadpth = example_data_path / "mf2005_test"
ml = Modflow.load("ibs2k.nam", "mf2k", model_ws=loadpth, check=False)
ax = ml.plot()
assert isinstance(ax, list), "ml.plot() ax is is not a list"
assert len(ax) == 18, f"number of axes ({len(ax)}) is not equal to 18"


def test_dataset_dot_plot(function_tmpdir, example_data_path):
loadpth = example_data_path / "mf2005_test"
ml = Modflow.load("ibs2k.nam", "mf2k", model_ws=loadpth, check=False)

# plot specific dataset
ax = ml.bcf6.hy.plot()
assert isinstance(ax, list), "ml.bcf6.hy.plot() ax is is not a list"
assert len(ax) == 2, f"number of hy axes ({len(ax)}) is not equal to 2"


def test_dataset_dot_plot_nlay_ne_plottable(
function_tmpdir, example_data_path
):
import matplotlib.pyplot as plt

loadpth = example_data_path / "mf2005_test"
ml = Modflow.load("ibs2k.nam", "mf2k", model_ws=loadpth, check=False)
# special case where nlay != plottable
ax = ml.bcf6.vcont.plot()
assert isinstance(
ax, plt.Axes
), "ml.bcf6.vcont.plot() ax is is not of type plt.Axes"


def test_model_dot_plot_export(function_tmpdir, example_data_path):
loadpth = example_data_path / "mf2005_test"
ml = Modflow.load("ibs2k.nam", "mf2k", model_ws=loadpth, check=False)

fh = join(function_tmpdir, "ibs2k")
ml.plot(mflay=0, filename_base=fh, file_extension="png")
files = [f for f in listdir(function_tmpdir) if f.endswith(".png")]
if len(files) < 10:
raise AssertionError(
"ml.plot did not properly export all supported data types"
)

for f in files:
t = f.split("_")
if len(t) < 3:
raise AssertionError("Plot filenames not written correctly")
Loading

0 comments on commit 1aa2c45

Please sign in to comment.