def test_invoke_as_part_of_workflow(self): resource = get_resource('workflows/three_ops.json') workflow = Workflow.load(resource) step = WorkflowStep(workflow, resource, node_id='jojo_87') workflow = Workflow( OpMetaInfo('contains_jojo_87', has_monitor=True, inputs=OrderedDict(x={}), outputs=OrderedDict(y={}))) workflow.add_step(step) step.inputs.p.source = workflow.inputs.x workflow.outputs.y.source = step.outputs.q value_cache = ValueCache() workflow.inputs.x.value = 4 workflow.invoke(context=dict(value_cache=value_cache)) output_value = workflow.outputs.y.value self.assertEqual(output_value, 2 * (4 + 1) + 3 * (2 * (4 + 1))) self.assertEqual( value_cache, { 'jojo_87._child': { 'op1': { 'y': 5 }, 'op2': { 'b': 10 }, 'op3': { 'w': 40 } } })
def test_to_json_dict(self): resource = get_resource('workflows/three_ops.json') workflow = Workflow.load(resource) step = WorkflowStep(workflow, resource, node_id='jojo_87') actual_json_dict = step.to_json_dict() expected_json_text = """ { "id": "jojo_87", "workflow": "%s", "inputs": { "p": {} }, "outputs": { "q": {} } } """ % resource actual_json_text = json.dumps(actual_json_dict, indent=4) expected_json_dict = json.loads(expected_json_text) actual_json_dict = json.loads(actual_json_text) self.assertEqual(actual_json_dict, expected_json_dict, msg='\n%sexpected:\n%s\n%s\nbut got:\n%s\n' % (120 * '-', expected_json_text, 120 * '-', actual_json_text))
def test_to_json_dict(self): resource = get_resource('workflows/three_ops.json') workflow = Workflow.load(resource) step = WorkflowStep(workflow, resource, node_id='jojo_87') actual_json_dict = step.to_json_dict() expected_json_text = """ { "id": "jojo_87", "workflow": "%s", "inputs": { "p": {} }, "outputs": { "q": {} } } """ % resource actual_json_text = json.dumps(actual_json_dict, indent=4) expected_json_dict = json.loads(expected_json_text) actual_json_dict = json.loads(actual_json_text) self.assertEqual( actual_json_dict, expected_json_dict, msg='\n%sexpected:\n%s\n%s\nbut got:\n%s\n' % (120 * '-', expected_json_text, 120 * '-', actual_json_text))
def open(cls, base_dir: str) -> 'Workspace': if not os.path.isdir(cls.get_workspace_dir(base_dir)): raise WorkspaceError('Not a valid workspace: %s' % base_dir) try: workflow_file = cls.get_workflow_file(base_dir) workflow = Workflow.load(workflow_file) return Workspace(base_dir, workflow) except (IOError, OSError) as e: raise WorkspaceError(e)
def test_routing(self): from cate.core.workflow import Workflow import os.path workflow = Workflow.load( os.path.join(os.path.dirname(__file__), 'workflows', 'four_steps_chain.json')) actual_svg = workflow._repr_svg_() self._write_svg_html(actual_svg)
def test_invoke(self): resource = get_resource('workflows/three_ops.json') workflow = Workflow.load(resource) step = WorkflowStep(workflow, resource, node_id='jojo_87') value_cache = {} step.inputs.p.value = 3 step.invoke(context=dict(value_cache=value_cache)) output_value = step.outputs.q.value self.assertEqual(output_value, 2 * (3 + 1) + 3 * (2 * (3 + 1))) self.assertEqual(value_cache, {'op1': {'y': 4}, 'op2': {'b': 8}, 'op3': {'w': 32}})
def test_init(self): resource = get_resource('workflows/three_ops.json') workflow = Workflow.load(resource) step = WorkflowStep(workflow, resource, node_id='jojo_87') self.assertEqual(step.id, 'jojo_87') self.assertEqual(step.resource, resource) self.assertEqual(str(step), 'jojo_87 = cool_workflow(p=None) -> (q) [WorkflowStep]') self.assertEqual(repr(step), "WorkflowStep(Workflow('cool_workflow'), '%s', node_id='jojo_87')" % resource) self.assertIsNotNone(step.workflow) self.assertIn('p', step.workflow.inputs) self.assertIn('q', step.workflow.outputs)
def test_invoke_from_workflow(self): resource = get_resource('workflows/one_expr.json') workflow = Workflow.load(resource) a = 1.5 b = -2.6 c = 4.3 workflow.inputs.a.value = a workflow.inputs.b.value = b workflow.inputs.c.value = c workflow.invoke() output_value_x = workflow.outputs.x.value output_value_y = workflow.outputs.y.value self.assertEqual(output_value_x, 1 + 2 * a) self.assertEqual(output_value_y, 3 * b**2 + 4 * c**3)
def test_invoke_from_workflow(self): resource = get_resource('workflows/one_expr.json') workflow = Workflow.load(resource) a = 1.5 b = -2.6 c = 4.3 workflow.inputs.a.value = a workflow.inputs.b.value = b workflow.inputs.c.value = c workflow.invoke() output_value_x = workflow.outputs.x.value output_value_y = workflow.outputs.y.value self.assertEqual(output_value_x, 1 + 2 * a) self.assertEqual(output_value_y, 3 * b ** 2 + 4 * c ** 3)
def test_invoke_as_part_of_workflow(self): resource = get_resource('workflows/three_ops.json') workflow = Workflow.load(resource) step = WorkflowStep(workflow, resource, node_id='jojo_87') workflow = Workflow(OpMetaInfo('contains_jojo_87', has_monitor=True, inputs=OrderedDict(x={}), outputs=OrderedDict(y={}))) workflow.add_step(step) step.inputs.p.source = workflow.inputs.x workflow.outputs.y.source = step.outputs.q value_cache = ValueCache() workflow.inputs.x.value = 4 workflow.invoke(context=dict(value_cache=value_cache)) output_value = workflow.outputs.y.value self.assertEqual(output_value, 2 * (4 + 1) + 3 * (2 * (4 + 1))) self.assertEqual(value_cache, {'jojo_87._child': {'op1': {'y': 5}, 'op2': {'b': 10}, 'op3': {'w': 40}}})