def test_handle_parsing_graph_component(self): component_text = '''\ inputs: - {name: graph in 1} - {name: graph in 2} outputs: - {name: graph out 1} - {name: graph out 2} implementation: graph: tasks: task 1: componentRef: {name: Comp 1} arguments: in1 1: 11 task 2: componentRef: {name: Comp 2} arguments: in2 1: 21 in2 2: {taskOutput: {taskId: task 1, outputName: out1 1}} task 3: componentRef: {name: Comp 3} arguments: in3 1: {taskOutput: {taskId: task 2, outputName: out2 1}} in3 2: {graphInput: {inputName: graph in 1}} outputValues: graph out 1: {taskOutput: {taskId: task 3, outputName: out3 1}} graph out 2: {taskOutput: {taskId: task 1, outputName: out1 2}} ''' struct = load_yaml(component_text) ComponentSpec.from_dict(struct)
def test_handle_parsing_predicates(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} task 2: componentRef: {name: Comp 2} arguments: in2 1: 21 in2 2: {taskOutput: {taskId: task 1, outputName: out1 1}} isEnabled: not: and: op1: '>': op1: {taskOutput: {taskId: task 1, outputName: out1 1}} op2: 0 op2: '==': op1: {taskOutput: {taskId: task 1, outputName: out1 2}} op2: 'head' ''' struct = load_yaml(component_text) ComponentSpec.from_dict(struct)
def test_handle_parsing_task_volumes_and_mounts(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} executionOptions: kubernetesOptions: mainContainer: volumeMounts: - name: workdir mountPath: /mnt/vol podSpec: volumes: - name: workdir emptyDir: {} ''' struct = load_yaml(component_text) component_spec = ComponentSpec.from_dict(struct) self.assertEqual( component_spec.implementation.graph.tasks['task 1']. execution_options.kubernetes_options.pod_spec.volumes[0].name, 'workdir') self.assertIsNotNone( component_spec.implementation.graph.tasks['task 1']. execution_options.kubernetes_options.pod_spec.volumes[0].empty_dir)
def test_fail_on_cyclic_references(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} arguments: in1 1: {taskOutput: {taskId: task 2, outputName: out2 1}} task 2: componentRef: {name: Comp 2} arguments: in2 1: {taskOutput: {taskId: task 1, outputName: out1 1}} ''' struct = load_yaml(component_text) with self.assertRaises(TypeError): ComponentSpec.from_dict(struct)
def test_handle_parsing_task_execution_options_caching_strategy(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} executionOptions: cachingStrategy: maxCacheStaleness: P30D ''' struct = load_yaml(component_text) component_spec = ComponentSpec.from_dict(struct) self.assertEqual( component_spec.implementation.graph.tasks['task 1']. execution_options.caching_strategy.max_cache_staleness, 'P30D')
def test_accessing_component_spec_from_task_factory(self): component_text = '''\ implementation: container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) actual_component_spec = task_factory1.component_spec actual_component_spec_dict = actual_component_spec.to_dict() expected_component_spec_dict = load_yaml(component_text) expected_component_spec = ComponentSpec.from_dict( expected_component_spec_dict) self.assertEqual(expected_component_spec_dict, actual_component_spec_dict) self.assertEqual(expected_component_spec, task_factory1.component_spec)
def test_handle_constructing_graph_component(self): task1 = TaskSpec(component_ref=ComponentReference(name='comp 1'), arguments={'in1 1': 11}) task2 = TaskSpec(component_ref=ComponentReference(name='comp 2'), arguments={ 'in2 1': 21, 'in2 2': TaskOutputArgument.construct(task_id='task 1', output_name='out1 1') }) task3 = TaskSpec( component_ref=ComponentReference(name='comp 3'), arguments={ 'in3 1': TaskOutputArgument.construct(task_id='task 2', output_name='out2 1'), 'in3 2': GraphInputReference(input_name='graph in 1').as_argument() }) graph_component1 = ComponentSpec( inputs=[ InputSpec(name='graph in 1'), InputSpec(name='graph in 2'), ], outputs=[ OutputSpec(name='graph out 1'), OutputSpec(name='graph out 2'), ], implementation=GraphImplementation(graph=GraphSpec( tasks={ 'task 1': task1, 'task 2': task2, 'task 3': task3, }, output_values={ 'graph out 1': TaskOutputArgument.construct(task_id='task 3', output_name='out3 1'), 'graph out 2': TaskOutputArgument.construct(task_id='task 1', output_name='out1 2'), })))
def test_handle_parsing_task_container_spec_options(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} executionOptions: kubernetesOptions: mainContainer: resources: requests: memory: 1024Mi cpu: 200m ''' struct = load_yaml(component_text) component_spec = ComponentSpec.from_dict(struct) self.assertEqual( component_spec.implementation.graph.tasks['task 1']. execution_options.kubernetes_options.main_container.resources. requests['memory'], '1024Mi')