Skip to content

Commit

Permalink
issue #76 add rules for top level process merging
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenVerstraelen committed Nov 24, 2022
1 parent 651a557 commit ebf7b24
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/openeo_aggregator/metadata/merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ def merge_process_metadata(self, by_backend: Dict[str, dict]) -> dict:
merged, "categories", self._merge_process_categories(by_backend=by_backend)
)

# TODO: merge "deprecated" field
# TODO: merge "experimental" field
# TODO: merge "examples" field
# TODO: merge "links" field
merged["deprecated"] = any(v for v in getter.get("deprecated") if v is True)

This comment has been minimized.

Copy link
@soxofaan

soxofaan Nov 24, 2022

Member

FYI: this is quite reduntantly written

any(x for x in items if x is True)
is basically equivalent with any(x for x in items if x)
is equivalent with any(x for x in items)
is equivalent with any(items)

This comment has been minimized.

Copy link
@soxofaan

soxofaan Nov 24, 2022

Member

addressed in d323710

merged["experimental"] = any(v for v in getter.get("experimental") if v is True)
merged["examples"] = list(set(getter.get("examples")))

This comment has been minimized.

Copy link
@soxofaan

soxofaan Nov 24, 2022

Member

This won't work: getter.get("examples") returns an iterator of lists, you want to concatenate these instead of a 2D list

This comment has been minimized.

Copy link
@soxofaan

soxofaan Nov 24, 2022

Member

addressed in d323710

merged["links"] = list(set(getter.get("links")))

return merged

Expand Down
56 changes: 56 additions & 0 deletions tests/metadata/test_merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def test_merge_processes_minimal(self, merger, reporter):
"parameters": [],
"returns": {"schema": {}},
"federation:backends": ["b1", "b2"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': [],
}
}
assert reporter.logs == []
Expand All @@ -44,6 +48,10 @@ def test_merge_process_minimal(self, merger, reporter):
"parameters": [],
"returns": {"schema": {}},
"federation:backends": ["b1", "b2"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': []
}
assert reporter.logs == []

Expand All @@ -61,6 +69,10 @@ def test_merge_process_returns(self, merger, reporter):
"parameters": [],
"returns": {"schema": {"type": "number"}},
"federation:backends": ["b1", "b2"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': []
}
assert reporter.logs == []

Expand All @@ -78,6 +90,10 @@ def test_merge_process_returns_difference(self, merger, reporter):
"parameters": [],
"returns": {"schema": {"type": "number"}},
"federation:backends": ["b1", "b2"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': []
}
assert reporter.logs == [
{
Expand Down Expand Up @@ -127,6 +143,10 @@ def test_merge_process_exceptions(self, merger, reporter):
"OverflowError": {"message": "Jeez"},
},
"federation:backends": ["b1", "b2"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': []
}
assert reporter.logs == []

Expand All @@ -151,6 +171,10 @@ def test_merge_process_exceptions_invalid(self, merger, reporter):
"returns": {"schema": {}},
"exceptions": {"MathError": {"message": "Nope"}},
"federation:backends": ["b1", "b2"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': []
}
assert reporter.logs == [
{
Expand All @@ -176,6 +200,10 @@ def test_merge_process_categories(self, merger, reporter):
"returns": {"schema": {}},
"categories": ["Math", "Maths"],
"federation:backends": ["b1", "b2"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': []
}
assert reporter.logs == []

Expand All @@ -194,6 +222,10 @@ def test_merge_process_categories_invalid(self, merger, reporter):
"returns": {"schema": {}},
"categories": ["Math"],
"federation:backends": ["b1", "b2"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': []
}
assert reporter.logs == [
{
Expand Down Expand Up @@ -228,6 +260,10 @@ def test_merge_process_parameters_basic(self, merger, reporter):
],
"returns": {"schema": {}},
"federation:backends": ["b1", "b2"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': []
}
assert reporter.logs == []

Expand All @@ -250,6 +286,10 @@ def test_merge_process_parameters_invalid(self, merger, reporter):
{"description": "x", "name": "x", "schema": {"type": "number"}}
],
"returns": {"schema": {}},
'deprecated': False,
'experimental': False,
'examples': [],
'links': []
}
assert reporter.logs == [
{
Expand Down Expand Up @@ -286,6 +326,10 @@ def test_merge_process_parameters_invalid_listing(self, merger, reporter):
{"description": "x", "name": "x", "schema": {"type": "number"}}
],
"returns": {"schema": {}},
'deprecated': False,
'experimental': False,
'examples': [],
'links': [],
}
assert reporter.logs == [
{
Expand Down Expand Up @@ -339,6 +383,10 @@ def test_merge_process_parameters_differences(self, merger, reporter):
],
"returns": {"schema": {}},
"federation:backends": ["b1", "b2", "b3"],
'deprecated': False,
'experimental': False,
'examples': [],
'links': [],
}
assert reporter.logs == [
{
Expand Down Expand Up @@ -422,6 +470,10 @@ def test_merge_process_parameters_recursive(self, merger, reporter):
}
],
"returns": {"schema": {}},
"experimental": False,
"deprecated": False,
"links": [],
"examples": [],
"federation:backends": ["b1", "b2"],
}
assert reporter.logs == []
Expand Down Expand Up @@ -523,6 +575,10 @@ def test_merge_process_parameters_recursive2(self, merger, reporter):
],
"returns": {"schema": {"type": "number"}},
"summary": "Count the number of elements",
'deprecated': False,
'experimental': False,
'examples': [],
'links': [],
}

assert reporter.logs == []
Expand Down

0 comments on commit ebf7b24

Please sign in to comment.