Ejemplo n.º 1
0
def test_serialize_exception_without_traceback():
    e: Exception = Exception()
    assert e.__traceback__ is None
    f: Failure = serialize_exception(e)
    assert isinstance(f, Failure)
    s = failure_to_str(f)
    assert isinstance(s, str)
    f2: Failure = str_to_failure(s)
    assert isinstance(f2, Failure)
    assert f.to_dict() == f2.to_dict()
    e2 = deserialize_exception(f2)
    assert isinstance(e2, Exception)
    assert e2.__traceback__ is None
Ejemplo n.º 2
0
def test_deserialize_exception_with_traceback():
    try:
        raise Exception("blah")
    except Exception as ex:
        e = ex
    assert e.__traceback__ is not None
    f: Failure = serialize_exception(e)
    assert isinstance(f, Failure)
    s = failure_to_str(f)
    assert isinstance(s, str)
    f2: Failure = str_to_failure(s)
    assert isinstance(f2, Failure)
    assert f.to_dict() == f2.to_dict()
    e2 = deserialize_exception(f2)
    assert isinstance(e2, Exception)
    assert e2.__traceback__ is not None
    assert traceback.format_tb(e.__traceback__) == traceback.format_tb(e2.__traceback__)
Ejemplo n.º 3
0
 def get_cause(self):
     if self.cause:
         f: Failure = str_to_failure(self.cause)
         return deserialize_exception(f)
     else:
         return None