# Path: loadsbroker/util.py
# def retry(attempts=3,
#           on_exception=None,
#           on_result=None):
#     """Retry a function multiple times, logging failures."""
#     assert on_exception or on_result
# 
#     def __retry(func):
#         @wraps(func)
#         def ___retry(*args, **kw):
#             attempt = 0
#             while True:
#                 attempt += 1
#                 try:
#                     result = func(*args, **kw)
#                 except Exception as exc:
#                     if (on_exception is None or not on_exception(exc) or
#                             attempt == attempts):
#                         logger.debug('Failed (%d/%d)' % (attempt, attempts),
#                                      exc_info=True)
#                         raise
#                 else:
#                     if (on_result is None or not on_result(result) or
#                             attempt == attempts):
#                         return result
#         return ___retry
#     return __retry


import unittest
from operator import not_
from loadsbroker.util import retry



class TestRetry(unittest.TestCase):

    def test_retry_on_result(self):
        attempts = []

        @retry(attempts=4, on_result=not_)
        def foo():
            attempts.append(None)
            return len(attempts) == 3

        self.assertTrue(foo())
        self.assertEqual(len(attempts), 3)

    def test_retry_on_result_propagate(self):
        attempts = []


# Path: loadsbroker/util.py
# def retry(attempts=3,
#           on_exception=None,
#           on_result=None):
#     """Retry a function multiple times, logging failures."""
#     assert on_exception or on_result
# 
#     def __retry(func):
#         @wraps(func)
#         def ___retry(*args, **kw):
#             attempt = 0
#             while True:
#                 attempt += 1
#                 try:
#                     result = func(*args, **kw)
#                 except Exception as exc:
#                     if (on_exception is None or not on_exception(exc) or
#                             attempt == attempts):
#                         logger.debug('Failed (%d/%d)' % (attempt, attempts),
#                                      exc_info=True)
#                         raise
#                 else:
#                     if (on_result is None or not on_result(result) or
#                             attempt == attempts):
#                         return result
#         return ___retry
#     return __retry


# Path: loadsbroker/tests/test_units/test_util.py
import unittest
from operator import not_
from loadsbroker.util import retry




class TestRetry(unittest.TestCase):

    def test_retry_on_result(self):
        attempts = []

        @retry(attempts=4, on_result=not_)
        def foo():
            attempts.append(None)
            return len(attempts) == 3

        self.assertTrue(foo())
        self.assertEqual(len(attempts), 3)

    def test_retry_on_result_propagate(self):
        attempts = []


        @retry(attempts=3, on_result=not_)