Skip to content

Commit 754a399

Browse files
issue693 replace default by unset and combine enum options
1 parent 7712675 commit 754a399

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

openeo/internal/processes/parse.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
import copy
89
import json
910
import re
1011
import typing
@@ -49,9 +50,9 @@ def get_enum_options(self):
4950
for item in self.schema:
5051
if "enum" in item:
5152
if result is None:
52-
result = item["enum"]
53+
result = copy.deepcopy(item["enum"])
5354
else:
54-
raise ValueError("Multiple entries found for enum options.")
55+
result += item["enum"]
5556
elif isinstance(self.schema,dict):
5657
if "enum" in self.schema:
5758
result = self.schema["enum"]

openeo/rest/datacube.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,7 +2726,7 @@ def ard_normalized_radar_backscatter(
27262726
@openeo_process
27272727
def sar_backscatter(
27282728
self,
2729-
coefficient: Union[str, None] = "default",
2729+
coefficient: Union[str, None] = _UNSET,
27302730
elevation_model: Union[str, None] = None,
27312731
mask: bool = False,
27322732
contributing_area: bool = False,
@@ -2774,7 +2774,7 @@ def sar_backscatter(
27742774
)
27752775
schema = parameter.schema
27762776
coefficient_options = schema.get_enum_options() + [None]
2777-
if coefficient == "default":
2777+
if coefficient == _UNSET:
27782778
coefficient = parameter.default
27792779
except Exception as e:
27802780
log.warning(f"Failed to extract coefficient options for process `sar_backscatter`: {e}")
@@ -2786,7 +2786,7 @@ def sar_backscatter(
27862786
"gamma0-terrain",
27872787
None,
27882788
]
2789-
if coefficient == "default":
2789+
if coefficient == _UNSET:
27902790
coefficient = "gamma0-terrain"
27912791
if coefficient not in coefficient_options:
27922792
raise OpenEoClientException("Invalid `sar_backscatter` coefficient {c!r}. Should be one of {o}".format(

tests/internal/processes/test_parse.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,21 @@ def test_schema_accepts_geojson(schema, expected):
6363
Schema([{"type": "string", "enum": ["replicate", "reflect", "reflect_pixel", "wrap"]}, {"type": "number"}]),
6464
["replicate", "reflect", "reflect_pixel", "wrap"],
6565
),
66+
(
67+
Schema(
68+
[
69+
{"type": "string", "enum": ["replicate", "reflect"]},
70+
{"type": "number", "enum": ["reflect_pixel", "wrap"]},
71+
]
72+
),
73+
["replicate", "reflect", "reflect_pixel", "wrap"],
74+
),
6675
],
6776
)
6877
def test_get_enum_options(schema, expected):
69-
schema.get_enum_options()
7078
assert schema.get_enum_options() == expected
7179

7280

73-
def test_get_enum_options_error():
74-
schema = Schema(
75-
[
76-
{"type": "string", "enum": ["replicate", "reflect", "reflect_pixel", "wrap"]},
77-
{"type": "number", "enum": ["replicate", "reflect", "reflect_pixel", "wrap"]},
78-
]
79-
)
80-
with pytest.raises(ValueError):
81-
schema.get_enum_options()
82-
83-
8481
def test_parameter():
8582
p = Parameter.from_dict({
8683
"name": "foo",

0 commit comments

Comments
 (0)