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