Skip to content

Commit

Permalink
MNT: Fix some of the polygon tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dopplershift committed Oct 19, 2017
1 parent e8c0692 commit 1fbe9a3
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions lib/cartopy/tests/test_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1fbe9a3

Please sign in to comment.