Skip to content

Commit 5bb0da8

Browse files
committed
Add tests for build_child_callback
1 parent b666ed9 commit 5bb0da8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from openeo.internal.graph_building import PGNode
2+
from openeo.rest._datacube import build_child_callback, UDF
3+
4+
5+
def test_build_child_callback_str():
6+
pg = build_child_callback("add", parent_parameters=["x", "y"])
7+
assert isinstance(pg["process_graph"], PGNode)
8+
assert pg["process_graph"].flat_graph() == {
9+
"add1": {
10+
"process_id": "add",
11+
"arguments": {"x": {"from_parameter": "x"}, "y": {"from_parameter": "y"}},
12+
"result": True,
13+
}
14+
}
15+
16+
17+
def test_build_child_callback_pgnode():
18+
pg = build_child_callback(
19+
PGNode(process_id="add", arguments={"x": {"from_parameter": "x"}, "y": 1}), parent_parameters=["x"]
20+
)
21+
assert isinstance(pg["process_graph"], PGNode)
22+
assert pg["process_graph"].flat_graph() == {
23+
"add1": {
24+
"process_id": "add",
25+
"arguments": {"x": {"from_parameter": "x"}, "y": 1},
26+
"result": True,
27+
}
28+
}
29+
30+
31+
def test_build_child_callback_lambda():
32+
pg = build_child_callback(lambda x: x + 1, parent_parameters=["x"])
33+
assert isinstance(pg["process_graph"], PGNode)
34+
assert pg["process_graph"].flat_graph() == {
35+
"add1": {
36+
"process_id": "add",
37+
"arguments": {"x": {"from_parameter": "x"}, "y": 1},
38+
"result": True,
39+
}
40+
}
41+
42+
43+
def test_build_child_callback_udf():
44+
pg = build_child_callback(UDF(code="def fun(x):\n return x + 1", runtime="Python"), parent_parameters=["data"])
45+
assert isinstance(pg["process_graph"], PGNode)
46+
assert pg["process_graph"].flat_graph() == {
47+
"runudf1": {
48+
"process_id": "run_udf",
49+
"arguments": {
50+
"data": {"from_parameter": "data"},
51+
"runtime": "Python",
52+
"udf": "def fun(x):\n return x + 1",
53+
},
54+
"result": True,
55+
}
56+
}

0 commit comments

Comments
 (0)