Beispiel #1
0
    def test_args_and_kwargs_passed(self):
        """ Args and kwargs passed to `retry` or to the function decorated with `@retry_on_error`
            should be passed to the wrapped function.
        """
        def flakey(a, b, c=None):
            self.assertEqual(a, 1)
            self.assertEqual(b, 2)
            self.assertEqual(c, 3)

        retry(flakey, 1, 2, c=3)
        retry_on_error()(flakey)(1, 2, c=3)
Beispiel #2
0
    def test_args_and_kwargs_passed(self):
        """ Args and kwargs passed to `retry` or to the function decorated with `@retry_on_error`
            should be passed to the wrapped function.
        """

        def flakey(a, b, c=None):
            self.assertEqual(a, 1)
            self.assertEqual(b, 2)
            self.assertEqual(c, 3)

        retry(flakey, 1, 2, c=3)
        retry_on_error()(flakey)(1, 2, c=3)
Beispiel #3
0
    def test_catch_param(self):
        """ It should only catch the exceptions given. """

        def flakey():
            flakey.attempts += 1
            raise ValueError("Oops")

        flakey.attempts = 0

        # If we only except TypeError then ValueError should raise immediately
        self.assertRaises(ValueError, retry_on_error(_catch=TypeError)(flakey))
        self.assertEqual(flakey.attempts, 1)  # Only 1 attempt should have been made
        # With the correct _catch param, it should catch our exception
        flakey.attempts = 0  # reset
        self.assertRaises(ValueError, retry_on_error(_catch=ValueError, _initial_wait=0, _attempts=5)(flakey))
        self.assertEqual(flakey.attempts, 5)
Beispiel #4
0
    def test_catch_param(self):
        """ It should only catch the exceptions given. """
        def flakey():
            flakey.attempts += 1
            raise ValueError("Oops")

        flakey.attempts = 0

        # If we only except TypeError then ValueError should raise immediately
        self.assertRaises(ValueError, retry_on_error(_catch=TypeError)(flakey))
        self.assertEqual(flakey.attempts,
                         1)  # Only 1 attempt should have been made
        # With the correct _catch param, it should catch our exception
        flakey.attempts = 0  # reset
        self.assertRaises(
            ValueError,
            retry_on_error(_catch=ValueError, _initial_wait=0,
                           _attempts=5)(flakey))
        self.assertEqual(flakey.attempts, 5)