Exemplo n.º 1
0
    def test_basic(self):
        """Test basic usage."""
        with Pipeline('somename') as p:
            self.assertTrue(Pipeline.get_default_pipeline() is not None)
            op1 = ContainerOp(name='op1', image='image')
            op2 = ContainerOp(name='op2', image='image')

        self.assertTrue(Pipeline.get_default_pipeline() is None)
        self.assertEqual(p.ops['op1'].name, 'op1')
        self.assertEqual(p.ops['op2'].name, 'op2')
Exemplo n.º 2
0
    def test_basic(self):
        """Test basic usage."""
        with Pipeline('somename') as p:
            self.assertEqual(1, len(p.groups))
            with OpsGroup(group_type='exit_handler'):
                op1 = ContainerOp(name='op1', image='image')
                with OpsGroup(group_type='branch'):
                    op2 = ContainerOp(name='op2', image='image')
                    op3 = ContainerOp(name='op3', image='image')
                with OpsGroup(group_type='loop'):
                    op4 = ContainerOp(name='op4', image='image')

        self.assertEqual(1, len(p.groups))
        self.assertEqual(1, len(p.groups[0].groups))
        exit_handler_group = p.groups[0].groups[0]
        self.assertEqual('exit_handler', exit_handler_group.type)
        self.assertEqual(2, len(exit_handler_group.groups))
        self.assertEqual(1, len(exit_handler_group.ops))
        self.assertEqual('op1', exit_handler_group.ops[0].name)

        branch_group = exit_handler_group.groups[0]
        self.assertFalse(branch_group.groups)
        self.assertCountEqual([x.name for x in branch_group.ops],
                              ['op2', 'op3'])

        loop_group = exit_handler_group.groups[1]
        self.assertFalse(loop_group.groups)
        self.assertCountEqual([x.name for x in loop_group.ops], ['op4'])
Exemplo n.º 3
0
 def test_invalid_exit_op(self):
     with self.assertRaises(ValueError):
         with Pipeline('somename') as p:
             op1 = ContainerOp(name='op1', image='image')
             exit_op = ContainerOp(name='exit', image='image')
             exit_op.after(op1)
             with ExitHandler(exit_op=exit_op):
                 pass
Exemplo n.º 4
0
    def test_basic(self):
        """Test basic usage."""
        with Pipeline('somename') as p:
            exit_op = ContainerOp(name='exit', image='image')
            with ExitHandler(exit_op=exit_op):
                op1 = ContainerOp(name='op1', image='image')

        exit_handler = p.groups[0].groups[0]
        self.assertEqual('exit_handler', exit_handler.type)
        self.assertEqual('exit', exit_handler.exit_op.name)
        self.assertEqual(1, len(exit_handler.ops))
        self.assertEqual('op1', exit_handler.ops[0].name)
Exemplo n.º 5
0
    def test_basic(self):
        with Pipeline('somename') as p:
            param1 = 'pizza'
            condition1 = Condition(param1 == 'pizza')
            self.assertEqual(condition1.name, None)
            with condition1:
                pass
            self.assertEqual(condition1.name, 'condition-1')

            condition2 = Condition(param1 == 'pizza', '[param1 is pizza]')
            self.assertEqual(condition2.name, '[param1 is pizza]')
            with condition2:
                pass
            self.assertEqual(condition2.name, 'condition-[param1 is pizza]-2')
Exemplo n.º 6
0
    def test_recursive_opsgroups_with_prefix_names(self):
        """Test recursive opsgroups."""
        with Pipeline('somename') as p:
            self.assertEqual(1, len(p.groups))

            # When a graph opsgraph is called.
            graph_ops_group_one = dsl._ops_group.Graph('foo_bar')
            graph_ops_group_one.__enter__()
            self.assertFalse(graph_ops_group_one.recursive_ref)
            self.assertEqual('graph-foo-bar-1', graph_ops_group_one.name)

            # Another graph opsgraph is called with the name as the prefix of the ops_group_one
            # when the previous graph opsgraphs is not finished.
            graph_ops_group_two = dsl._ops_group.Graph('foo')
            graph_ops_group_two.__enter__()
            self.assertFalse(graph_ops_group_two.recursive_ref)
Exemplo n.º 7
0
    def test_basic_recursive_opsgroups(self):
        """Test recursive opsgroups."""
        with Pipeline('somename') as p:
            self.assertEqual(1, len(p.groups))

            # When a graph opsgraph is called.
            graph_ops_group_one = dsl._ops_group.Graph('hello')
            graph_ops_group_one.__enter__()
            self.assertFalse(graph_ops_group_one.recursive_ref)
            self.assertEqual('graph-hello-1', graph_ops_group_one.name)

            # Another graph opsgraph is called with the same name
            # when the previous graph opsgraphs is not finished.
            graph_ops_group_two = dsl._ops_group.Graph('hello')
            graph_ops_group_two.__enter__()
            self.assertTrue(graph_ops_group_two.recursive_ref)
            self.assertEqual(graph_ops_group_one,
                             graph_ops_group_two.recursive_ref)
Exemplo n.º 8
0
    def test_graphcomponent_basic(self):
        """Test graph_component decorator metadata."""

        @graph_component
        def flip_component(flip_result):
            with dsl.Condition(flip_result == 'heads'):
                flip_component(flip_result)

        with Pipeline('pipeline') as p:
            param = PipelineParam(name='param')
            flip_component(param)
            self.assertEqual(1, len(p.groups))
            self.assertEqual(1, len(p.groups[0].groups))  # pipeline
            self.assertEqual(1, len(
                p.groups[0].groups[0].groups))  # flip_component
            self.assertEqual(1, len(
                p.groups[0].groups[0].groups[0].groups))  # condition
            self.assertEqual(0,
                             len(p.groups[0].groups[0].groups[0].groups[0]
                                 .groups))  # recursive flip_component
            recursive_group = p.groups[0].groups[0].groups[0].groups[0]
            self.assertTrue(recursive_group.recursive_ref is not None)
            self.assertEqual(1, len(recursive_group.inputs))
            self.assertEqual('param', recursive_group.inputs[0].name)
Exemplo n.º 9
0
 def test_nested_pipelines(self):
     """Test nested pipelines."""
     with self.assertRaises(Exception):
         with Pipeline('somename1') as p1:
             with Pipeline('somename2') as p2:
                 pass