Esempio n. 1
0
def test_model_promotion():
    list_type = containers.List(primitives.Integer)
    list_model = literals.Literal(collection=literals.LiteralCollection(
        literals=[
            literals.Literal(scalar=literals.Scalar(
                primitive=literals.Primitive(integer=0))),
            literals.Literal(scalar=literals.Scalar(
                primitive=literals.Primitive(integer=1))),
            literals.Literal(scalar=literals.Scalar(
                primitive=literals.Primitive(integer=2))),
        ]))
    list_obj = list_type.promote_from_model(list_model)
    assert len(list_obj.collection.literals) == 3
    assert isinstance(list_obj.collection.literals[0], primitives.Integer)
    assert list_obj == list_type.from_python_std([0, 1, 2])
    assert list_obj == list_type(
        [primitives.Integer(0),
         primitives.Integer(1),
         primitives.Integer(2)])
Esempio n. 2
0
def test_input():
    i = promise.Input("name", primitives.Integer, help="blah", default=None)
    assert i.name == "name"
    assert i.sdk_default is None
    assert i.default == base_sdk_types.Void()
    assert i.sdk_required is False
    assert i.help == "blah"
    assert i.var.description == "blah"
    assert i.sdk_type == primitives.Integer

    i = promise.Input("name2", primitives.Integer, default=1)
    assert i.name == "name2"
    assert i.sdk_default == 1
    assert i.default == primitives.Integer(1)
    assert i.required is None
    assert i.sdk_required is False
    assert i.help is None
    assert i.var.description == ""
    assert i.sdk_type == primitives.Integer

    with pytest.raises(_user_exceptions.FlyteAssertion):
        promise.Input("abc", primitives.Integer, required=True, default=1)
Esempio n. 3
0
def test_input():
    i = Input(primitives.Integer, help="blah", default=None)
    assert i.name == ''
    assert i.sdk_default is None
    assert i.default == base_sdk_types.Void()
    assert i.sdk_required is False
    assert i.required is None
    assert i.help == "blah"
    assert i.var.description == "blah"
    assert i.sdk_type == primitives.Integer

    i = i.rename_and_return_reference('new_name')
    assert i.name == 'new_name'
    assert i.sdk_default is None
    assert i.default == base_sdk_types.Void()
    assert i.sdk_required is False
    assert i.required is None
    assert i.help == "blah"
    assert i.var.description == "blah"
    assert i.sdk_type == primitives.Integer

    i = Input(primitives.Integer, default=1)
    assert i.name == ''
    assert i.sdk_default is 1
    assert i.default == primitives.Integer(1)
    assert i.sdk_required is False
    assert i.required is None
    assert i.help is None
    assert i.var.description == ""
    assert i.sdk_type == primitives.Integer

    i = i.rename_and_return_reference('new_name')
    assert i.name == 'new_name'
    assert i.sdk_default is 1
    assert i.default == primitives.Integer(1)
    assert i.sdk_required is False
    assert i.required is None
    assert i.help is None
    assert i.var.description == ""
    assert i.sdk_type == primitives.Integer

    with pytest.raises(_user_exceptions.FlyteAssertion):
        Input(primitives.Integer, required=True, default=1)

    i = Input([primitives.Integer], default=[1, 2])
    assert i.name == ''
    assert i.sdk_default == [1, 2]
    assert i.default == containers.List(primitives.Integer)([primitives.Integer(1), primitives.Integer(2)])
    assert i.sdk_required is False
    assert i.required is None
    assert i.help is None
    assert i.var.description == ""
    assert i.sdk_type == containers.List(primitives.Integer)

    i = i.rename_and_return_reference('new_name')
    assert i.name == 'new_name'
    assert i.sdk_default == [1, 2]
    assert i.default == containers.List(primitives.Integer)([primitives.Integer(1), primitives.Integer(2)])
    assert i.sdk_required is False
    assert i.required is None
    assert i.help is None
    assert i.var.description == ""
    assert i.sdk_type == containers.List(primitives.Integer)