From fd9fb5577b1c6c1e620448d5ce4f80d94dbc5f32 Mon Sep 17 00:00:00 2001 From: Gerald Walter Irsiegler Date: Wed, 3 Jan 2024 10:24:41 +0100 Subject: [PATCH] Fix: Allow integer values for crs parsing in Bounding Box (#79) Co-authored-by: Gerald Walter Irsiegler --- openeo_pg_parser_networkx/pg_schema.py | 6 +++--- pyproject.toml | 2 +- tests/test_pg_parser.py | 22 +++++++++++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/openeo_pg_parser_networkx/pg_schema.py b/openeo_pg_parser_networkx/pg_schema.py index 994e237..d68a73f 100644 --- a/openeo_pg_parser_networkx/pg_schema.py +++ b/openeo_pg_parser_networkx/pg_schema.py @@ -110,7 +110,7 @@ class PGEdgeType(str, Enum): def parse_crs(v) -> pyproj.CRS: - if v is None or v.strip() == "": + if not isinstance(v, int) and (v is None or v.strip() == ""): return DEFAULT_CRS else: try: @@ -122,7 +122,7 @@ def parse_crs(v) -> pyproj.CRS: raise e -def crs_validator(field: str) -> classmethod: +def crs_validator(field: Union[str, int]) -> classmethod: decorator = validator(field, allow_reuse=True, pre=True, always=True) validator_func = decorator(parse_crs) return validator_func @@ -135,7 +135,7 @@ class BoundingBox(BaseModel, arbitrary_types_allowed=True): south: float base: Optional[float] height: Optional[float] - crs: Optional[str] + crs: Optional[Union[str, int]] # validators _parse_crs: classmethod = crs_validator('crs') diff --git a/pyproject.toml b/pyproject.toml index 904da81..188a577 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "openeo-pg-parser-networkx" -version = "2023.11.0" +version = "2024.1.1" description = "Parse OpenEO process graphs from JSON to traversible Python objects." authors = ["Lukas Weidenholzer ", "Sean Hoyal ", "Valentina Hutter ", "Gerald Irsiegler "] diff --git a/tests/test_pg_parser.py b/tests/test_pg_parser.py index 1391d3e..ccc45d3 100644 --- a/tests/test_pg_parser.py +++ b/tests/test_pg_parser.py @@ -121,9 +121,15 @@ def test_bounding_box(get_process_graph_with_args): assert parsed_arg.crs == pyproj.CRS.from_user_input('EPSG:2025').to_wkt() +def test_pydantic_loading(): + test_extent = {'west': 0, 'east': 10, 'south': 0, 'north': 10} + test_bb = BoundingBox(**test_extent) + assert test_bb.crs == DEFAULT_CRS + + def test_bounding_box_no_crs(get_process_graph_with_args): pg = get_process_graph_with_args( - {'spatial_extent': {'west': 0, 'east': 10, 'south': 0, 'north': 10, 'crs': ""}} + {'spatial_extent': {'west': 0, 'east': 10, 'south': 0, 'north': 10}} ) parsed_arg = ( ProcessGraph.parse_obj(pg) @@ -153,6 +159,20 @@ def test_bounding_box_with_faulty_crs(get_process_graph_with_args): ] +def test_bounding_box_int_crs(get_process_graph_with_args): + pg = get_process_graph_with_args( + {'spatial_extent': {'west': 0, 'east': 10, 'south': 0, 'north': 10, 'crs': 4326}} + ) + parsed_arg = ( + ProcessGraph.parse_obj(pg) + .process_graph[TEST_NODE_KEY] + .arguments["spatial_extent"] + ) + assert isinstance(parsed_arg, BoundingBox) + assert isinstance(parsed_arg.crs, str) + assert parsed_arg.crs == DEFAULT_CRS + + @pytest.mark.skip( reason="Not passing because of https://github.com/developmentseed/geojson-pydantic/issues/92" )