def test_from_json_dict_invalids(self): json_dict = json.loads('{"header": {}}') with self.assertRaises(ValueError) as cm: Workflow.from_json_dict(json_dict) self.assertEqual( str(cm.exception), 'missing mandatory property "qualified_name" in Workflow-JSON')
def test_from_json_dict_empty(self): json_dict = json.loads('{"qualified_name": "hello"}') workflow = Workflow.from_json_dict(json_dict) self.assertEqual(workflow.id, 'hello')
def test_from_json_dict(self): workflow_json_text = """ { "qualified_name": "my_workflow", "header": { "description": "My workflow is not too bad." }, "inputs": { "p": {"description": "Input 'p'"} }, "outputs": { "q": {"source": "op3.w", "description": "Output 'q'"} }, "steps": [ { "id": "op1", "op": "tests.core.test_workflow.op1", "inputs": { "x": { "source": ".p" } } }, { "id": "op2", "op": "tests.core.test_workflow.op2", "inputs": { "a": {"source": "op1"} } }, { "id": "op3", "persistent": true, "op": "tests.core.test_workflow.op3", "inputs": { "u": {"source": "op1.y"}, "v": {"source": "op2.b"} } } ] } """ workflow_json_dict = json.loads(workflow_json_text) workflow = Workflow.from_json_dict(workflow_json_dict) self.assertIsNotNone(workflow) self.assertEqual(workflow.id, "my_workflow") self.assertEqual(workflow.op_meta_info.qualified_name, workflow.id) self.assertEqual(workflow.op_meta_info.header, dict(description="My workflow is not too bad.")) self.assertEqual(len(workflow.op_meta_info.inputs), 1) self.assertEqual(len(workflow.op_meta_info.outputs), 1) self.assertEqual(workflow.op_meta_info.inputs['p'], dict(description="Input 'p'")) self.assertEqual(workflow.op_meta_info.outputs['q'], dict(source="op3.w", description="Output 'q'")) self.assertEqual(len(workflow.inputs), 1) self.assertEqual(len(workflow.outputs), 1) self.assertIn('p', workflow.inputs) self.assertIn('q', workflow.outputs) self.assertEqual(len(workflow.steps), 3) step1 = workflow.steps[0] step2 = workflow.steps[1] step3 = workflow.steps[2] self.assertEqual(step1.id, 'op1') self.assertEqual(step2.id, 'op2') self.assertEqual(step3.id, 'op3') self.assertIs(step1.inputs.x.source, workflow.inputs.p) self.assertIs(step2.inputs.a.source, step1.outputs.y) self.assertIs(step3.inputs.u.source, step1.outputs.y) self.assertIs(step3.inputs.v.source, step2.outputs.b) self.assertIs(workflow.outputs.q.source, step3.outputs.w) self.assertEqual(step1.persistent, False) self.assertEqual(step2.persistent, False) self.assertEqual(step3.persistent, True)
def from_json_dict(cls, json_dict): base_dir = json_dict.get('base_dir', None) workflow_json = json_dict.get('workflow', {}) is_modified = json_dict.get('is_modified', False) workflow = Workflow.from_json_dict(workflow_json) return Workspace(base_dir, workflow, is_modified=is_modified)
def test_from_json_dict_invalids(self): json_dict = json.loads('{"header": {}}') with self.assertRaises(ValueError) as cm: Workflow.from_json_dict(json_dict) self.assertEqual(str(cm.exception), 'missing mandatory property "qualified_name" in Workflow-JSON')
def test_from_json_dict_empty(self): json_dict = json.loads('{"qualified_name": "hello"}') workflow = Workflow.from_json_dict(json_dict) self.assertEqual(workflow.id, 'hello')
def test_from_json_dict(self): workflow_json_text = """ { "qualified_name": "my_workflow", "header": { "description": "My workflow is not too bad." }, "inputs": { "p": {"description": "Input 'p'"} }, "outputs": { "q": {"source": "op3.w", "description": "Output 'q'"} }, "steps": [ { "id": "op1", "op": "test.core.test_workflow.op1", "inputs": { "x": { "source": ".p" } } }, { "id": "op2", "op": "test.core.test_workflow.op2", "inputs": { "a": {"source": "op1"} } }, { "id": "op3", "persistent": true, "op": "test.core.test_workflow.op3", "inputs": { "u": {"source": "op1.y"}, "v": {"source": "op2.b"} } } ] } """ workflow_json_dict = json.loads(workflow_json_text) workflow = Workflow.from_json_dict(workflow_json_dict) self.assertIsNotNone(workflow) self.assertEqual(workflow.id, "my_workflow") self.assertEqual(workflow.op_meta_info.qualified_name, workflow.id) self.assertEqual(workflow.op_meta_info.header, dict(description="My workflow is not too bad.")) self.assertEqual(len(workflow.op_meta_info.inputs), 1) self.assertEqual(len(workflow.op_meta_info.outputs), 1) self.assertEqual(workflow.op_meta_info.inputs['p'], dict(description="Input 'p'")) self.assertEqual(workflow.op_meta_info.outputs['q'], dict(source="op3.w", description="Output 'q'")) self.assertEqual(len(workflow.inputs), 1) self.assertEqual(len(workflow.outputs), 1) self.assertIn('p', workflow.inputs) self.assertIn('q', workflow.outputs) self.assertEqual(len(workflow.steps), 3) step1 = workflow.steps[0] step2 = workflow.steps[1] step3 = workflow.steps[2] self.assertEqual(step1.id, 'op1') self.assertEqual(step2.id, 'op2') self.assertEqual(step3.id, 'op3') self.assertIs(step1.inputs.x.source, workflow.inputs.p) self.assertIs(step2.inputs.a.source, step1.outputs.y) self.assertIs(step3.inputs.u.source, step1.outputs.y) self.assertIs(step3.inputs.v.source, step2.outputs.b) self.assertIs(workflow.outputs.q.source, step3.outputs.w) self.assertEqual(step1.persistent, False) self.assertEqual(step2.persistent, False) self.assertEqual(step3.persistent, True)