diff --git a/pyresample/test/test_gradient.py b/pyresample/test/test_gradient.py index 90983847..c911f297 100644 --- a/pyresample/test/test_gradient.py +++ b/pyresample/test/test_gradient.py @@ -407,103 +407,6 @@ def fake_compute(arg1, data): decorated('bla', data) -def test_check_overlap(): - """Test overlap check returning correct results.""" - from shapely.geometry import Polygon - - from pyresample.gradient import check_overlap - - # If either of the polygons is False, True is returned - assert check_overlap(False, 3) is True - assert check_overlap('eggs', False) is True - assert check_overlap(False, False) is True - - # If either the polygons is None, False is returned - assert check_overlap(None, 'bacon') is False - assert check_overlap('spam', None) is False - assert check_overlap(None, None) is False - - # If the polygons overlap, True is returned - poly1 = Polygon(((0, 0), (0, 1), (1, 1), (1, 0))) - poly2 = Polygon(((-1, -1), (-1, 1), (1, 1), (1, -1))) - assert check_overlap(poly1, poly2) is True - - # If the polygons do not overlap, False is returned - poly2 = Polygon(((5, 5), (6, 5), (6, 6), (5, 6))) - assert check_overlap(poly1, poly2) is False - - -def test_get_border_lonlats_geos(): - """Test that correct methods are called in get_border_lonlats() with geos inputs.""" - from pyresample.gradient import get_border_lonlats - geo_def = AreaDefinition("", "", "", - "+proj=geos +h=1234567", 2, 2, [1, 2, 3, 4]) - with mock.patch("pyresample.gradient.get_geostationary_bounding_box_in_lonlats") as get_geostationary_bounding_box: - get_geostationary_bounding_box.return_value = 1, 2 - res = get_border_lonlats(geo_def) - assert res == (1, 2) - get_geostationary_bounding_box.assert_called_with(geo_def, 3600) - - -def test_get_border_lonlats(): - """Test that correct methods are called in get_border_lonlats().""" - from pyresample.boundary import SimpleBoundary - from pyresample.gradient import get_border_lonlats - lon_sides = SimpleBoundary(side1=np.array([1]), side2=np.array([2]), - side3=np.array([3]), side4=np.array([4])) - lat_sides = SimpleBoundary(side1=np.array([1]), side2=np.array([2]), - side3=np.array([3]), side4=np.array([4])) - geo_def = AreaDefinition("", "", "", - "+proj=lcc +lat_1=25 +lat_2=25", 2, 2, [1, 2, 3, 4]) - with mock.patch.object(geo_def, "get_boundary_lonlats") as get_boundary_lonlats: - get_boundary_lonlats.return_value = lon_sides, lat_sides - lon_b, lat_b = get_border_lonlats(geo_def) - assert np.all(lon_b == np.array([1, 2, 3, 4])) - assert np.all(lat_b == np.array([1, 2, 3, 4])) - - -@mock.patch('pyresample.gradient.Polygon') -@mock.patch('pyresample.gradient.get_border_lonlats') -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 - - @mock.patch('pyresample.gradient.one_step_gradient_search') def test_gradient_resample_data(one_step_gradient_search): """Test that one_step_gradient_search() is called with proper array shapes."""