From 1fbe9a35e7f04fe0fb181615bbce7e9da78b383b Mon Sep 17 00:00:00 2001 From: Ryan May Date: Thu, 19 Oct 2017 16:35:26 -0600 Subject: [PATCH] MNT: Fix some of the polygon tests These were relying on the order of polygons, which doesn't seem to be guaranteed by the wrapping process. It was essentially relying upon the order of popitem() from a dict, which changed with Python 3.6. This changes to try to identify the appropriate polygons before embarking on testing them. --- lib/cartopy/tests/test_polygon.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/cartopy/tests/test_polygon.py b/lib/cartopy/tests/test_polygon.py index 3c8b5b5185..66512c5f48 100644 --- a/lib/cartopy/tests/test_polygon.py +++ b/lib/cartopy/tests/test_polygon.py @@ -270,10 +270,13 @@ def test_plate_carree_partial_wrap(self): # Check the structure assert len(multi_polygon) == 2 # Check the rough shape - polygon = multi_polygon[0] - self._assert_bounds(polygon.bounds, 170, 0, 180, 10) - polygon = multi_polygon[1] - self._assert_bounds(polygon.bounds, -180, 0, -170, 10) + poly1, poly2 = multi_polygon + # The order of these polygons is not guaranteed, so figure out + # which is appropriate + if 170.0 not in poly1.bounds: + poly1, poly2 = poly2, poly1 + self._assert_bounds(poly1.bounds, 170, 0, 180, 10) + self._assert_bounds(poly2.bounds, -180, 0, -170, 10) def test_plate_carree_wrap(self): proj = ccrs.PlateCarree() @@ -312,14 +315,19 @@ def test_wrapped_poly_simple_hole(self): multi_polygon = proj.project_geometry(poly) # Check the structure assert len(multi_polygon) == 2 - assert len(multi_polygon[0].interiors) == 1 - assert len(multi_polygon[1].interiors) == 0 + + poly1, poly2 = multi_polygon + # The order of these polygons is not guaranteed, so figure out + # which is appropriate + if not len(poly1.interiors) == 1: + poly1, poly2 = poly2, poly1 + + assert len(poly1.interiors) == 1 + assert len(poly2.interiors) == 0 # Check the rough shape - polygon = multi_polygon[0] - self._assert_bounds(polygon.bounds, 110, -47, 180, 47) - self._assert_bounds(polygon.interiors[0].bounds, 130, -21, 170, 21) - polygon = multi_polygon[1] - self._assert_bounds(polygon.bounds, -180, -43, -170, 43) + self._assert_bounds(poly1.bounds, 110, -47, 180, 47) + self._assert_bounds(poly1.interiors[0].bounds, 130, -21, 170, 21) + self._assert_bounds(poly2.bounds, -180, -43, -170, 43) def test_wrapped_poly_wrapped_hole(self): proj = ccrs.PlateCarree(-180)