Skip to content

Commit cf57056

Browse files
committed
Issue #259/#453/#458 Fixup pyproj related test skips
Skip based on pyproj version iso python version (allows testing the skips on higher python versions too)
1 parent b2a0e00 commit cf57056

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

openeo/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def normalize_crs(crs: Any, *, use_pyproj: bool = True) -> Union[None, int, str]
677677
# Convert back to EPSG int or WKT2 string
678678
crs = crs_obj.to_epsg() or crs_obj.to_wkt()
679679
except pyproj.ProjError as e:
680-
raise ValueError(f"Failed to normalize CRS data with pyproj: {crs}") from e
680+
raise ValueError(f"Failed to normalize CRS data with pyproj: {crs!r}") from e
681681
else:
682682
# Best effort simple validation/normalization
683683
if isinstance(crs, int) and crs > 0:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"geopandas",
2828
"flake8>=5.0.0",
2929
"time_machine",
30+
"pyproj", # Pyproj is an optional, best-effort runtime dependency
3031
]
3132

3233
docs_require = [

tests/test_util.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import unittest.mock as mock
99
from typing import List, Union
1010

11+
import pyproj
1112
import pytest
1213
import shapely.geometry
1314

15+
from openeo.capabilities import ComparableVersion
1416
from openeo.util import (
1517
BBoxDict,
1618
ContextTimer,
@@ -891,6 +893,10 @@ class TestNormalizeCrs:
891893
)
892894
def test_normalize_crs_succeeds_with_correct_crses(self, epsg_input, expected):
893895
"""Happy path, values that are allowed"""
896+
if isinstance(epsg_input, str) and epsg_input.isnumeric() and pyproj.__version__ < ComparableVersion("3.3.1"):
897+
# TODO #460 this skip is only necessary for python 3.6 and lower
898+
pytest.skip("pyproj below 3.3.1 does not support int-like strings")
899+
894900
assert normalize_crs(epsg_input) == expected
895901

896902
@pytest.mark.parametrize(
@@ -926,23 +932,22 @@ def test_normalize_crs_without_pyproj_accept_non_epsg_string(self, caplog):
926932
in caplog.text
927933
)
928934

929-
@pytest.mark.skipif(sys.version_info < (3, 7), reason="WKT2 format not supported by pyproj 3.0 / python 3.6")
935+
@pytest.mark.skipif(
936+
# TODO #460 this skip is only necessary for python 3.6 and lower
937+
pyproj.__version__ < ComparableVersion("3.1.0"),
938+
reason="WKT2 format support requires pypro 3.1.0 or higher",
939+
)
930940
def test_normalize_crs_succeeds_with_wkt2_input(self):
931941
"""Test can handle WKT2 strings.
932942
933943
We need to support WKT2:
934944
See also https://github.com/Open-EO/openeo-processes/issues/58
935-
936-
937-
WARNING:
938-
=======
939-
940-
Older versions of pyproj do not support this format.
941-
In particular, pyproj 3.0 which is the version we get on python 3.6, would
942-
fail on this test, and is marked with a skipif for that reason.
943945
"""
944946
assert normalize_crs(self.WKT2_FOR_EPSG32631) == 32631
945947

948+
def test_normalize_crs_without_pyproj_succeeds_with_wkt2_input(self):
949+
assert normalize_crs(self.WKT2_FOR_EPSG32631, use_pyproj=False) == self.WKT2_FOR_EPSG32631
950+
946951
PROJJSON_FOR_EPSG32631 = {
947952
"$schema": "https://proj.org/schemas/v0.4/projjson.schema.json",
948953
"type": "ProjectedCRS",
@@ -1013,7 +1018,9 @@ def test_normalize_crs_succeeds_with_wkt2_input(self):
10131018
}
10141019

10151020
@pytest.mark.skipif(
1016-
sys.version_info < (3, 8), reason="PROJJSON format not supported by pyproj v3.2 / python < v3.8"
1021+
# TODO #460 this skip is only necessary for python 3.6 and lower
1022+
pyproj.__version__ < ComparableVersion("3.3.0"),
1023+
reason="PROJJSON format requires pyproj 3.3.0 or higher",
10171024
)
10181025
def test_normalize_crs_succeeds_with_correct_projjson(
10191026
self,

0 commit comments

Comments
 (0)