def test_wait_long_predicate(): """ After the actual check the predicate is held for .3 seconds. Make sure that we don't get a timeout after .2 seconds - because the actual condition should be met in .1 second! """ t = Timer() def pred(): try: return 0.1 < t.duration finally: wait(0.3) wait(0.2, pred, message=False)
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