def create_example_3_steps_workflow(cls): step1 = OpStep(op1, node_id='op1') step2 = OpStep(op2, node_id='op2') step3 = OpStep(op3, node_id='op3') workflow = Workflow(OpMetaInfo('myWorkflow', inputs=OrderedDict(p={}), outputs=OrderedDict(q={}))) workflow.add_steps(step1, step2, step3) step1.inputs.x.source = workflow.inputs.p step2.inputs.a.source = step1.outputs.y step3.inputs.u.source = step1.outputs.y step3.inputs.v.source = step2.outputs.b workflow.outputs.q.source = step3.outputs.w return step1, step2, step3, workflow
def create_example_3_steps_workflow(cls): step1 = OpStep(op1, node_id='op1') step2 = OpStep(op2, node_id='op2') step3 = OpStep(op3, node_id='op3') workflow = Workflow(OpMetaInfo('myWorkflow', inputs=OrderedDict(p={}), outputs=OrderedDict(q={}))) workflow.add_steps(step1, step2, step3) step1.inputs.x.source = workflow.inputs.p step2.inputs.a.source = step1.outputs.y step3.inputs.u.source = step1.outputs.y step3.inputs.v.source = step2.outputs.b workflow.outputs.q.source = step3.outputs.w return step1, step2, step3, workflow
def test_repr_svg(self): step1 = OpStep(Op1, node_id='op1') step2 = OpStep(Op2, node_id='op2') step3 = OpStep(Op3, node_id='op3') workflow = Workflow(OpMetaInfo('my_workflow', input_dict=OrderedDict(p={}), output_dict=OrderedDict(q={}))) workflow.add_steps(step1, step2, step3) step1.input.x.source = workflow.input.p step2.input.a.source = step1.output.y step3.input.u.source = step1.output.y step3.input.v.source = step2.output.b workflow.output.q.source = step3.output.w workflow_json = workflow._repr_svg_() # print('\n\n%s\n\n' % workflow_json) self.assertIsNotNone(workflow_json)
def test_resolve_source_ref(self): step1 = OpStep(op1, node_id='myop1') step2 = OpStep(op2, node_id='myop2') step2.inputs.a._source_ref = ('myop1', 'y') g = Workflow(OpMetaInfo('myWorkflow', has_monitor=True, inputs=OrderedDict(x={}), outputs=OrderedDict(b={}))) g.add_steps(step1, step2) step2.inputs.a.update_source() self.assertEqual(step2.inputs.a._source_ref, ('myop1', 'y')) self.assertIs(step2.inputs.a.source, step1.outputs.y) self.assertIs(step2.inputs.a.value, None)
def test_resolve_source_ref(self): step1 = OpStep(op1, node_id='myop1') step2 = OpStep(op2, node_id='myop2') step2.inputs.a._source_ref = ('myop1', 'y') g = Workflow(OpMetaInfo('myWorkflow', has_monitor=True, inputs=OrderedDict(x={}), outputs=OrderedDict(b={}))) g.add_steps(step1, step2) step2.inputs.a.update_source() self.assertEqual(step2.inputs.a._source_ref, ('myop1', 'y')) self.assertIs(step2.inputs.a.source, step1.outputs.y) self.assertIs(step2.inputs.a.value, None)
def test_to_json_dict(self): step1 = OpStep(op1, node_id='op1') step2 = OpStep(op2, node_id='op2') step3 = OpStep(op3, node_id='op3') workflow = Workflow( OpMetaInfo('my_workflow', inputs=OrderedDict(p={}), outputs=OrderedDict(q={}))) workflow.add_steps(step1, step2, step3) step1.inputs.x.source = workflow.inputs.p step2.inputs.a.source = step1.outputs.y step3.inputs.u.source = step1.outputs.y step3.inputs.v.source = step2.outputs.b workflow.outputs.q.source = step3.outputs.w step2.persistent = True workflow_dict = workflow.to_json_dict() expected_json_text = """ { "schema_version": 1, "qualified_name": "my_workflow", "header": {}, "inputs": { "p": {} }, "outputs": { "q": { "source": "op3.w" } }, "steps": [ { "id": "op1", "op": "tests.core.test_workflow.op1", "inputs": { "x": "my_workflow.p" } }, { "id": "op2", "persistent": true, "op": "tests.core.test_workflow.op2", "inputs": { "a": "op1.y" } }, { "id": "op3", "op": "tests.core.test_workflow.op3", "inputs": { "v": "op2.b", "u": "op1.y" } } ] } """ actual_json_text = json.dumps(workflow_dict, indent=4) expected_json_obj = json.loads(expected_json_text) actual_json_obj = json.loads(actual_json_text) self.assertEqual( actual_json_obj, expected_json_obj, msg='\nexpected:\n%s\n%s\nbut got:\n%s\n%s\n' % (120 * '-', expected_json_text, 120 * '-', actual_json_text))
def test_to_json_dict(self): step1 = OpStep(op1, node_id='op1') step2 = OpStep(op2, node_id='op2') step3 = OpStep(op3, node_id='op3') workflow = Workflow(OpMetaInfo('my_workflow', inputs=OrderedDict(p={}), outputs=OrderedDict(q={}))) workflow.add_steps(step1, step2, step3) step1.inputs.x.source = workflow.inputs.p step2.inputs.a.source = step1.outputs.y step3.inputs.u.source = step1.outputs.y step3.inputs.v.source = step2.outputs.b workflow.outputs.q.source = step3.outputs.w step2.persistent = True workflow_dict = workflow.to_json_dict() expected_json_text = """ { "schema_version": 1, "qualified_name": "my_workflow", "header": {}, "inputs": { "p": {} }, "outputs": { "q": { "source": "op3.w" } }, "steps": [ { "id": "op1", "op": "test.core.test_workflow.op1", "inputs": { "x": "my_workflow.p" } }, { "id": "op2", "persistent": true, "op": "test.core.test_workflow.op2", "inputs": { "a": "op1.y" } }, { "id": "op3", "op": "test.core.test_workflow.op3", "inputs": { "v": "op2.b", "u": "op1.y" } } ] } """ actual_json_text = json.dumps(workflow_dict, indent=4) expected_json_obj = json.loads(expected_json_text) actual_json_obj = json.loads(actual_json_text) self.assertEqual(actual_json_obj, expected_json_obj, msg='\nexpected:\n%s\n%s\nbut got:\n%s\n%s\n' % (120 * '-', expected_json_text, 120 * '-', actual_json_text))