Skip to content

Commit

Permalink
SDK - Components - Task objects now have the .output attribute when c…
Browse files Browse the repository at this point in the history
…omponent has only one output (#3622)
  • Loading branch information
Ark-kun authored Apr 27, 2020
1 parent 45bc582 commit e41ee9c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdk/python/kfp/components/_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ def _init_outputs(self):
task_outputs[output.name] = task_output_arg

self.outputs = task_outputs
if len(task_outputs) == 1:
self.output = list(task_outputs.values())[0]


class GraphSpec(ModelBase):
Expand Down
48 changes: 48 additions & 0 deletions sdk/python/tests/components/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
import sys
import textwrap
import unittest
from contextlib import contextmanager
from pathlib import Path
Expand Down Expand Up @@ -597,6 +598,53 @@ def test_check_task_spec_outputs_dictionary(self):

self.assertEqual(list(task.outputs.keys()), ['out 1', 'out 2'])

def test_check_task_object_no_output_attribute_when_0_outputs(self):
component_text = textwrap.dedent('''\
implementation:
container:
image: busybox
command: []
''',
)

op = comp.load_component_from_text(component_text)
task = op()

self.assertFalse(hasattr(task, 'output'))

def test_check_task_object_has_output_attribute_when_1_output(self):
component_text = textwrap.dedent('''\
outputs:
- {name: out 1}
implementation:
container:
image: busybox
command: [touch, {outputPath: out 1}]
''',
)

op = comp.load_component_from_text(component_text)
task = op()

self.assertEqual(task.output.task_output.output_name, 'out 1')

def test_check_task_object_no_output_attribute_when_multiple_outputs(self):
component_text = textwrap.dedent('''\
outputs:
- {name: out 1}
- {name: out 2}
implementation:
container:
image: busybox
command: [touch, {outputPath: out 1}, {outputPath: out 2}]
''',
)

op = comp.load_component_from_text(component_text)
task = op()

self.assertFalse(hasattr(task, 'output'))

def test_check_type_validation_of_task_spec_outputs(self):
producer_component_text = '''\
outputs:
Expand Down

0 comments on commit e41ee9c

Please sign in to comment.