def __init__(self, sdk_type): """ :param flytekit.common.types.base_sdk_types.FlyteSdkType sdk_type: """ self._raw_value = None self._sdk_type = sdk_type self._sdk_value = _base_sdk_types.Void()
def test_sdk_output_references_construction(): references = { name: _task_output.OutputReference(_type_helpers.get_sdk_type_from_literal_type(variable.type)) for name, variable in _six.iteritems(two_queries.interface.outputs) } # Before user code is run, the outputs passed to the user code should not have values assert references['hive_results'].sdk_value == _base_sdk_types.Void() # Should be a list of schemas assert isinstance(references['hive_results'].sdk_type, _containers.TypedCollectionType) assert isinstance(references['hive_results'].sdk_type.sub_type, _schema.SchemaInstantiator)
def from_python_std(cls, t_value): """ :param T t_value: It is up to each individual object as to whether or not this value can be cast. :rtype: FlyteSdkValue :raises: flytekit.common.exceptions.user.FlyteTypeException """ if t_value is None: return _base_sdk_types.Void() if type(t_value) != bool: raise _user_exceptions.FlyteTypeException(type(t_value), bool, t_value) return cls(t_value)
def from_python_std(cls, t_value: Union[GeneratedProtocolMessageType, FlyteIdlEntity]): """ :param Union[T, FlyteIdlEntity] t_value: It is up to each individual object as to whether or not this value can be cast. :rtype: _base_sdk_types.FlyteSdkValue :raises: flytekit.common.exceptions.user.FlyteTypeException """ if t_value is None: return _base_sdk_types.Void() elif isinstance(t_value, cls.pb_type) or isinstance(t_value, FlyteIdlEntity): return cls(t_value) else: raise _user_exceptions.FlyteTypeException(type(t_value), cls.pb_type, received_value=t_value)
def from_python_std(cls, t_value): """ :param T t_value: It is up to each individual object as to whether or not this value can be cast. :rtype: FlyteSdkValue :raises: flytekit.common.exceptions.user.FlyteTypeException """ if t_value is None: return _base_sdk_types.Void() if not isinstance(t_value, list): raise _user_exceptions.FlyteTypeException(type(t_value), list, t_value) return cls([cls.sub_type.from_python_std(v) for v in t_value])
def from_python_std(cls, t_value): """ Creates an object of this type from the model primitive defining it. :param T t_value: It is up to each individual object as to whether or not this value can be cast. :rtype: FlyteSdkValue :raises: flytekit.common.exceptions.user.FlyteTypeException """ if t_value is None: return _base_sdk_types.Void() if type(t_value) not in set([str, _six.text_type]): raise _user_exceptions.FlyteTypeException( type(t_value), set([str, _six.text_type]), t_value) return cls(t_value)
def from_python_std(cls, t_value): """ :param T t_value: It is up to each individual object as to whether or not this value can be cast. :rtype: FlyteSdkValue :raises: flytekit.common.exceptions.user.FlyteTypeException """ if t_value is None: return _base_sdk_types.Void() elif isinstance(t_value, _blob_impl.Blob): blob = t_value else: blob = _blob_impl.Blob.from_python_std(t_value) return cls(blob)
def from_python_std(cls, t_value): """ :param T t_value: It is up to each individual object as to whether or not this value can be cast. :rtype: FlyteSdkValue :raises: flytekit.common.exceptions.user.FlyteTypeException """ if t_value is None: return _base_sdk_types.Void() elif isinstance(t_value, _schema_impl.Schema): schema = t_value.cast_to(cls.schema_type) else: schema = _schema_impl.Schema.from_python_std(t_value, schema_type=cls.schema_type) return cls(schema)
def from_python_std(cls, t_value): """ :param T t_value: It is up to each individual object as to whether or not this value can be cast. :rtype: FlyteSdkValue :raises: flytekit.common.exceptions.user.FlyteTypeException """ if t_value is None: return _base_sdk_types.Void() elif type(t_value) != _datetime.datetime: raise _user_exceptions.FlyteTypeException(type(t_value), _datetime.datetime, t_value) elif t_value.tzinfo is None: raise _user_exceptions.FlyteValueException( t_value, "Datetime objects in Flyte must be timezone aware. " "tzinfo was found to be None.") return cls(t_value)
def test_void(): # Check type specification with pytest.raises(user_exceptions.FlyteAssertion): base_sdk_types.Void.to_flyte_literal_type() # Test value behavior for val in [ 1, 1.0, 'abc', True, False, datetime.datetime.now(), datetime.timedelta(seconds=1), None ]: assert base_sdk_types.Void.from_python_std(val).to_python_std() is None obj = base_sdk_types.Void() assert base_sdk_types.Void.from_flyte_idl(obj.to_flyte_idl()) == obj assert obj.short_string() == "Void()" assert obj.verbose_string() == "Void()"
def from_python_std(cls, t_value): """ :param T t_value: It is up to each individual object as to whether or not this value can be cast. :rtype: FlyteSdkValue :raises: flytekit.common.exceptions.user.FlyteTypeException """ if t_value is None: return _base_sdk_types.Void() elif isinstance(t_value, _blob_impl.Blob): if t_value.metadata.type.format != "csv": raise _user_exceptions.FlyteValueException( t_value, "Blob is in incorrect format. Expected CSV.") blob = t_value else: blob = _blob_impl.Blob.from_python_std(t_value, format="csv", mode="w") return cls(blob)
def from_python_std(cls, t_value): """ :param T t_value: It is up to each individual object as to whether or not this value can be cast. :rtype: FlyteSdkValue :raises: flytekit.common.exceptions.user.FlyteTypeException """ if t_value is None: return _base_sdk_types.Void() elif not isinstance(t_value, dict): raise _user_exceptions.FlyteTypeException(type(t_value), dict, t_value) try: t = _json.dumps(t_value) except Exception: raise _user_exceptions.FlyteValueException( t_value, "Is not JSON serializable.") return cls(_json_format.Parse(t, _struct.Struct()))
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)
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)