Skip to content

Commit 2f9df8b

Browse files
committed
Simplify area slice tests with parametrize
1 parent e9f7fa0 commit 2f9df8b

1 file changed

Lines changed: 25 additions & 44 deletions

File tree

pyresample/test/test_geometry/test_area.py

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,20 @@ def test_get_array_indices_from_lonlat(self, create_test_area):
880880
assert (x__.data == x_expects).all()
881881
assert (y__.data == y_expects).all()
882882

883-
def test_get_slice_starts_stops(self, create_test_area):
883+
@pytest.mark.parametrize(
884+
"src_extent",
885+
[
886+
# Source and target have the same orientation
887+
(-5580248.477339745, -5571247.267842293, 5577248.074173927, 5580248.477339745),
888+
# Source is flipped in X direction
889+
(5577248.074173927, -5571247.267842293, -5580248.477339745, 5580248.477339745),
890+
# Source is flipped in Y direction
891+
(-5580248.477339745, 5580248.477339745, 5577248.074173927, -5571247.267842293),
892+
# Source is flipped in both X and Y directions
893+
(5577248.074173927, 5580248.477339745, -5580248.477339745, -5571247.267842293),
894+
]
895+
)
896+
def test_get_slice_starts_stops(self, create_test_area, src_extent):
884897
"""Check area slice end-points."""
885898
from pyresample.future.geometry._subset import _get_slice_starts_stops
886899
x_size = 3712
@@ -889,33 +902,9 @@ def test_get_slice_starts_stops(self, create_test_area):
889902
proj_dict = {'a': 6378169.0, 'b': 6356583.8, 'h': 35785831.0,
890903
'lon_0': 0.0, 'proj': 'geos', 'units': 'm'}
891904
target_area = create_test_area(proj_dict, x_size, y_size, area_extent)
892-
893-
# Expected result is the same for all cases
894-
expected = (3, 3709, 3, 3709)
895-
896-
# Source and target have the same orientation
897-
area_extent = (-5580248.477339745, -5571247.267842293, 5577248.074173927, 5580248.477339745)
898-
source_area = create_test_area(proj_dict, x_size, y_size, area_extent)
899-
res = _get_slice_starts_stops(source_area, target_area)
900-
assert res == expected
901-
902-
# Source is flipped in X direction
903-
area_extent = (5577248.074173927, -5571247.267842293, -5580248.477339745, 5580248.477339745)
904-
source_area = create_test_area(proj_dict, x_size, y_size, area_extent)
905-
res = _get_slice_starts_stops(source_area, target_area)
906-
assert res == expected
907-
908-
# Source is flipped in Y direction
909-
area_extent = (-5580248.477339745, 5580248.477339745, 5577248.074173927, -5571247.267842293)
910-
source_area = create_test_area(proj_dict, x_size, y_size, area_extent)
911-
res = _get_slice_starts_stops(source_area, target_area)
912-
assert res == expected
913-
914-
# Source is flipped in both X and Y directions
915-
area_extent = (5577248.074173927, 5580248.477339745, -5580248.477339745, -5571247.267842293)
916-
source_area = create_test_area(proj_dict, x_size, y_size, area_extent)
905+
source_area = create_test_area(proj_dict, x_size, y_size, src_extent)
917906
res = _get_slice_starts_stops(source_area, target_area)
918-
assert res == expected
907+
assert res == (3, 3709, 3, 3709)
919908

920909
def test_proj_str(self, create_test_area):
921910
"""Test the 'proj_str' property of AreaDefinition."""
@@ -1250,27 +1239,19 @@ def test_area_def_metadata_equality(self):
12501239
class TestMakeSliceDivisible:
12511240
"""Test the _make_slice_divisible."""
12521241

1253-
def test_make_slice_divisible(self):
1242+
@pytest.mark.parametrize(
1243+
("sli", "factor"),
1244+
[
1245+
(slice(10, 21), 2),
1246+
(slice(10, 23), 3),
1247+
(slice(10, 23), 5),
1248+
]
1249+
)
1250+
def test_make_slice_divisible(self, sli, factor):
12541251
"""Test that making area shape divisible by a given factor works."""
12551252
from pyresample.future.geometry._subset import _make_slice_divisible
12561253

12571254
# Divisible by 2
1258-
sli = slice(10, 21)
1259-
factor = 2
1260-
assert (sli.stop - sli.start) % factor != 0
1261-
res = _make_slice_divisible(sli, 1000, factor=factor)
1262-
assert (res.stop - res.start) % factor == 0
1263-
1264-
# Divisible by 3
1265-
sli = slice(10, 23)
1266-
factor = 3
1267-
assert (sli.stop - sli.start) % factor != 0
1268-
res = _make_slice_divisible(sli, 1000, factor=factor)
1269-
assert (res.stop - res.start) % factor == 0
1270-
1271-
# Divisible by 5
1272-
sli = slice(10, 23)
1273-
factor = 5
12741255
assert (sli.stop - sli.start) % factor != 0
12751256
res = _make_slice_divisible(sli, 1000, factor=factor)
12761257
assert (res.stop - res.start) % factor == 0

0 commit comments

Comments
 (0)