Skip to content

Commit

Permalink
Qualify warnings (#498)
Browse files Browse the repository at this point in the history
* Qualify warnings

* add samples.lfric warn test coverage

* update pytest filterwarnings
  • Loading branch information
bjlittle authored Oct 16, 2023
1 parent 9fc3b94 commit 4e5af96
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ doctest_optionflags = "NORMALIZE_WHITESPACE ELLIPSIS NUMBER"
filterwarnings = [
"error",
"ignore:numpy.ndarray size changed:RuntimeWarning",
"ignore:Unable to remesh 1 cell:UserWarning",
"ignore:geovista unable to remesh 1 cell:UserWarning",
"ignore:pyvista test cache image dir:UserWarning",
"ignore:pyvista test generated image dir:UserWarning",
]
Expand Down
2 changes: 1 addition & 1 deletion src/geovista/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def from_unstructured(
n_invalid = n_faces - np.sum(valid_faces_mask)
plural = "s" if n_invalid > 1 else ""
wmsg = (
f"Masked connectivity defines {n_invalid:,} face{plural} "
f"geovista masked connectivity defines {n_invalid:,} face{plural} "
"with no vertices."
)
warnings.warn(wmsg, stacklevel=2)
Expand Down
4 changes: 2 additions & 2 deletions src/geovista/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def slice_cells(
plural = "s" if (n_cells := bad_cids.size) > 1 else ""
naughty = ", ".join([f"{cid}" for cid in bad_cids])
wmsg = (
f"Unable to remesh {n_cells} cell{plural}. Removing the "
f"geovista unable to remesh {n_cells} cell{plural}. Removing the "
f"following mesh cell-id{plural} [{naughty}]."
)
warnings.warn(wmsg, stacklevel=2)
Expand Down Expand Up @@ -727,7 +727,7 @@ def slice_lines(
n_points = SPLINE_N_POINTS

if n_points < 1:
wmsg = f"Ignoring 'n_points={n_points}', defaulting to 'n_points=1'."
wmsg = f"geovista ignoring 'n_points={n_points}', defaulting to 'n_points=1'."
warnings.warn(wmsg, stacklevel=2)

# check whether the line is completely aligned with the slice plane
Expand Down
6 changes: 3 additions & 3 deletions src/geovista/geodesic.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ def __init__(
lons, lats = lons[-1], lats[-1]
else:
wmsg = (
"The bounding-box was specified with 5 longitude/latitude values, "
"however the first and last values are not close enough to specify "
"a closed geometry - ignoring last value."
"geovista bounding-box was specified with 5 longitude/latitude"
"values, however the first and last values are not close enough to "
"specify a closed geometry - ignoring last value."
)
warnings.warn(wmsg, stacklevel=2)
lons, lats = lons[:-1], lats[:-1]
Expand Down
11 changes: 7 additions & 4 deletions src/geovista/geoplotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __init__(self, *args: Any | None, **kwargs: Any | None) -> None:
klass = f"'{self.__class__.__name__}'"
if len(args) == 1 and ("crs" not in kwargs or kwargs["crs"] is None):
wmsg = (
f"{klass} received an unexpected argument. "
f"geovista {klass} received an unexpected argument. "
"Assuming 'crs' keyword argument instead..."
)
warn(wmsg, stacklevel=2)
Expand Down Expand Up @@ -574,7 +574,10 @@ def add_mesh(self, mesh: Any, **kwargs: Any | None) -> pv.Actor:
src_crs = from_wkt(mesh)

if src_crs is None:
wmsg = "Found no coordinate reference system (CRS) attached to mesh."
wmsg = (
"geovista found no coordinate reference system (CRS) attached "
"to mesh."
)
warn(wmsg, stacklevel=2)

tgt_crs = self.crs
Expand Down Expand Up @@ -1110,8 +1113,8 @@ def add_points(

if isinstance(scalars, str):
wmsg = (
f"Ignoring the 'scalars' string name '{scalars}', as no 'points' "
"mesh was provided."
f"geovista ignoring the 'scalars' string name '{scalars}', as no "
"'points' mesh was provided."
)
warn(wmsg, stacklevel=2)

Expand Down
2 changes: 1 addition & 1 deletion src/geovista/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def lfric(resolution: str | None = None) -> pv.PolyData:

if resolution not in LFRIC_RESOLUTIONS:
wmsg = (
f"Unknown LFRic cubed-sphere resolution {original!r}, "
f"geovista detected unknown LFRic cubed-sphere resolution {original!r}, "
f"using {LFRIC_RESOLUTION!r} instead."
)
warn(wmsg, stacklevel=2)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_slice_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_no_lines(mesh):
@pytest.mark.parametrize("n_points", [0, -1])
def test_n_points_warning(coastlines, n_points):
"""Test invalid domain for n_points warning is raised."""
wmsg = f"Ignoring 'n_points={n_points}'"
wmsg = f"geovista ignoring 'n_points={n_points}'"
with pytest.warns(UserWarning, match=wmsg):
_ = slice_lines(coastlines, n_points=n_points)

Expand Down
2 changes: 1 addition & 1 deletion tests/geoplotter/test_add_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_xy_ys_scalars_name_warnings(mocker):
xs, ys = mocker.sentinel.xs, mocker.sentinel.ys
scalars = "invalid"
wmsg = (
f"Ignoring the 'scalars' string name '{scalars}', "
f"geovista ignoring the 'scalars' string name '{scalars}', "
"as no 'points' mesh was provided"
)
with pytest.warns(UserWarning, match=wmsg):
Expand Down
31 changes: 31 additions & 0 deletions tests/samples/test_lfric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Unit-tests for :func:`geovista.samples.lfric`."""
from __future__ import annotations

import pytest

from geovista.samples import LFRIC_RESOLUTION, lfric


def test_resolution_warning(mocker):
"""Test warning raised of invalid cubed-sphere resolution request."""
processor = mocker.sentinel.processor
_ = mocker.patch("pooch.Decompress", return_value=processor)
resource = mocker.sentinel.resource
_ = mocker.patch("geovista.cache.CACHE.fetch", return_value=resource)
mesh = mocker.sentinel.mesh
_ = mocker.patch("pyvista.read", return_value=mesh)
bad = "r24"
wmsg = f"geovista detected unknown LFRic cubed-sphere resolution {bad!r}"
with pytest.warns(UserWarning, match=wmsg):
result = lfric(resolution=bad)

import pooch
import pyvista as pv

from geovista.cache import CACHE

fname = f"lfric_{LFRIC_RESOLUTION}.vtk"
pooch.Decompress.assert_called_once_with(method="auto", name=fname)
CACHE.fetch.assert_called_once_with(f"mesh/{fname}.bz2", processor=processor)
pv.read.assert_called_once_with(resource)
assert result == mesh

0 comments on commit 4e5af96

Please sign in to comment.