Skip to content

Commit

Permalink
Add tests for build_child_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Aug 9, 2023
1 parent b666ed9 commit 5bb0da8
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/rest/datacube/test_base_datacube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from openeo.internal.graph_building import PGNode
from openeo.rest._datacube import build_child_callback, UDF


def test_build_child_callback_str():
pg = build_child_callback("add", parent_parameters=["x", "y"])
assert isinstance(pg["process_graph"], PGNode)
assert pg["process_graph"].flat_graph() == {
"add1": {
"process_id": "add",
"arguments": {"x": {"from_parameter": "x"}, "y": {"from_parameter": "y"}},
"result": True,
}
}


def test_build_child_callback_pgnode():
pg = build_child_callback(
PGNode(process_id="add", arguments={"x": {"from_parameter": "x"}, "y": 1}), parent_parameters=["x"]
)
assert isinstance(pg["process_graph"], PGNode)
assert pg["process_graph"].flat_graph() == {
"add1": {
"process_id": "add",
"arguments": {"x": {"from_parameter": "x"}, "y": 1},
"result": True,
}
}


def test_build_child_callback_lambda():
pg = build_child_callback(lambda x: x + 1, parent_parameters=["x"])
assert isinstance(pg["process_graph"], PGNode)
assert pg["process_graph"].flat_graph() == {
"add1": {
"process_id": "add",
"arguments": {"x": {"from_parameter": "x"}, "y": 1},
"result": True,
}
}


def test_build_child_callback_udf():
pg = build_child_callback(UDF(code="def fun(x):\n return x + 1", runtime="Python"), parent_parameters=["data"])
assert isinstance(pg["process_graph"], PGNode)
assert pg["process_graph"].flat_graph() == {
"runudf1": {
"process_id": "run_udf",
"arguments": {
"data": {"from_parameter": "data"},
"runtime": "Python",
"udf": "def fun(x):\n return x + 1",
},
"result": True,
}
}

0 comments on commit 5bb0da8

Please sign in to comment.