Skip to content

Commit

Permalink
Removing old MPL version checks and tolerances.
Browse files Browse the repository at this point in the history
  • Loading branch information
greglucas committed Jun 5, 2020
1 parent 2ea9a1e commit 0f0ee79
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 140 deletions.
9 changes: 1 addition & 8 deletions lib/cartopy/tests/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,7 @@ def wrapped(*args, **kwargs):
(mod_name, test_name))
plt.close('all')

if MPL_VERSION >= '2':
style_context = mpl.style.context
else:
@contextlib.contextmanager
def style_context(style, after_reset=False):
yield

with style_context(self.style):
with mpl.style.context(self.style):
if MPL_VERSION >= '3.2.0':
mpl.rcParams['text.kerning_factor'] = 6

Expand Down
11 changes: 3 additions & 8 deletions lib/cartopy/tests/mpl/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@ def new_fn(*args, **kwargs):


@pytest.mark.natural_earth
@ExampleImageTesting(['global_map'],
tolerance=4.5 if MPL_VERSION < '2' else 0.5)
@ExampleImageTesting(['global_map'], tolerance=0.5)
def test_global_map():
import cartopy.examples.global_map as example
example.main()


if MPL_VERSION < '2':
contour_labels_tolerance = 7.5
elif MPL_VERSION <= '2.0.2':
contour_labels_tolerance = 1.24
elif MPL_VERSION <= '2.1.2':
contour_labels_tolerance = 0.63
if MPL_VERSION < '3':
contour_labels_tolerance = 9.8
else:
contour_labels_tolerance = 0

Expand Down
5 changes: 2 additions & 3 deletions lib/cartopy/tests/mpl/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import cartopy.feature as cfeature
from cartopy.io.ogc_clients import _OWSLIB_AVAILABLE

from cartopy.tests.mpl import MPL_VERSION, ImageTesting
from cartopy.tests.mpl import ImageTesting


@pytest.mark.natural_earth
Expand Down Expand Up @@ -40,8 +40,7 @@ def test_natural_earth_custom():
ax.set_ylim((58, 72))


@ImageTesting(['gshhs_coastlines'],
tolerance=3.3 if MPL_VERSION < '2' else 0.95)
@ImageTesting(['gshhs_coastlines'], tolerance=0.95)
def test_gshhs():
ax = plt.axes(projection=ccrs.Mollweide())
ax.set_extent([138, 142, 32, 42], ccrs.Geodetic())
Expand Down
43 changes: 8 additions & 35 deletions lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,42 +126,15 @@ def test_gridliner_specified_lines():

# The tolerance on these tests are particularly high because of the high number
# of text objects. A new testing strategy is needed for this kind of test.
grid_label_tol = grid_label_inline_tol = grid_label_inline_usa_tol = 0.5
if MPL_VERSION >= '2.0':
grid_label_image = 'gridliner_labels'
if ccrs.PROJ4_VERSION < (4, 9, 3):
# A 0-longitude label is missing on older Proj versions.
grid_label_tol = 1.8
grid_label_inline_image = 'gridliner_labels_inline'
grid_label_inline_usa_image = 'gridliner_labels_inline_usa'
if ccrs.PROJ4_VERSION == (4, 9, 1):
# AzimuthalEquidistant was previously broken.
grid_label_inline_tol = 7.9
grid_label_inline_usa_tol = 7.7
elif ccrs.PROJ4_VERSION < (5, 0, 0):
# Stereographic was previously broken.
grid_label_inline_tol = 6.4
grid_label_inline_usa_tol = 4.0
if MPL_VERSION < "3":
TOL = 15
else:
grid_label_image = 'gridliner_labels_1.5'
grid_label_tol = 1.8
grid_label_inline_image = 'gridliner_labels_inline_1.5'
grid_label_inline_usa_image = 'gridliner_labels_inline_usa_1.5'
if ccrs.PROJ4_VERSION >= (5, 0, 0):
# Stereographic was fixed, but test image was not updated.
grid_label_inline_tol = 7.9
grid_label_inline_usa_tol = 7.9
elif ccrs.PROJ4_VERSION >= (4, 9, 2):
# AzimuthalEquidistant was fixed, but test image was not updated.
grid_label_inline_tol = 5.4
grid_label_inline_usa_tol = 7.2
if (5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0):
# Several projections are broken in these versions, so not plotted.
grid_label_inline_tol += 5.1
grid_label_inline_usa_tol += 5.5
elif (6, 0, 0) <= ccrs.PROJ4_VERSION:
# Better Robinson projection causes some text movement.
grid_label_inline_tol += 1.2
TOL = 0.5
grid_label_tol = grid_label_inline_tol = grid_label_inline_usa_tol = TOL
grid_label_inline_tol += 1.1
grid_label_image = 'gridliner_labels'
grid_label_inline_image = 'gridliner_labels_inline'
grid_label_inline_usa_image = 'gridliner_labels_inline_usa'


@pytest.mark.natural_earth
Expand Down
30 changes: 8 additions & 22 deletions lib/cartopy/tests/mpl/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import cartopy.crs as ccrs
import cartopy.io.img_tiles as cimgt

from cartopy.tests.mpl import MPL_VERSION, ImageTesting
from cartopy.tests.mpl import ImageTesting
import cartopy.tests.test_img_tiles as ctest_tiles


Expand All @@ -31,20 +31,12 @@
# We have an exceptionally large tolerance for the web_tiles test.
# The basemap changes on a regular basis (for seasons) and we really only
# care that it is putting images onto the map which are roughly correct.
if MPL_VERSION < '2':
web_tiles_tolerance = 12
elif MPL_VERSION < '2.1.0':
web_tiles_tolerance = 4.6
else:
web_tiles_tolerance = 5.4


@pytest.mark.natural_earth
@pytest.mark.network
@pytest.mark.xfail(ccrs.PROJ4_VERSION == (5, 0, 0),
reason='Proj returns slightly different bounds.',
strict=True)
@ImageTesting(['web_tiles'], tolerance=web_tiles_tolerance)
@ImageTesting(['web_tiles'], tolerance=5.4)
def test_web_tiles():
extent = [-15, 0.1, 50, 60]
target_domain = sgeom.Polygon([[extent[0], extent[1]],
Expand Down Expand Up @@ -83,8 +75,7 @@ def test_web_tiles():
@pytest.mark.xfail(ccrs.PROJ4_VERSION == (5, 0, 0),
reason='Proj returns slightly different bounds.',
strict=True)
@ImageTesting(['image_merge'],
tolerance=3.9 if MPL_VERSION < '2' else 0.01)
@ImageTesting(['image_merge'], tolerance=0.01)
def test_image_merge():
# tests the basic image merging functionality
tiles = []
Expand Down Expand Up @@ -113,8 +104,7 @@ def test_image_merge():
@pytest.mark.xfail((5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0),
reason='Proj Orthographic projection is buggy.',
strict=True)
@ImageTesting(['imshow_natural_earth_ortho'],
tolerance=3.99 if MPL_VERSION < '2' else 0.7)
@ImageTesting(['imshow_natural_earth_ortho'], tolerance=0.7)
def test_imshow():
source_proj = ccrs.PlateCarree()
img = plt.imread(NATURAL_EARTH_IMG)
Expand All @@ -127,8 +117,7 @@ def test_imshow():


@pytest.mark.natural_earth
@ImageTesting(['imshow_regional_projected'],
tolerance=10.4 if MPL_VERSION < '2' else 0.8)
@ImageTesting(['imshow_regional_projected'], tolerance=0.8)
def test_imshow_projected():
source_proj = ccrs.PlateCarree()
img_extent = (-120.67660000000001, -106.32104523100001,
Expand All @@ -153,8 +142,7 @@ def test_imshow_wrapping():
@pytest.mark.xfail((5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0),
reason='Proj Orthographic projection is buggy.',
strict=True)
@ImageTesting(['imshow_natural_earth_ortho'],
tolerance=4.19 if MPL_VERSION < '2' else 0.7)
@ImageTesting(['imshow_natural_earth_ortho'], tolerance=0.7)
def test_stock_img():
ax = plt.axes(projection=ccrs.Orthographic())
ax.stock_img()
Expand All @@ -163,8 +151,7 @@ def test_stock_img():
@pytest.mark.xfail((5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0),
reason='Proj Orthographic projection is buggy.',
strict=True)
@ImageTesting(['imshow_natural_earth_ortho'],
tolerance=3.99 if MPL_VERSION < '2' else 0.7)
@ImageTesting(['imshow_natural_earth_ortho'], tolerance=0.7)
def test_pil_Image():
img = Image.open(NATURAL_EARTH_IMG)
source_proj = ccrs.PlateCarree()
Expand All @@ -176,8 +163,7 @@ def test_pil_Image():
@pytest.mark.xfail((5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0),
reason='Proj Orthographic projection is buggy.',
strict=True)
@ImageTesting(['imshow_natural_earth_ortho'],
tolerance=4.2 if MPL_VERSION < '2' else 0.5)
@ImageTesting(['imshow_natural_earth_ortho'], tolerance=0.5)
def test_background_img():
ax = plt.axes(projection=ccrs.Orthographic())
ax.background_img(name='ne_shaded', resolution='low')
Expand Down
19 changes: 3 additions & 16 deletions lib/cartopy/tests/mpl/test_img_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pytest

from cartopy import config
from cartopy.tests.mpl import MPL_VERSION, ImageTesting
from cartopy.tests.mpl import ImageTesting
import cartopy.crs as ccrs
import cartopy.img_transform as im_trans
from functools import reduce
Expand Down Expand Up @@ -78,22 +78,9 @@ def test_different_dims(self):
target_proj, target_x, target_y)


if MPL_VERSION < '2':
# Changes in zooming in old versions.
regrid_tolerance = 2.5
elif MPL_VERSION < '2.0.1':
regrid_tolerance = 0.5
elif MPL_VERSION < '2.1.0':
# Bug in latest Matplotlib that we don't consider correct.
regrid_tolerance = 4.78
else:
# Bug in latest Matplotlib that we don't consider correct.
regrid_tolerance = 5.55


# Bug in latest Matplotlib that we don't consider correct.
@pytest.mark.natural_earth
@ImageTesting(['regrid_image'],
tolerance=regrid_tolerance)
@ImageTesting(['regrid_image'], tolerance=5.55)
def test_regrid_image():
# Source data
fname = os.path.join(config["repo_data_dir"], 'raster', 'natural_earth',
Expand Down
42 changes: 10 additions & 32 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@
_STREAMPLOT_STYLE = 'mpl20'
else:
_CONTOUR_IMAGE = 'global_contour_wrap_mpl_pre_3.0.0'
if MPL_VERSION >= '2.1.0':
_STREAMPLOT_IMAGE = 'streamplot_mpl_2.1.0'
elif MPL_VERSION >= '2':
_CONTOUR_TOL = 11.4
_STREAMPLOT_IMAGE = 'streamplot_mpl_2.0.0'
else:
_CONTOUR_TOL = 11.4
_STREAMPLOT_IMAGE = 'streamplot_mpl_1.4.3'
_STREAMPLOT_IMAGE = 'streamplot_mpl_2.1.0'


@pytest.mark.natural_earth
Expand Down Expand Up @@ -105,8 +98,7 @@ def test_global_pcolor_wrap_no_transform():


@pytest.mark.natural_earth
@ImageTesting(['global_scatter_wrap'],
tolerance=12.4 if MPL_VERSION < '2.1.0' else 0.5)
@ImageTesting(['global_scatter_wrap'], tolerance=0.5)
def test_global_scatter_wrap_new_transform():
ax = plt.axes(projection=ccrs.PlateCarree())
# By default the coastline feature will be drawn after patches.
Expand All @@ -119,8 +111,7 @@ def test_global_scatter_wrap_new_transform():


@pytest.mark.natural_earth
@ImageTesting(['global_scatter_wrap'],
tolerance=12.4 if MPL_VERSION < '2.1.0' else 0.5)
@ImageTesting(['global_scatter_wrap'], tolerance=0.5)
def test_global_scatter_wrap_no_transform():
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines(zorder=0)
Expand All @@ -131,7 +122,7 @@ def test_global_scatter_wrap_no_transform():

@pytest.mark.natural_earth
@ImageTesting(['global_hexbin_wrap'],
tolerance=27.7 if MPL_VERSION < '2.1.0' else 0.5)
tolerance=2 if MPL_VERSION < '3' else 0.5)
def test_global_hexbin_wrap():
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines(zorder=2)
Expand All @@ -148,7 +139,7 @@ def test_global_hexbin_wrap():

@pytest.mark.natural_earth
@ImageTesting(['global_hexbin_wrap'],
tolerance=27.7 if MPL_VERSION < '2.1.0' else 0.5)
tolerance=2 if MPL_VERSION < '3' else 0.5)
def test_global_hexbin_wrap_transform():
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines(zorder=2)
Expand All @@ -166,7 +157,7 @@ def test_global_hexbin_wrap_transform():


@ImageTesting(['global_map'],
tolerance=1.93 if MPL_VERSION < '2.1.0' else 0.55)
tolerance=0.55)
def test_global_map():
plt.axes(projection=ccrs.Robinson())
# ax.coastlines()
Expand Down Expand Up @@ -309,8 +300,7 @@ def test_axes_natural_earth_interface():


@pytest.mark.natural_earth
@ImageTesting(['pcolormesh_global_wrap1'],
tolerance=6.3 if MPL_VERSION < '2.1.0' else 1.27)
@ImageTesting(['pcolormesh_global_wrap1'], tolerance=1.27)
def test_pcolormesh_global_with_wrap1():
# make up some realistic data with bounds (such as data from the UM)
nx, ny = 36, 18
Expand All @@ -333,8 +323,6 @@ def test_pcolormesh_global_with_wrap1():


tolerance = 1.61
if MPL_VERSION < '2.1.0':
tolerance = 6.4
if (5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0):
tolerance += 0.8

Expand Down Expand Up @@ -369,8 +357,6 @@ def test_pcolormesh_global_with_wrap2():


tolerance = 1.39
if MPL_VERSION < '2.1.0':
tolerance = 2.5
if (5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0):
tolerance += 1.4

Expand Down Expand Up @@ -415,10 +401,8 @@ def test_pcolormesh_global_with_wrap3():
ax.set_global() # make sure everything is visible


@pytest.mark.xfail(MPL_VERSION < '2.1.0', reason='Matplotlib is broken.')
@pytest.mark.natural_earth
@ImageTesting(['pcolormesh_limited_area_wrap'],
tolerance=1.82 if MPL_VERSION >= '2.1.0' else 0.7)
@ImageTesting(['pcolormesh_limited_area_wrap'], tolerance=1.82)
def test_pcolormesh_limited_area_wrap():
# make up some realistic data with bounds (such as data from the UM's North
# Atlantic Europe model)
Expand Down Expand Up @@ -478,7 +462,6 @@ def test_pcolormesh_single_column_wrap():
ax.set_global()


@pytest.mark.xfail(MPL_VERSION < '2.1.0', reason='Matplotlib is broken.')
@pytest.mark.natural_earth
@ImageTesting(['pcolormesh_goode_wrap'])
def test_pcolormesh_goode_wrap():
Expand All @@ -494,7 +477,6 @@ def test_pcolormesh_goode_wrap():
ax.pcolormesh(x, y, Z, transform=ccrs.PlateCarree())


@pytest.mark.xfail(MPL_VERSION < '2.1.0', reason='Matplotlib is broken.')
@pytest.mark.natural_earth
@ImageTesting(['pcolormesh_mercator_wrap'], tolerance=0.93)
def test_pcolormesh_mercator_wrap():
Expand All @@ -508,7 +490,6 @@ def test_pcolormesh_mercator_wrap():
ax.pcolormesh(x, y, Z, transform=ccrs.PlateCarree())


@pytest.mark.xfail(MPL_VERSION < '2.1.0', reason='Matplotlib is broken.')
@pytest.mark.natural_earth
@ImageTesting(['quiver_plate_carree'])
def test_quiver_plate_carree():
Expand All @@ -532,7 +513,6 @@ def test_quiver_plate_carree():
ax.quiver(x, y, u, v, mag, transform=ccrs.PlateCarree())


@pytest.mark.xfail(MPL_VERSION < '2.1.0', reason='Matplotlib is broken.')
@pytest.mark.natural_earth
@ImageTesting(['quiver_rotated_pole'])
def test_quiver_rotated_pole():
Expand Down Expand Up @@ -596,8 +576,7 @@ def test_quiver_regrid_with_extent():


@pytest.mark.natural_earth
@ImageTesting(['barbs_plate_carree'],
tolerance=8 if MPL_VERSION < '2.1.0' else 0.5)
@ImageTesting(['barbs_plate_carree'], tolerance=0.5)
def test_barbs():
x = np.arange(-60, 45, 5)
y = np.arange(30, 75, 5)
Expand All @@ -619,8 +598,7 @@ def test_barbs():


@pytest.mark.natural_earth
@ImageTesting(['barbs_regrid'],
tolerance=2.9 if MPL_VERSION < '2.1.0' else 0.5)
@ImageTesting(['barbs_regrid'], tolerance=0.5)
def test_barbs_regrid():
x = np.arange(-60, 42.5, 2.5)
y = np.arange(30, 72.5, 2.5)
Expand Down
Loading

0 comments on commit 0f0ee79

Please sign in to comment.