From 0f0ee79aa43e38484067be14835c56d8ae3302e4 Mon Sep 17 00:00:00 2001 From: Greg Lucas <greg.lucas@lasp.colorado.edu> Date: Thu, 4 Jun 2020 22:04:48 -0600 Subject: [PATCH] Removing old MPL version checks and tolerances. --- lib/cartopy/tests/mpl/__init__.py | 9 +--- lib/cartopy/tests/mpl/test_examples.py | 11 ++--- lib/cartopy/tests/mpl/test_features.py | 5 +-- lib/cartopy/tests/mpl/test_gridliner.py | 43 ++++--------------- lib/cartopy/tests/mpl/test_images.py | 30 ++++--------- lib/cartopy/tests/mpl/test_img_transform.py | 19 ++------ lib/cartopy/tests/mpl/test_mpl_integration.py | 42 +++++------------- lib/cartopy/tests/mpl/test_pseudo_color.py | 2 - lib/cartopy/tests/mpl/test_ticks.py | 13 +----- lib/cartopy/tests/mpl/test_web_services.py | 6 +-- 10 files changed, 40 insertions(+), 140 deletions(-) diff --git a/lib/cartopy/tests/mpl/__init__.py b/lib/cartopy/tests/mpl/__init__.py index 105ef9b75c..bedb435289 100644 --- a/lib/cartopy/tests/mpl/__init__.py +++ b/lib/cartopy/tests/mpl/__init__.py @@ -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 diff --git a/lib/cartopy/tests/mpl/test_examples.py b/lib/cartopy/tests/mpl/test_examples.py index 91780f9f9f..c6c51e521e 100644 --- a/lib/cartopy/tests/mpl/test_examples.py +++ b/lib/cartopy/tests/mpl/test_examples.py @@ -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 diff --git a/lib/cartopy/tests/mpl/test_features.py b/lib/cartopy/tests/mpl/test_features.py index db998f9437..174f65bbd8 100644 --- a/lib/cartopy/tests/mpl/test_features.py +++ b/lib/cartopy/tests/mpl/test_features.py @@ -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 @@ -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()) diff --git a/lib/cartopy/tests/mpl/test_gridliner.py b/lib/cartopy/tests/mpl/test_gridliner.py index d507b15847..f1fb07c0ff 100644 --- a/lib/cartopy/tests/mpl/test_gridliner.py +++ b/lib/cartopy/tests/mpl/test_gridliner.py @@ -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 diff --git a/lib/cartopy/tests/mpl/test_images.py b/lib/cartopy/tests/mpl/test_images.py index 0204655239..19ac94a239 100644 --- a/lib/cartopy/tests/mpl/test_images.py +++ b/lib/cartopy/tests/mpl/test_images.py @@ -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 @@ -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]], @@ -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 = [] @@ -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) @@ -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, @@ -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() @@ -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() @@ -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') diff --git a/lib/cartopy/tests/mpl/test_img_transform.py b/lib/cartopy/tests/mpl/test_img_transform.py index 710a70f957..23a9bbdb77 100644 --- a/lib/cartopy/tests/mpl/test_img_transform.py +++ b/lib/cartopy/tests/mpl/test_img_transform.py @@ -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 @@ -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', diff --git a/lib/cartopy/tests/mpl/test_mpl_integration.py b/lib/cartopy/tests/mpl/test_mpl_integration.py index d9d73e1a1d..3d9f3ce205 100644 --- a/lib/cartopy/tests/mpl/test_mpl_integration.py +++ b/lib/cartopy/tests/mpl/test_mpl_integration.py @@ -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 @@ -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. @@ -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) @@ -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) @@ -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) @@ -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() @@ -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 @@ -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 @@ -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 @@ -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) @@ -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(): @@ -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(): @@ -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(): @@ -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(): @@ -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) @@ -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) diff --git a/lib/cartopy/tests/mpl/test_pseudo_color.py b/lib/cartopy/tests/mpl/test_pseudo_color.py index 436bd7ce47..2e0ee19d86 100644 --- a/lib/cartopy/tests/mpl/test_pseudo_color.py +++ b/lib/cartopy/tests/mpl/test_pseudo_color.py @@ -12,7 +12,6 @@ import pytest import cartopy.crs as ccrs -from cartopy.tests.mpl import MPL_VERSION def test_pcolormesh_fully_masked(): @@ -53,7 +52,6 @@ def test_pcolormesh_invisible(): plt.close() -@pytest.mark.skipif(MPL_VERSION < '2.1.0', reason='Matplotlib is broken.') def test_savefig_tight(): nx, ny = 36, 18 xbnds = np.linspace(0, 360, nx, endpoint=True) diff --git a/lib/cartopy/tests/mpl/test_ticks.py b/lib/cartopy/tests/mpl/test_ticks.py index 9fc9cd76d4..0e161736e6 100644 --- a/lib/cartopy/tests/mpl/test_ticks.py +++ b/lib/cartopy/tests/mpl/test_ticks.py @@ -11,7 +11,7 @@ import pytest import cartopy.crs as ccrs -from cartopy.tests.mpl import MPL_VERSION, ImageTesting +from cartopy.tests.mpl import ImageTesting def _format_lat(val, i): @@ -37,16 +37,7 @@ def _format_lon(val, i): return '%.0fW' % abs(val) -# Text tends to move a lot. Also, pre-2.0.1, the new center_baseline alignment -# did not exist. -if MPL_VERSION < '2.0.0': - ticks_tolerance = 6.3 -elif '2.0.0' <= MPL_VERSION < '2.0.1': - ticks_tolerance = 9 -else: - ticks_tolerance = 7 - - +ticks_tolerance = 7 @pytest.mark.natural_earth @ImageTesting(['xticks_no_transform'], tolerance=ticks_tolerance) diff --git a/lib/cartopy/tests/mpl/test_web_services.py b/lib/cartopy/tests/mpl/test_web_services.py index ae50e221af..55ac7606ca 100644 --- a/lib/cartopy/tests/mpl/test_web_services.py +++ b/lib/cartopy/tests/mpl/test_web_services.py @@ -8,7 +8,7 @@ from matplotlib.testing.decorators import cleanup import pytest -from cartopy.tests.mpl import MPL_VERSION, ImageTesting +from cartopy.tests.mpl import ImageTesting import cartopy.crs as ccrs from cartopy.io.ogc_clients import _OWSLIB_AVAILABLE @@ -16,7 +16,7 @@ @pytest.mark.network @pytest.mark.skipif(not _OWSLIB_AVAILABLE, reason='OWSLib is unavailable.') @pytest.mark.xfail(raises=KeyError, reason='OWSLib WMTS support is broken.') -@ImageTesting(['wmts'], tolerance=7.56 if MPL_VERSION < '2' else 0) +@ImageTesting(['wmts'], tolerance=0) def test_wmts(): ax = plt.axes(projection=ccrs.PlateCarree()) url = 'https://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi' @@ -40,7 +40,7 @@ def test_wms_tight_layout(): reason='Proj Orthographic projection is buggy.', strict=True) @pytest.mark.skipif(not _OWSLIB_AVAILABLE, reason='OWSLib is unavailable.') -@ImageTesting(['wms'], tolerance=7.79 if MPL_VERSION < '2' else 0.02) +@ImageTesting(['wms'], tolerance=0.02) def test_wms(): ax = plt.axes(projection=ccrs.Orthographic()) url = 'http://vmap0.tiles.osgeo.org/wms/vmap0'