Ejemplo n.º 1
0
 def to_flyte_idl(self):
     """
     :rtype: flyteidl.core.errors_pb2.ContainerError
     """
     return _errors_pb2.ContainerError(code=self.code,
                                       message=self.message,
                                       kind=self.kind)
Ejemplo n.º 2
0
def test_from_string():
    proto_type = _proto.create_protobuf(_errors_pb2.ContainerError)

    pb = _errors_pb2.ContainerError(code="code", message="message")
    pb_str = _base64.b64encode(pb.SerializeToString())

    obj = proto_type.from_string(pb_str)
    assert obj.to_python_std().code == "code"
    assert obj.to_python_std().message == "message"
Ejemplo n.º 3
0
def test_proto():
    @task
    def t1(in1: errors_pb2.ContainerError) -> errors_pb2.ContainerError:
        e2 = errors_pb2.ContainerError(code=in1.code, message=in1.message + "!!!", kind=in1.kind + 1)
        return e2

    @workflow
    def wf(a: errors_pb2.ContainerError) -> errors_pb2.ContainerError:
        return t1(in1=a)

    e1 = errors_pb2.ContainerError(code="test", message="hello world", kind=1)
    e_out = wf(a=e1)
    assert e_out.kind == 2
    assert e_out.message == "hello world!!!"
Ejemplo n.º 4
0
def test_protos():
    ctx = FlyteContext.current_context()

    pb = errors_pb2.ContainerError(code="code", message="message")
    lt = TypeEngine.to_literal_type(errors_pb2.ContainerError)
    assert lt.simple == SimpleType.STRUCT
    assert lt.metadata["pb_type"] == "flyteidl.core.errors_pb2.ContainerError"

    lit = TypeEngine.to_literal(ctx, pb, errors_pb2.ContainerError, lt)
    new_python_val = TypeEngine.to_python_value(ctx, lit, errors_pb2.ContainerError)
    assert new_python_val == pb

    # Test error
    l0 = Literal(scalar=Scalar(primitive=Primitive(integer=4)))
    with pytest.raises(AssertionError):
        TypeEngine.to_python_value(ctx, l0, errors_pb2.ContainerError)
Ejemplo n.º 5
0
def test_proto():
    proto_type = _proto.create_protobuf(_errors_pb2.ContainerError)
    assert proto_type.short_class_string(
    ) == "Types.Proto(flyteidl.core.errors_pb2.ContainerError)"

    pb = _errors_pb2.ContainerError(code="code", message="message")
    obj = proto_type.from_python_std(pb)
    obj2 = proto_type.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2

    obj = obj.to_python_std()
    obj2 = obj2.to_python_std()

    assert obj.code == "code"
    assert obj.message == "message"

    assert obj2.code == "code"
    assert obj2.message == "message"
Ejemplo n.º 6
0
 def t1(in1: errors_pb2.ContainerError) -> errors_pb2.ContainerError:
     e2 = errors_pb2.ContainerError(code=in1.code, message=in1.message + "!!!", kind=in1.kind + 1)
     return e2