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 Aug 21, 2020
1 parent 7704bb5 commit dbf366e
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 146 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 @@ -205,14 +205,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 @@ -30,8 +30,7 @@ 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():
fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.Robinson())
Expand All @@ -48,12 +47,8 @@ def test_global_map():
ax.plot([-0.08, 132], [51.53, 43.17], transform=ccrs.Geodetic())


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.filterwarnings("ignore:Downloading")
Expand Down Expand Up @@ -42,8 +42,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
48 changes: 8 additions & 40 deletions lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,44 +127,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:
# Skip test_grid_labels_tight for matplotlib 1.5.1 because it
# is not possible to override tight bounding box calculation
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 Expand Up @@ -237,9 +208,6 @@ def test_grid_labels():
plt.subplots_adjust(wspace=0.25, hspace=0.25)


@pytest.mark.skipif(
MPL_VERSION < '2.0.0',
reason='Impossible to override tight layout algorithm in mpl < 2.0.0')
@pytest.mark.natural_earth
@ImageTesting(['gridliner_labels_tight'],
tolerance=grid_label_tol if ccrs.PROJ4_VERSION < (7, 1, 0)
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 @@ -19,7 +19,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 @@ -33,20 +33,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 @@ -85,8 +77,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 @@ -115,8 +106,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 @@ -129,8 +119,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 Down Expand Up @@ -184,8 +173,7 @@ def test_imshow_rgb():
@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 @@ -194,8 +182,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 @@ -207,8 +194,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
Loading

0 comments on commit dbf366e

Please sign in to comment.