Skip to content

Commit

Permalink
add samples.lfric warn test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle committed Oct 16, 2023
1 parent acc4a15 commit c0e533d
Showing 1 changed file with 31 additions and 0 deletions.
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 c0e533d

Please sign in to comment.