Skip to content

Commit ea016e5

Browse files
committed
Add test for executorlib interface
1 parent c36bc71 commit ea016e5

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/test_executorlib.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import unittest
2+
from executorlib import SingleNodeExecutor
3+
from python_workflow_definition.executorlib import load_workflow_json
4+
5+
function_str = """
6+
def get_prod_and_div(x, y):
7+
return {"prod": x * y, "div": x / y}
8+
9+
10+
def get_sum(x, y):
11+
return x + y
12+
13+
14+
def get_square(x):
15+
return x ** 2
16+
"""
17+
18+
workflow_str = """
19+
{
20+
"version": "0.1.0",
21+
"nodes": [
22+
{"id": 0, "type": "function", "value": "workflow.get_prod_and_div"},
23+
{"id": 1, "type": "function", "value": "workflow.get_sum"},
24+
{"id": 2, "type": "function", "value": "workflow.get_square"},
25+
{"id": 3, "type": "input", "value": 1, "name": "x"},
26+
{"id": 4, "type": "input", "value": 2, "name": "y"},
27+
{"id": 5, "type": "output", "name": "result"}
28+
],
29+
"edges": [
30+
{"target": 0, "targetPort": "x", "source": 3, "sourcePort": null},
31+
{"target": 0, "targetPort": "y", "source": 4, "sourcePort": null},
32+
{"target": 1, "targetPort": "x", "source": 0, "sourcePort": "prod"},
33+
{"target": 1, "targetPort": "y", "source": 0, "sourcePort": "div"},
34+
{"target": 2, "targetPort": "x", "source": 1, "sourcePort": null},
35+
{"target": 5, "targetPort": null, "source": 2, "sourcePort": null}
36+
]
37+
}"""
38+
39+
class TestExecutorlib(unittest.TestCase):
40+
def test_executorlib(self):
41+
with open("workflow.py", "w") as f:
42+
f.write(function_str)
43+
44+
with open("workflow.json", "w") as f:
45+
f.write(workflow_str)
46+
47+
with SingleNodeExecutor(max_workers=1) as exe:
48+
self.assertEqual(load_workflow_json(file_name="workflow.json", exe=exe).result(), 6.25)

0 commit comments

Comments
 (0)