コード例 #1
0
def test_no_args(passes):
    """Use the decorator without passing any args or calling the decorator

    @retry
    def fn():
        #...
    """
    wrapped = retrace.retry(passes)
    assert wrapped() == 1
コード例 #2
0
def test_no_args_instance(passes):
    """Use the decorator without passing any args or but call the decorator

    @retry()
    def fn():
        #...
    """
    wrapped = retrace.retry()(passes)
    assert wrapped() == 1
コード例 #3
0
def test_validator_pass(passes):
    """Use the decorator without passing any args or calling the decorator

    @retry
    def fn():
        #...
    """
    wrapped = retrace.retry(validator=1)(passes)

    assert 1 == wrapped()
コード例 #4
0
ファイル: test_limits.py プロジェクト: widy28/retrace
def test_limit_passed_first_time(passes):
    """Use the decorator and only retry on specific exceptions. The wrapped
    method raises a KeyboardInterrupt but we only want to retry on an Exception

    @retry()
    def fn():
        #...
    """
    wrapped = retrace.retry()(passes)
    assert wrapped() == 1
コード例 #5
0
ファイル: test_limits.py プロジェクト: d0ugal/retrace
def test_limit_passed_first_time(passes):
    """Use the decorator and only retry on specific exceptions. The wrapped
    method raises a KeyboardInterrupt but we only want to retry on an Exception

    @retry()
    def fn():
        #...
    """
    wrapped = retrace.retry()(passes)
    assert wrapped() == 1
コード例 #6
0
ファイル: test_limits.py プロジェクト: d0ugal/retrace
def test_limit_always_fails(fails):
    """Use the decorator and only retry on specific exceptions. The wrapped
    method raises a KeyboardInterrupt but we only want to retry on an Exception

    @retry()
    def fn():
        #...
    """
    wrapped = retrace.retry()(fails)
    with pytest.raises(retrace.LimitReached):
        wrapped(Exception)
コード例 #7
0
ファイル: test_limits.py プロジェクト: widy28/retrace
def test_limit_always_fails(fails):
    """Use the decorator and only retry on specific exceptions. The wrapped
    method raises a KeyboardInterrupt but we only want to retry on an Exception

    @retry()
    def fn():
        #...
    """
    wrapped = retrace.retry()(fails)
    with pytest.raises(retrace.LimitReached):
        wrapped(Exception)
コード例 #8
0
def test_raises(keyboard_interrupt):
    """Use the decorator and only retry on specific exceptions. The wrapped
    method raises a KeyboardInterrupt but we only want to retry on an Exception

    @retry()
    def fn():
        #...
    """
    wrapped = retrace.retry(on_exception=Exception)(keyboard_interrupt)
    with pytest.raises(KeyboardInterrupt):
        wrapped(KeyboardInterrupt())
コード例 #9
0
def test_validator_limit_value(passes):
    """Use the decorator without passing any args or calling the decorator

    @retry
    def fn():
        #...
    """
    wrapped = retrace.retry(validator=2)(passes)

    with pytest.raises(retrace.LimitReached):
        wrapped()
コード例 #10
0
ファイル: test_limits.py プロジェクト: d0ugal/retrace
def test_limit_fn(fails):

    start = time.time()
    count = [0]

    def limit_1_sec(attempt_number):
        """Create a limiter that allows as many calls as possible in 0.1s"""
        count[0] += 1
        if time.time() - start > 0.1:
            raise retrace.LimitReached()

    wrapped = retrace.retry(limit=limit_1_sec)(fails)

    with pytest.raises(retrace.LimitReached):
        wrapped()

    assert fails.call_count == count[0]
コード例 #11
0
ファイル: test_limits.py プロジェクト: widy28/retrace
def test_limit_fn(fails):

    start = time.time()
    count = [0]

    def limit_1_sec(attempt_number):
        """Create a limiter that allows as many calls as possible in 0.1s"""
        count[0] += 1
        if time.time() - start > .1:
            raise retrace.LimitReached()

    wrapped = retrace.retry(limit=limit_1_sec)(fails)

    with pytest.raises(retrace.LimitReached):
        wrapped()

    assert fails.call_count == count[0]
コード例 #12
0
ファイル: test_limits.py プロジェクト: d0ugal/retrace
def test_limit_class(fails):
    class LimitSeconds(object):
        def __init__(self, seconds):
            self.seconds = seconds
            self.count = 0
            self.start = None

        def __call__(self, attempt_number):
            """Create a limiter that allows as many calls as possible in 0.1s"""

            if self.start is None:
                self.start = time.time()

            self.count += 1
            if time.time() - self.start > self.seconds:
                raise retrace.LimitReached()

    limiter = LimitSeconds(0.1)
    wrapped = retrace.retry(limit=limiter)(fails)

    with pytest.raises(retrace.LimitReached):
        wrapped()

    assert fails.call_count == limiter.count
コード例 #13
0
ファイル: test_limits.py プロジェクト: widy28/retrace
def test_limit_class(fails):
    class LimitSeconds(object):
        def __init__(self, seconds):
            self.seconds = seconds
            self.count = 0
            self.start = None

        def __call__(self, attempt_number):
            """Create a limiter that allows as many calls as possible in 0.1s"""

            if self.start is None:
                self.start = time.time()

            self.count += 1
            if time.time() - self.start > self.seconds:
                raise retrace.LimitReached()

    limiter = LimitSeconds(0.1)
    wrapped = retrace.retry(limit=limiter)(fails)

    with pytest.raises(retrace.LimitReached):
        wrapped()

    assert fails.call_count == limiter.count
コード例 #14
0
ファイル: test_limits.py プロジェクト: d0ugal/retrace
def test_fails_4_times_and_hits_limit(fail_then_pass):
    mock, fail_then_pass = fail_then_pass
    wrapped = retrace.retry(limit=4)(fail_then_pass)
    with pytest.raises(retrace.LimitReached):
        wrapped()
    assert mock.call_count == 4
コード例 #15
0
ファイル: test_limits.py プロジェクト: d0ugal/retrace
def test_fails_then_pass(fail_then_pass):
    mock, fail_then_pass = fail_then_pass
    wrapped = retrace.retry()(fail_then_pass)
    assert wrapped() == "PASS"
    assert mock.call_count == 5
コード例 #16
0
def test_limit_reached_float(fails):
    with pytest.raises(retrace.LimitReached):
        wrapped = retrace.retry(interval=.1)(fails)
        wrapped(Exception)
コード例 #17
0
ファイル: test_limits.py プロジェクト: widy28/retrace
def test_fails_4_times_and_hits_limit(fail_then_pass):
    mock, fail_then_pass = fail_then_pass
    wrapped = retrace.retry(limit=4)(fail_then_pass)
    with pytest.raises(retrace.LimitReached):
        wrapped()
    assert mock.call_count == 4
コード例 #18
0
ファイル: test_limits.py プロジェクト: widy28/retrace
def test_fails_then_pass(fail_then_pass):
    mock, fail_then_pass = fail_then_pass
    wrapped = retrace.retry()(fail_then_pass)
    assert wrapped() == "PASS"
    assert mock.call_count == 5
コード例 #19
0
def test_limit_passed(passes):
    wrapped = retrace.retry(interval=0.1)(passes)
    assert wrapped() == 1
コード例 #20
0
def test_limit_passed(passes):
    wrapped = retrace.retry(interval=.1)(passes)
    assert wrapped() == 1
コード例 #21
0
def test_limit_reached_float(fails):
    with pytest.raises(conftest.CustomException):
        wrapped = retrace.retry(interval=0.001)(fails)
        wrapped(Exception)