Ejemplo n.º 1
0
def test_iter_wait_progress_adv_timeout():
    with pytest.raises(TimeoutException) as exc:
        for state in iter_wait_progress(lambda: 100,
                                        advance_timeout=.1,
                                        sleep=.05,
                                        total_timeout=1):
            pass
    assert exc.value.message.startswith("did not advance")
    assert float(exc.value.duration) == pytest.approx(0.1, 0.05)
Ejemplo n.º 2
0
def test_iter_wait_progress_total_timeout():
    data = Bunch(a=1000)

    def get():
        data.a -= 1
        return data.a

    with pytest.raises(TimeoutException) as exc:
        for state in iter_wait_progress(get,
                                        advance_timeout=1,
                                        sleep=.05,
                                        total_timeout=.1):
            pass
    assert exc.value.message.startswith("advanced but failed to finish")
Ejemplo n.º 3
0
def test_iter_wait_progress_inbetween_sleep():
    data = Bunch(a=3)

    def get():
        data.a -= 1
        return data.a

    sleep = .1
    g = iter_wait_progress(get, advance_timeout=10, sleep=sleep)

    # first iteration should be immediate
    t = Timer()
    next(g)
    assert t.duration < sleep

    # subsequent iteration should be at least 'sleep' long
    next(g)
    assert t.duration >= sleep

    for state in g:
        pass
    assert state.finished is True