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