Ejemplo n.º 1
0
 def test_to_placeholder(self):
     structure = structures.InputPathPlaceholder('input1')
     actual = structure.to_placeholder()
     expected = "{{$.inputs.artifacts['input1'].path}}"
     self.assertEqual(
         actual,
         expected,
     )
Ejemplo n.º 2
0
 def test_from_placeholder(self):
     placeholder = "{{$.inputs.artifacts['input1'].path}}"
     expected = structures.InputPathPlaceholder('input1')
     actual = structures.InputPathPlaceholder.from_placeholder(placeholder)
     self.assertEqual(
         actual,
         expected,
     )
Ejemplo n.º 3
0
 def _transform_arg(arg: ValidCommandArgs) -> Any:
     if isinstance(arg, str):
         return arg
     if isinstance(arg, InputValuePlaceholder):
         return v1_structures.InputValuePlaceholder(arg.input_name)
     if isinstance(arg, InputPathPlaceholder):
         return v1_structures.InputPathPlaceholder(arg.input_name)
     if isinstance(arg, InputUriPlaceholder):
         return v1_structures.InputUriPlaceholder(arg.input_name)
     if isinstance(arg, OutputPathPlaceholder):
         return v1_structures.OutputPathPlaceholder(arg.output_name)
     if isinstance(arg, OutputUriPlaceholder):
         return v1_structures.OutputUriPlaceholder(arg.output_name)
     if isinstance(arg, IfPresentPlaceholder):
         return v1_structures.IfPlaceholder(arg.if_structure)
     if isinstance(arg, ConcatPlaceholder):
         return v1_structures.ConcatPlaceholder(arg.concat)
     raise ValueError(
         f'Unexpected command/argument type: "{arg}" of type "{type(arg)}".'
     )
Ejemplo n.º 4
0
 def test_input_path_placeholder(self):
     arg = "{{$.inputs.artifacts['input1'].path}}"
     actual = structures.maybe_convert_command_arg_to_placeholder(arg)
     expected = structures.InputPathPlaceholder('input1')
     self.assertEqual(actual, expected)
Ejemplo n.º 5
0
    def test_component_spec_load_from_v1_component_yaml(self):
        component_yaml_v1 = textwrap.dedent("""\
        name: Component with 2 inputs and 2 outputs
        inputs:
        - {name: Input parameter, type: String}
        - {name: Input artifact}
        outputs:
        - {name: Output 1}
        - {name: Output 2}
        implementation:
          container:
            image: busybox
            command: [sh, -c, '
                mkdir -p $(dirname "$2")
                mkdir -p $(dirname "$3")
                echo "$0" > "$2"
                cp "$1" "$3"
                '
            ]
            args:
            - {inputValue: Input parameter}
            - {inputPath: Input artifact}
            - {outputPath: Output 1}
            - {outputPath: Output 2}
        """)

        generated_spec = structures.ComponentSpec.load_from_component_yaml(
            component_yaml_v1)

        expected_spec = structures.ComponentSpec(
            name='Component with 2 inputs and 2 outputs',
            implementation=structures.Implementation(
                container=structures.ContainerSpec(
                    image='busybox',
                    command=[
                        'sh',
                        '-c',
                        (' mkdir -p $(dirname "$2") mkdir -p $(dirname "$3") '
                         'echo "$0" > "$2" cp "$1" "$3" '),
                    ],
                    args=[
                        structures.InputValuePlaceholder(
                            input_name='input_parameter'),
                        structures.InputPathPlaceholder(
                            input_name='input_artifact'),
                        structures.OutputPathPlaceholder(
                            output_name='output_1'),
                        structures.OutputPathPlaceholder(
                            output_name='output_2'),
                    ],
                    env={},
                )),
            inputs={
                'input_parameter': structures.InputSpec(type='String'),
                'input_artifact': structures.InputSpec(type='Artifact')
            },
            outputs={
                'output_1': structures.OutputSpec(type='Artifact'),
                'output_2': structures.OutputSpec(type='Artifact'),
            })
        self.assertEqual(generated_spec, expected_spec)