コード例 #1
0
    def test_command_if_input_value_then(self):
        component_text = '''\
inputs:
- {name: Do test, type: Boolean, optional: true}
- {name: Test data, type: Integer, optional: true}
- {name: Test parameter 1, optional: true}
implementation:
  container:
    image: busybox
    args:
      - if:
          cond: {inputValue: Do test}
          then: [--test-data, {inputValue: Test data}, --test-param1, {inputValue: Test parameter 1}]
'''
        task_factory1 = comp.load_component(text=component_text)

        task_then = task_factory1(True, 'test_data.txt', '42')
        resolved_cmd_then = _resolve_command_line_and_paths(
            task_then.component_ref.spec, task_then.arguments)
        self.assertEqual(
            resolved_cmd_then.args,
            ['--test-data', 'test_data.txt', '--test-param1', '42'])

        task_else = task_factory1()
        resolved_cmd_else = _resolve_command_line_and_paths(
            task_else.component_ref.spec, task_else.arguments)
        self.assertEqual(resolved_cmd_else.args, [])
コード例 #2
0
    def test_conflicting_name_renaming_stability(self):
        # Checking that already pythonic input names are not renamed
        # Checking that renaming is deterministic
        component_text = textwrap.dedent('''\
            inputs:
            - {name: Input 1}
            - {name: Input_1}
            - {name: Input-1}
            - {name: input_1}  # Last in the list, but is pythonic, so it should not be renamed
            implementation:
              container:
                image: busybox
                command:
                - inputValue: Input 1
                - inputValue: Input_1
                - inputValue: Input-1
                - inputValue: input_1
            ''')
        task_factory1 = comp.load_component(text=component_text)
        task1 = task_factory1(
            input_1_2='value_1_2',
            input_1_3='value_1_3',
            input_1_4='value_1_4',
            input_1='value_1',  # Expecting this input not to be renamed
        )
        resolved_cmd = _resolve_command_line_and_paths(task1.component_ref.spec,
                                                       task1.arguments)

        self.assertEqual(resolved_cmd.command,
                         ['value_1_2', 'value_1_3', 'value_1_4', 'value_1'])
コード例 #3
0
    def test_loading_minimal_component(self):
        component_text = '''\
implementation:
  container:
    image: busybox
'''
        component_dict = load_yaml(component_text)
        task_factory1 = comp.load_component(text=component_text)

        self.assertEqual(
            task_factory1.component_spec.implementation.container.image,
            component_dict['implementation']['container']['image'])
コード例 #4
0
    def test_command_if_true_string_then_else(self):
        component_text = '''\
implementation:
  container:
    image: busybox
    args:
      - if:
          cond: 'true'
          then: --true-arg
          else: --false-arg
'''
        task_factory1 = comp.load_component(text=component_text)
        task = task_factory1()
        resolved_cmd = _resolve_command_line_and_paths(task.component_ref.spec,
                                                       task.arguments)
        self.assertEqual(resolved_cmd.args, ['--true-arg'])
コード例 #5
0
    def test_command_concat(self):
        component_text = '''\
inputs:
- {name: In1}
- {name: In2}
implementation:
  container:
    image: busybox
    args:
      - concat: [{inputValue: In1}, {inputValue: In2}]
'''
        task_factory1 = comp.load_component(text=component_text)
        task1 = task_factory1('some', 'data')
        resolved_cmd = _resolve_command_line_and_paths(task1.component_ref.spec,
                                                       task1.arguments)

        self.assertEqual(resolved_cmd.args, ['somedata'])
コード例 #6
0
    def test_input_value_resolving(self):
        component_text = '''\
inputs:
- {name: Data}
implementation:
  container:
    image: busybox
    args:
      - --data
      - inputValue: Data
'''
        task_factory1 = comp.load_component(text=component_text)
        task1 = task_factory1('some-data')
        resolved_cmd = _resolve_command_line_and_paths(task1.component_ref.spec,
                                                       task1.arguments)

        self.assertEqual(resolved_cmd.args, ['--data', 'some-data'])
コード例 #7
0
    def test_automatic_output_resolving(self):
        component_text = '''\
outputs:
- {name: Data}
implementation:
  container:
    image: busybox
    args:
      - --output-data
      - {outputPath: Data}
'''
        task_factory1 = comp.load_component(text=component_text)
        task1 = task_factory1()
        resolved_cmd = _resolve_command_line_and_paths(task1.component_ref.spec,
                                                       task1.arguments)

        self.assertEqual(len(resolved_cmd.args), 2)
        self.assertEqual(resolved_cmd.args[0], '--output-data')
        self.assertTrue(resolved_cmd.args[1].startswith('/'))
コード例 #8
0
    def test_command_if_is_present_then_else(self):
        component_text = '''\
inputs:
- {name: In, optional: true}
implementation:
  container:
    image: busybox
    args:
      - if:
          cond: {isPresent: In}
          then: [--in, {inputValue: In}]
          else: --no-in
'''
        task_factory1 = comp.load_component(text=component_text)

        task_then = task_factory1('data')
        resolved_cmd_then = _resolve_command_line_and_paths(
            task_then.component_ref.spec, task_then.arguments)
        self.assertEqual(resolved_cmd_then.args, ['--in', 'data'])

        task_else = task_factory1()
        resolved_cmd_else = _resolve_command_line_and_paths(
            task_else.component_ref.spec, task_else.arguments)
        self.assertEqual(resolved_cmd_else.args, ['--no-in'])
コード例 #9
0
 def test_load_component_fail_on_none_arguments(self):
     with self.assertRaises(ValueError):
         comp.load_component(filename=None, url=None, text=None)
コード例 #10
0
 def test_load_component_fail_on_multiple_sources(self):
     with self.assertRaises(ValueError):
         comp.load_component(filename='', text='')
コード例 #11
0
 def test_load_component_fail_on_no_sources(self):
     with self.assertRaises(ValueError):
         comp.load_component()