def test_get_polygon(get_border_lonlats, Polygon): """Test polygon creation.""" from pyresample.gradient import get_polygon # Valid polygon get_border_lonlats.return_value = (1, 2) geo_def = mock.MagicMock() prj = mock.MagicMock() x_borders = [0, 0, 1, 1] y_borders = [0, 1, 1, 0] boundary = [(0, 0), (0, 1), (1, 1), (1, 0)] prj.return_value = (x_borders, y_borders) poly = mock.MagicMock(area=2.0) Polygon.return_value = poly res = get_polygon(prj, geo_def) get_border_lonlats.assert_called_with(geo_def) prj.assert_called_with(1, 2) Polygon.assert_called_with(boundary) assert res is poly # Some border points are invalid, those should have been removed x_borders = [np.inf, 0, 0, 0, 1, np.nan, 2] y_borders = [-1, 0, np.nan, 1, 1, np.nan, -1] boundary = [(0, 0), (0, 1), (1, 1), (2, -1)] prj.return_value = (x_borders, y_borders) res = get_polygon(prj, geo_def) Polygon.assert_called_with(boundary) assert res is poly # Polygon area is NaN poly.area = np.nan res = get_polygon(prj, geo_def) assert res is None # Polygon area is 0.0 poly.area = 0.0 res = get_polygon(prj, geo_def) assert res is None