Beispiel #1
0
def test_binding_data_promise():
    obj = literals.BindingData(promise=_types.OutputReference('some_node', 'myvar'))
    assert obj.scalar is None
    assert obj.promise is not None
    assert obj.collection is None
    assert obj.map is None
    assert obj.value.node_id == 'some_node'
    assert obj.value.var == 'myvar'

    obj2 = literals.BindingData.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2
    assert obj2.scalar is None
    assert obj2.promise is not None
    assert obj2.collection is None
    assert obj2.map is None
Beispiel #2
0
    def __init__(self, name, sdk_type, help=None, **kwargs):
        """
        :param Text name:
        :param flytekit.common.types.base_sdk_types.FlyteSdkType sdk_type: This is the SDK type necessary to create an
            input to this workflow.
        :param Text help: An optional help string to describe the input to users.
        :param bool required: If set to True, default must be None
        :param T default:  If this is not a required input, the value will default to this value.
        """
        param_default = None
        if "required" not in kwargs and "default" not in kwargs:
            # Neither required or default is set so assume required
            required = True
            default = None
        elif kwargs.get("required", False) and "default" in kwargs:
            # Required cannot be set to True and have a default specified
            raise _user_exceptions.FlyteAssertion(
                "Default cannot be set when required is True")
        elif "default" in kwargs:
            # If default is specified, then required must be false and the value is whatever is specified
            required = None
            default = kwargs["default"]
            param_default = sdk_type.from_python_std(default)
        else:
            # If no default is set, but required is set, then the behavior is determined by required == True or False
            default = None
            required = kwargs["required"]
            if not required:
                # If required == False, we assume default to be None
                param_default = sdk_type.from_python_std(default)
                required = None

        self._sdk_required = required or False
        self._sdk_default = default
        self._help = help
        self._sdk_type = sdk_type
        self._promise = _type_models.OutputReference(
            _constants.GLOBAL_INPUT_NODE_ID, name)
        self._name = name
        super(Input, self).__init__(
            _interface_models.Variable(type=sdk_type.to_flyte_literal_type(),
                                       description=help or ""),
            required=required,
            default=param_default,
        )
Beispiel #3
0
def test_workflow_closure():
    int_type = _types.LiteralType(_types.SimpleType.INTEGER)
    typed_interface = _interface.TypedInterface(
        {'a': _interface.Variable(int_type, "description1")}, {
            'b': _interface.Variable(int_type, "description2"),
            'c': _interface.Variable(int_type, "description3")
        })

    b0 = _literals.Binding(
        'a',
        _literals.BindingData(scalar=_literals.Scalar(
            primitive=_literals.Primitive(integer=5))))
    b1 = _literals.Binding(
        'b',
        _literals.BindingData(promise=_types.OutputReference('my_node', 'b')))
    b2 = _literals.Binding(
        'b',
        _literals.BindingData(promise=_types.OutputReference('my_node', 'c')))

    node_metadata = _workflow.NodeMetadata(name='node1',
                                           timeout=timedelta(seconds=10),
                                           retries=_literals.RetryStrategy(0))

    task_metadata = _task.TaskMetadata(
        True,
        _task.RuntimeMetadata(_task.RuntimeMetadata.RuntimeType.FLYTE_SDK,
                              "1.0.0", "python"), timedelta(days=1),
        _literals.RetryStrategy(3), "0.1.1b0", "This is deprecated!")

    cpu_resource = _task.Resources.ResourceEntry(
        _task.Resources.ResourceName.CPU, "1")
    resources = _task.Resources(requests=[cpu_resource], limits=[cpu_resource])

    task = _task.TaskTemplate(
        _identifier.Identifier(_identifier.ResourceType.TASK, "project",
                               "domain", "name", "version"),
        "python",
        task_metadata,
        typed_interface, {
            'a': 1,
            'b': {
                'c': 2,
                'd': 3
            }
        },
        container=_task.Container("my_image", ["this", "is", "a", "cmd"],
                                  ["this", "is", "an", "arg"], resources, {},
                                  {}))

    task_node = _workflow.TaskNode(task.id)
    node = _workflow.Node(id='my_node',
                          metadata=node_metadata,
                          inputs=[b0],
                          upstream_node_ids=[],
                          output_aliases=[],
                          task_node=task_node)

    template = _workflow.WorkflowTemplate(
        id=_identifier.Identifier(_identifier.ResourceType.WORKFLOW, "project",
                                  "domain", "name", "version"),
        metadata=_workflow.WorkflowMetadata(),
        interface=typed_interface,
        nodes=[node],
        outputs=[b1, b2],
    )

    obj = _workflow_closure.WorkflowClosure(workflow=template, tasks=[task])
    assert len(obj.tasks) == 1

    obj2 = _workflow_closure.WorkflowClosure.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2
Beispiel #4
0
def test_output_reference():
    obj = _types.OutputReference(node_id='node1', var='var1')
    assert obj.node_id == 'node1'
    assert obj.var == 'var1'
    obj2 = _types.OutputReference.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2
Beispiel #5
0
def test_output_reference():
    obj = _types.OutputReference(node_id="node1", var="var1")
    assert obj.node_id == "node1"
    assert obj.var == "var1"
    obj2 = _types.OutputReference.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2