Skip to content

Commit

Permalink
TST: Skip scipy tests if scipy isn't installed
Browse files Browse the repository at this point in the history
Scipy isn't a required dependency, so skip the tests that require
scipy if scipy isn't found.
  • Loading branch information
greglucas committed Oct 29, 2023
1 parent 0d58449 commit a709f0d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/cartopy/tests/mpl/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
import numpy as np
from numpy.testing import assert_array_almost_equal
import pytest
from scipy.interpolate import NearestNDInterpolator
from scipy.signal import convolve2d


try:
from scipy.interpolate import NearestNDInterpolator
from scipy.signal import convolve2d
except ImportError:
pytest.skip("scipy is required for contouring", allow_module_level=True)

import cartopy.crs as ccrs

Expand Down
10 changes: 10 additions & 0 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,8 @@ def test_quiver_rotated_pole():
@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 @@ -840,6 +842,8 @@ def test_quiver_regrid():
@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 Down Expand Up @@ -883,6 +887,8 @@ def test_barbs():
@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 @@ -903,6 +909,8 @@ def test_barbs_regrid():
@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 @@ -958,6 +966,8 @@ def test_barbs_1d_transformed():
@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
8 changes: 7 additions & 1 deletion lib/cartopy/tests/test_img_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
import numpy as np
from numpy.testing import assert_array_equal
import pytest
import scipy.spatial


try:
import scipy.spatial
except ImportError:
pytest.skip("scipy is required for image transforms", allow_module_level=True)


import cartopy.crs as ccrs
import cartopy.img_transform as img_trans
Expand Down
8 changes: 8 additions & 0 deletions lib/cartopy/tests/test_vector_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

import numpy as np
from numpy.testing import assert_array_almost_equal, assert_array_equal
import pytest


try:
import scipy # noqa: F401
except ImportError:
pytest.skip("scipy is required for vector transforms", allow_module_level=True)


import cartopy.crs as ccrs
import cartopy.vector_transform as vec_trans
Expand Down

0 comments on commit a709f0d

Please sign in to comment.