From c0e533d9213026d65988f0f5b5886576a92234e6 Mon Sep 17 00:00:00 2001 From: Bill Little Date: Mon, 16 Oct 2023 15:10:58 +0100 Subject: [PATCH] add samples.lfric warn test coverage --- tests/samples/test_lfric.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/samples/test_lfric.py diff --git a/tests/samples/test_lfric.py b/tests/samples/test_lfric.py new file mode 100644 index 00000000..7651f18e --- /dev/null +++ b/tests/samples/test_lfric.py @@ -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