Skip to content

Commit

Permalink
TST: Use requires_scipy decorator in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
greglucas committed Nov 2, 2023
1 parent 3260a1b commit a52198f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
11 changes: 6 additions & 5 deletions lib/cartopy/tests/mpl/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
import pytest

import cartopy.crs as ccrs
from cartopy.tests.conftest import _HAS_PYKDTREE_OR_SCIPY


if not _HAS_PYKDTREE_OR_SCIPY:
pytest.skip('pykdtree or scipy is required', allow_module_level=True)

from cartopy.io.ogc_clients import _OWSLIB_AVAILABLE, WMTSRasterSource
import cartopy.io.shapereader
from cartopy.mpl import _MPL_38
from cartopy.mpl.feature_artist import FeatureArtist
import cartopy.mpl.geoaxes as cgeoaxes
import cartopy.mpl.patch
from cartopy.tests.conftest import _HAS_PYKDTREE_OR_SCIPY


if not _HAS_PYKDTREE_OR_SCIPY:
pytest.skip('pykdtree or scipy is required', allow_module_level=True)


def sample_data(shape=(73, 145)):
Expand Down
9 changes: 4 additions & 5 deletions lib/cartopy/tests/mpl/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytest

import cartopy.crs as ccrs
from cartopy.tests.conftest import requires_scipy


def test_contour_plot_bounds():
Expand Down Expand Up @@ -70,13 +71,11 @@ def test_plot_after_contour_doesnt_shrink(func):
assert_array_almost_equal(ax.get_extent(), expected)


@requires_scipy
def test_contour_linear_ring():
"""Test contourf with a section that only has 3 points."""
try:
from scipy.interpolate import NearestNDInterpolator
from scipy.signal import convolve2d
except ImportError:
pytest.skip("scipy is required for this test")
from scipy.interpolate import NearestNDInterpolator
from scipy.signal import convolve2d

ax = plt.axes([0.01, 0.05, 0.898, 0.85], projection=ccrs.Mercator(),
aspect='equal')
Expand Down
17 changes: 7 additions & 10 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import cartopy.crs as ccrs
from cartopy.mpl import _MPL_38
from cartopy.tests.conftest import requires_scipy


@pytest.mark.natural_earth
Expand Down Expand Up @@ -817,11 +818,10 @@ def test_quiver_rotated_pole():
return fig


@requires_scipy
@pytest.mark.natural_earth
@pytest.mark.mpl_image_compare(filename='quiver_regrid.png')
def test_quiver_regrid():
# scipy required for regridding
pytest.importorskip("scipy")
x = np.arange(-60, 42.5, 2.5)
y = np.arange(30, 72.5, 2.5)
x2d, y2d = np.meshgrid(x, y)
Expand All @@ -838,12 +838,11 @@ def test_quiver_regrid():
return fig


@requires_scipy
@pytest.mark.natural_earth
@pytest.mark.mpl_image_compare(filename='quiver_regrid_with_extent.png',
tolerance=0.54)
def test_quiver_regrid_with_extent():
# scipy required for regridding
pytest.importorskip("scipy")
x = np.arange(-60, 42.5, 2.5)
y = np.arange(30, 72.5, 2.5)
x2d, y2d = np.meshgrid(x, y)
Expand All @@ -861,6 +860,7 @@ def test_quiver_regrid_with_extent():
return fig


@requires_scipy
@pytest.mark.natural_earth
@pytest.mark.mpl_image_compare(filename='barbs_plate_carree.png')
def test_barbs():
Expand All @@ -884,11 +884,10 @@ def test_barbs():
return fig


@requires_scipy
@pytest.mark.natural_earth
@pytest.mark.mpl_image_compare(filename='barbs_regrid.png')
def test_barbs_regrid():
# scipy required for regridding
pytest.importorskip("scipy")
x = np.arange(-60, 42.5, 2.5)
y = np.arange(30, 72.5, 2.5)
x2d, y2d = np.meshgrid(x, y)
Expand All @@ -905,12 +904,11 @@ def test_barbs_regrid():
return fig


@requires_scipy
@pytest.mark.natural_earth
@pytest.mark.mpl_image_compare(filename='barbs_regrid_with_extent.png',
tolerance=0.54)
def test_barbs_regrid_with_extent():
# scipy required for regridding
pytest.importorskip("scipy")
x = np.arange(-60, 42.5, 2.5)
y = np.arange(30, 72.5, 2.5)
x2d, y2d = np.meshgrid(x, y)
Expand Down Expand Up @@ -963,11 +961,10 @@ def test_barbs_1d_transformed():
return fig


@requires_scipy
@pytest.mark.natural_earth
@pytest.mark.mpl_image_compare(filename='streamplot.png', style='mpl20')
def test_streamplot():
# scipy required for regridding
pytest.importorskip("scipy")
x = np.arange(-60, 42.5, 2.5)
y = np.arange(30, 72.5, 2.5)
x2d, y2d = np.meshgrid(x, y)
Expand Down

0 comments on commit a52198f

Please sign in to comment.