Ejemplo n.º 1
0
 def test_error_validating_observer(self):
     """
     The observer returned replaces event with error if it fails to
     type check
     """
     wrapper = SpecificationObserverWrapper(
         self.observer, lambda e: raise_(ValueError('hm')))
     wrapper({'message': ("something-bad", ), 'a': 'b'})
     self.assertEqual(self.e,
                      [{
                          'original_event': {
                              'message': ("something-bad", ),
                              'a': 'b'
                          },
                          'isError': True,
                          'failure': CheckFailureValue(ValueError('hm')),
                          'why': 'Error validating event',
                          'message': ()
                      }])
Ejemplo n.º 2
0
    def test_failure_passed_correctly(self):
        """
        The failure argument to can_retry and next_interval represents the
        error that occurred.
        """
        can_retry_failures = []
        next_interval_failures = []

        def can_retry(failure):
            can_retry_failures.append(failure)
            return True

        def next_interval(failure):
            next_interval_failures.append(failure)
            return 0.5

        sdar = ShouldDelayAndRetry(can_retry=can_retry,
                                   next_interval=next_interval)
        eff = sdar(get_exc_info())
        _perform_func_intent(eff)
        self.assertEqual(can_retry_failures, next_interval_failures)
        self.assertEqual(can_retry_failures[0],
                         CheckFailureValue(ZeroDivisionError("foo")))