def result(self): "Provide the result of the iterable as a value or exception" ex = self.result if isinstance(self.result, failure.Failure): ex = resolveException(self.result) if isinstance(ex, Exception): raise ex return self.result
def test_resolveException_with_exception_string_with_import_error(self): failure = Failure() failure.value = "value" failure.tb = "tb" failure.type = "Products.ZenUtils.Exceptions.UnknownError" actual = resolveException(failure) self.assertIsInstance(actual, Exception) self.assertEquals(("value", "tb"), actual.args)
def test_resolveException_with_exception_string_with_import_error(self): failure = Failure() failure.value = "value" failure.tb = "tb" failure.type = "Products.ZenUtils.Exceptions.UnknownError" actual = resolveException( failure) self.assertIsInstance( actual, Exception) self.assertEquals( ("value", "tb"), actual.args)
def test_resolveException_with_raiseException(self): failure = Failure() failure.raise_value = RuntimeError() self.assertIs(failure.raise_value, resolveException(failure))
def test_resolveException_with_exception_string(self): failure = Failure() failure.type = "Products.ZenUtils.Exceptions.ZenPathError" self.assertIsInstance(resolveException(failure), ZenPathError)
def test_resolveException_with_exception_value(self): failure = Failure() failure.value = ZentinelException() self.assertIs(failure.value, resolveException(failure))
def test_resolveException_with_raiseException(self): failure = Failure() failure.raise_value = RuntimeError() self.assertIs( failure.raise_value, resolveException( failure))
def test_resolveException_with_exception_string(self): failure = Failure() failure.type = "Products.ZenUtils.Exceptions.ZenPathError" self.assertIsInstance( resolveException( failure), ZenPathError)
def test_resolveException_with_exception_value(self): failure = Failure() failure.value = ZentinelException() self.assertIs( failure.value, resolveException( failure))
def test_wraps_invalid_failure_objects(self): failure = {'i am': 'not a', 'valid': 'failure'} out = resolveException(failure) expected = ZenResolveExceptionError(failure) self.assertIsInstance(out, ZenResolveExceptionError) self.assertEqual(out.args, expected.args)
def test_handles_twisted_spread_pb_RemoteError(self): exception = RemoteError('remoteType', 'value', 'remoteTraceback') failure = Failure(exception) out = resolveException(failure) self.assertIsInstance(out, RemoteError) self.assertEqual(out, exception)
def test_alternate_failure_constructor(self): failure = Failure(exc_value="boom", exc_type=RuntimeError, exc_tb=[]) out = resolveException(failure) expected = RuntimeError('boom') self.assertIsInstance(out, RuntimeError) self.assertEqual(out.args, expected.args)
def test_resolveException(self): exception = RuntimeError('genric exception') failure = Failure(exception) out = resolveException(failure) self.assertEqual(out, exception)