Beispiel #1
0
    def test_diagnose_unwraps_first_error_if_apierr_or_connection_error(self):
        """
        :func:`diagnose` unwraps :class:`FirstError`, no matter how deeply
        nested, and wraps the underlying :class:`ConnectionRefusedError` and
        :class:`APIError` in an :class:`UpstreamError`
        """
        def _wrap(exception):
            return lambda: fail(
                FirstError(
                    Failure(FirstError(Failure(exception), 0)),
                    0))

        f = self.failureResultOf(
            diagnose("system", "operation")(_wrap(APIError(200, {})))(),
            UpstreamError)
        self.assertTrue(f.value.reason.check(APIError))
        self.assertEqual(f.value.system, "system")
        self.assertEqual(f.value.operation, "operation")

        f = self.failureResultOf(
            diagnose("system", "operation")(
                _wrap(ConnectionRefusedError('meh')))(),
            UpstreamError)
        self.assertTrue(f.value.reason.check(ConnectionRefusedError))
        self.assertEqual(f.value.system, "system")
        self.assertEqual(f.value.operation, "operation")
Beispiel #2
0
    def test_diagnose_wraps_connection_and_api_errors(self):
        """
        :func:`diagnose` wraps only :class:`ConnectionRefusedError` and
        :class:`APIError`
        """
        af = fail(APIError(200, {}))
        f = self.failureResultOf(diagnose("system", "operation")(lambda: af)(),
                                 UpstreamError)
        self.assertTrue(f.value.reason.check(APIError))
        self.assertEqual(f.value.system, "system")
        self.assertEqual(f.value.operation, "operation")

        cf = fail(ConnectionRefusedError('meh'))
        f = self.failureResultOf(diagnose("system", "operation")(lambda: cf)(),
                                 UpstreamError)
        self.assertTrue(f.value.reason.check(ConnectionRefusedError))
        self.assertEqual(f.value.system, "system")
        self.assertEqual(f.value.operation, "operation")

        of = fail(ValueError('not-wrapped'))
        self.failureResultOf(diagnose("system", "operation")(lambda: of)(),
                             ValueError)
Beispiel #3
0
    def test_diagnose_keeps_first_error_if_not_apierr_or_connection_err(self):
        """
        :func:`diagnose` keeps the original :class:`FirstError`, if
        the ultimately underlying exception is not a
        :class:`ConnectionRefusedError` or :class:`APIError`
        """
        err = FirstError(
            Failure(FirstError(Failure(ValueError), 0)),
            0
        )
        f = self.failureResultOf(
            diagnose("system", "operation")(lambda: fail(err))(), FirstError)

        self.assertIs(f.value, err)