Exemplo n.º 1
0
    def test_invoke(self):
        step = NoOpStep(inputs=OrderedDict([('a', {}), ('b', {})]),
                        outputs=OrderedDict([('c', {}), ('d', {})]))

        # Operation: Swap input
        step.outputs.c.source = step.inputs.b
        step.outputs.d.source = step.inputs.a

        step.inputs.a.value = 'A'
        step.inputs.b.value = 'B'
        step.invoke()
        self.assertEqual(step.outputs.c.value, 'B')
        self.assertEqual(step.outputs.d.value, 'A')
Exemplo n.º 2
0
    def test_invoke(self):
        step = NoOpStep(inputs=OrderedDict([('a', {}), ('b', {})]),
                        outputs=OrderedDict([('c', {}), ('d', {})]))

        # Operation: Swap input
        step.outputs.c.source = step.inputs.b
        step.outputs.d.source = step.inputs.a

        step.inputs.a.value = 'A'
        step.inputs.b.value = 'B'
        step.invoke()
        self.assertEqual(step.outputs.c.value, 'B')
        self.assertEqual(step.outputs.d.value, 'A')
Exemplo n.º 3
0
    def test_from_and_to_json(self):
        json_text = """
        {
            "id": "op3",
            "no_op": true,
            "inputs": {
                "a": {"value": 647},
                "b": {"value": 2.9}
            },
            "outputs": {
                "c": {"source": "op3.b"},
                "d": {"source": "op3.a"}
            }
        }
        """

        json_dict = json.loads(json_text)

        step = NoOpStep.from_json_dict(json_dict)

        self.assertIsInstance(step, NoOpStep)
        self.assertEqual(step.id, "op3")
        self.assertIn('a', step.inputs)
        self.assertIn('b', step.inputs)
        self.assertIn('c', step.outputs)
        self.assertIn('d', step.outputs)

        self.assertEqual(step.inputs.a.value, 647)
        self.assertEqual(step.inputs.b.value, 2.9)
        self.assertEqual(step.outputs.c._source_ref, ('op3', 'b'))
        self.assertEqual(step.outputs.d._source_ref, ('op3', 'a'))
Exemplo n.º 4
0
    def test_from_and_to_json(self):
        json_text = """
        {
            "id": "op3",
            "no_op": true,
            "inputs": {
                "a": {"value": 647},
                "b": {"value": 2.9}
            },
            "outputs": {
                "c": {"source": "op3.b"},
                "d": {"source": "op3.a"}
            }
        }
        """

        json_dict = json.loads(json_text)

        step = NoOpStep.from_json_dict(json_dict)

        self.assertIsInstance(step, NoOpStep)
        self.assertEqual(step.id, "op3")
        self.assertIn('a', step.inputs)
        self.assertIn('b', step.inputs)
        self.assertIn('c', step.outputs)
        self.assertIn('d', step.outputs)

        self.assertEqual(step.inputs.a.value, 647)
        self.assertEqual(step.inputs.b.value, 2.9)
        self.assertEqual(step.outputs.c._source_ref, ('op3', 'b'))
        self.assertEqual(step.outputs.d._source_ref, ('op3', 'a'))
Exemplo n.º 5
0
    def test_init(self):
        step = NoOpStep(inputs=OrderedDict([('a', {}), ('b', {})]),
                        outputs=OrderedDict([('c', {}), ('d', {})]))

        self.assertRegex(step.id, '^noopstep_[0-9a-f]+$')

        self.assertIsNotNone(step.op_meta_info)
        self.assertEqual(step.op_meta_info.qualified_name, step.id)

        self.assertTrue(len(step.inputs), 2)
        self.assertTrue(len(step.outputs), 2)

        self.assertTrue(hasattr(step.inputs, 'a'))
        self.assertIs(step.inputs.a.node, step)

        self.assertTrue(hasattr(step.outputs, 'd'))
        self.assertIs(step.outputs.d.node, step)

        self.assertEqual(str(step), step.id + ' = noop(a=None, b=None) -> (c, d) [NoOpStep]')
        self.assertEqual(repr(step), "NoOpStep(node_id='%s')" % step.id)