Example #1
0
    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))
Example #2
0
    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))
Example #3
0
    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}})
Example #4
0
    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}})
Example #5
0
    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
                    }
                }
            })
Example #6
0
    def test_from_json_dict(self):
        resource = get_resource('workflows/three_ops.json')
        json_text = """
        {
            "id": "workflow_ref_89",
            "workflow": "%s",
            "inputs": {
                "p": {"value": 2.8}
            }
        }
        """ % resource

        json_dict = json.loads(json_text)

        step = WorkflowStep.from_json_dict(json_dict)

        self.assertIsInstance(step, WorkflowStep)
        self.assertEqual(step.id, "workflow_ref_89")
        self.assertEqual(step.resource, resource)
        self.assertIn('p', step.inputs)
        self.assertIn('q', step.outputs)
        self.assertEqual(step.inputs.p.value, 2.8)
        self.assertEqual(step.outputs.q.value, None)

        self.assertIsNotNone(step.workflow)
        self.assertIn('p', step.workflow.inputs)
        self.assertIn('q', step.workflow.outputs)

        self.assertIs(step.workflow.inputs.p.source, step.inputs.p)
Example #7
0
    def test_from_json_dict(self):
        resource = get_resource('workflows/three_ops.json')
        json_text = """
        {
            "id": "workflow_ref_89",
            "workflow": "%s",
            "inputs": {
                "p": {"value": 2.8}
            }
        }
        """ % resource

        json_dict = json.loads(json_text)

        step = WorkflowStep.from_json_dict(json_dict)

        self.assertIsInstance(step, WorkflowStep)
        self.assertEqual(step.id, "workflow_ref_89")
        self.assertEqual(step.resource, resource)
        self.assertIn('p', step.inputs)
        self.assertIn('q', step.outputs)
        self.assertEqual(step.inputs.p.value, 2.8)
        self.assertEqual(step.outputs.q.value, None)

        self.assertIsNotNone(step.workflow)
        self.assertIn('p', step.workflow.inputs)
        self.assertIn('q', step.workflow.outputs)

        self.assertIs(step.workflow.inputs.p.source, step.inputs.p)
Example #8
0
    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)