Skip to content

Commit 49f6c26

Browse files
committed
fixup! Issue #259/#453/#458 Fixup pyproj related test skips
1 parent cf57056 commit 49f6c26

File tree

3 files changed

+30
-66
lines changed

3 files changed

+30
-66
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"geopandas",
2828
"flake8>=5.0.0",
2929
"time_machine",
30-
"pyproj", # Pyproj is an optional, best-effort runtime dependency
30+
"pyproj", # Pyproj is an optional, best-effort runtime dependency # TODO #460 set a high enough minimum version when py3.6 support can be dropped
3131
]
3232

3333
docs_require = [

tests/rest/datacube/test_datacube100.py

Lines changed: 27 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
import textwrap
1414
from typing import Optional
1515

16+
import pyproj
1617
import pytest
1718
import requests
1819
import shapely.geometry
1920

2021
import openeo.metadata
2122
import openeo.processes
2223
from openeo.api.process import Parameter
24+
from openeo.capabilities import ComparableVersion
2325
from openeo.internal.graph_building import PGNode
2426
from openeo.internal.process_graph_visitor import ProcessGraphVisitException
2527
from openeo.internal.warnings import UserDeprecationWarning
@@ -182,12 +184,21 @@
182184
}
183185

184186

185-
CRS_VALUES_SUPPORTED_FOR_ALL_PYTHON_VERSIONS = [
186-
"EPSG:32631",
187-
"32631",
188-
32631,
189-
"+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs", # is also EPSG:32631, in proj format
190-
]
187+
def _get_normalizable_crs_inputs():
188+
"""
189+
Dynamic (proj version based) generation of supported CRS inputs (to normalize).
190+
:return:
191+
"""
192+
yield "EPSG:32631"
193+
yield 32631
194+
if pyproj.__version__ >= ComparableVersion("3.3.1"):
195+
# pyproj below 3.3.1 does not support int-like strings
196+
# TODO #460 this skip is only necessary for python 3.6 and lower
197+
yield "32631"
198+
yield "+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs" # is also EPSG:32631, in proj format
199+
if pyproj.__version__ >= ComparableVersion("3.1.0"):
200+
# WKT2 format support requires pyproj 3.1.0 or higher
201+
yield WKT2_FOR_EPSG23631
191202

192203

193204
def _get_leaf_node(cube: DataCube) -> dict:
@@ -405,7 +416,7 @@ def test_aggregate_spatial_types(con100: Connection, polygon, expected_geometrie
405416
}
406417

407418

408-
@pytest.mark.parametrize("crs", CRS_VALUES_SUPPORTED_FOR_ALL_PYTHON_VERSIONS)
419+
@pytest.mark.parametrize("crs", _get_normalizable_crs_inputs())
409420
def test_aggregate_spatial_with_crs(con100: Connection, recwarn, crs: str):
410421
img = con100.load_collection("S2")
411422
polygon = shapely.geometry.box(0, 0, 1, 1)
@@ -430,36 +441,10 @@ def test_aggregate_spatial_with_crs(con100: Connection, recwarn, crs: str):
430441
}
431442

432443

433-
@pytest.mark.skipif(sys.version_info < (3, 7), reason="WKT2 format not supported by pyproj 3.0 / python 3.6")
434-
def test_aggregate_spatial_with_crs_as_wkt(con100: Connection, recwarn):
435-
"""Separate test coverage for WKT, so we can skip it for Python3.6"""
436-
crs = WKT2_FOR_EPSG23631
437-
img = con100.load_collection("S2")
438-
polygon = shapely.geometry.box(0, 0, 1, 1)
439-
masked = img.aggregate_spatial(geometries=polygon, reducer="mean", crs=crs)
440-
warnings = [str(w.message) for w in recwarn]
441-
assert f"Geometry with non-Lon-Lat CRS {crs!r} is only supported by specific back-ends." in warnings
442-
assert sorted(masked.flat_graph().keys()) == ["aggregatespatial1", "loadcollection1"]
443-
assert masked.flat_graph()["aggregatespatial1"] == {
444-
"process_id": "aggregate_spatial",
445-
"arguments": {
446-
"data": {"from_node": "loadcollection1"},
447-
"geometries": {
448-
"type": "Polygon",
449-
"coordinates": (((1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0)),),
450-
"crs": {"properties": {"name": "EPSG:32631"}, "type": "name"},
451-
},
452-
"reducer": {
453-
"process_graph": {
454-
"mean1": {"process_id": "mean", "arguments": {"data": {"from_parameter": "data"}}, "result": True}
455-
}
456-
},
457-
},
458-
"result": True,
459-
}
460-
461-
462-
@pytest.mark.skipif(sys.version_info < (3, 8), reason="PROJJSON format not supported by pyproj 3.2 / python < v3.8")
444+
@pytest.mark.skipif(
445+
pyproj.__version__ < ComparableVersion("3.3.0"),
446+
reason="PROJJSON format support requires pyproj 3.3.0 or higher",
447+
)
463448
@pytest.mark.parametrize("crs", [PROJJSON_FOR_EPSG23631, json.dumps(PROJJSON_FOR_EPSG23631)])
464449
def test_aggregate_spatial_with_crs_as_projjson(con100: Connection, recwarn, crs):
465450
"""Separate test coverage for PROJJSON, so we can skip it for Python versions below 3.8"""
@@ -686,7 +671,7 @@ def test_mask_polygon_types(con100: Connection, polygon, expected_mask):
686671
}
687672

688673

689-
@pytest.mark.parametrize("crs", CRS_VALUES_SUPPORTED_FOR_ALL_PYTHON_VERSIONS)
674+
@pytest.mark.parametrize("crs", _get_normalizable_crs_inputs())
690675
def test_mask_polygon_with_crs(con100: Connection, recwarn, crs: str):
691676
img = con100.load_collection("S2")
692677
polygon = shapely.geometry.box(0, 0, 1, 1)
@@ -709,31 +694,10 @@ def test_mask_polygon_with_crs(con100: Connection, recwarn, crs: str):
709694
}
710695

711696

712-
@pytest.mark.skipif(sys.version_info < (3, 7), reason="WKT2 format not supported by pyproj 3.0 / python 3.6")
713-
def test_mask_polygon_with_crs_as_wkt(con100: Connection, recwarn):
714-
"""Separate test coverage for WKT, so we can skip it for Python3.6"""
715-
crs = WKT2_FOR_EPSG23631
716-
img = con100.load_collection("S2")
717-
polygon = shapely.geometry.box(0, 0, 1, 1)
718-
masked = img.mask_polygon(mask=polygon, srs=crs)
719-
warnings = [str(w.message) for w in recwarn]
720-
assert f"Geometry with non-Lon-Lat CRS {crs!r} is only supported by specific back-ends." in warnings
721-
assert sorted(masked.flat_graph().keys()) == ["loadcollection1", "maskpolygon1"]
722-
assert masked.flat_graph()["maskpolygon1"] == {
723-
"process_id": "mask_polygon",
724-
"arguments": {
725-
"data": {"from_node": "loadcollection1"},
726-
"mask": {
727-
"type": "Polygon", "coordinates": (((1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0)),),
728-
# All listed test inputs for crs should be converted to "EPSG:32631"
729-
"crs": {"type": "name", "properties": {"name": "EPSG:32631"}},
730-
},
731-
},
732-
"result": True,
733-
}
734-
735-
736-
@pytest.mark.skipif(sys.version_info < (3, 8), reason="PROJJSON format not supported by pyproj 3.2 / python < v3.8")
697+
@pytest.mark.skipif(
698+
pyproj.__version__ < ComparableVersion("3.3.0"),
699+
reason="PROJJSON format support requires pyproj 3.3.0 or higher",
700+
)
737701
@pytest.mark.parametrize("crs", [PROJJSON_FOR_EPSG23631, json.dumps(PROJJSON_FOR_EPSG23631)])
738702
def test_mask_polygon_with_crs_as_projjson(con100: Connection, recwarn, crs):
739703
"""Separate test coverage for PROJJSON, so we can skip it for Python versions below 3.8"""

tests/test_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ def test_normalize_crs_without_pyproj_accept_non_epsg_string(self, caplog):
935935
@pytest.mark.skipif(
936936
# TODO #460 this skip is only necessary for python 3.6 and lower
937937
pyproj.__version__ < ComparableVersion("3.1.0"),
938-
reason="WKT2 format support requires pypro 3.1.0 or higher",
938+
reason="WKT2 format support requires pyproj 3.1.0 or higher",
939939
)
940940
def test_normalize_crs_succeeds_with_wkt2_input(self):
941941
"""Test can handle WKT2 strings.
@@ -1020,7 +1020,7 @@ def test_normalize_crs_without_pyproj_succeeds_with_wkt2_input(self):
10201020
@pytest.mark.skipif(
10211021
# TODO #460 this skip is only necessary for python 3.6 and lower
10221022
pyproj.__version__ < ComparableVersion("3.3.0"),
1023-
reason="PROJJSON format requires pyproj 3.3.0 or higher",
1023+
reason="PROJJSON format support requires pyproj 3.3.0 or higher",
10241024
)
10251025
def test_normalize_crs_succeeds_with_correct_projjson(
10261026
self,

0 commit comments

Comments
 (0)