def test_timeout_when_condition_did_not_meet_in_time(): with pytest.raises(ConditionTimeoutError): wait().at_most(FIVE_HUNDRED_MILLISECONDS).until(lambda: 1 == 2) with pytest.raises(ConditionTimeoutError): wait().at_most(100, MILLISECOND).until(lambda: False) with pytest.raises(ConditionTimeoutError): wait_at_most(100, MILLISECOND).until(lambda: 'Pizza' == 'Pie')
def test_fail_on_exception_if_not_specified(): with pytest.raises(ZeroDivisionError): wait().ignore_exceptions(AttributeError).at_most(ONE_SECOND).until( raise_error) with pytest.raises(ConditionTimeoutError): wait().ignore_exceptions(AttributeError, ZeroDivisionError).at_most( 200, MILLISECOND).until(raise_error)
def test_produce_message_by_topic(app): with Connection(RABBIT_URI) as conn: message_consumer = MessagesConsumer(conn) Thread(target=message_consumer.run).start() app.publish(topic='user_logged_in', message='userID') wait().at_most(FIVE_SECONDS).until( lambda: 'userID' in message_consumer.received_messages) message_consumer.stop()
def test_consume_using_function_handler(app): received_messages = [] count = [] @app.handler('status_changed') def status_changed_handler(message): received_messages.append(message) Thread(target=app.start).start() sleep(1) _send_message('status_changed', 'enabled') wait().at_most(FIVE_SECONDS).until(lambda: 'enabled' in received_messages)
def test_combine_wait_and_at_most(): assert wait().at_most(ONE_SECOND) == wait_at_most(ONE_SECOND) assert wait().at_most(2, MILLISECOND) == wait_at_most(2, MILLISECOND) assert given().wait_at_most(2, MILLISECOND) == wait().at_most(2, MILLISECOND)
def test_poll_with_specific_interval(): with _verify_poll_interval_is(FIVE_HUNDRED_MILLISECONDS) as verifier: wait().poll_interval(FIVE_HUNDRED_MILLISECONDS).until(verifier.record) with _verify_poll_interval_is(200 * MILLISECOND) as verifier: wait().poll_interval(200, MILLISECOND).until(verifier.record)
def test_retrieve_assertion_error_as_cause_on_timeout(): with pytest.raises(ConditionTimeoutError) as e: wait().at_most(ONE_HUNDRED_MILLISECONDS).until_asserted( _failed_assertion) assert isinstance(e.value.__cause__, AssertionError)
def test_fail_on_delay_longer_than_max_wait_time(): with pytest.raises(ValueError): wait().poll_delay(11, SECOND).until(lambda: True)
def test_nested_waits(): def condition(): return wait().until(lambda: True) assert wait().until(condition)
def test_fail_on_exception_if_not_ignored(): with pytest.raises(ZeroDivisionError): wait().at_most(ONE_SECOND).until(raise_error)
def test_wait_until_condition_passed(): with assert_done_after(seconds=0.3) as c: wait().until(lambda: c.done)
def test_wait_until_condition_fail(): with assert_done_after(seconds=0.2) as c: wait().during(lambda: not c.done)
def test_start_with_given(): assert given() == wait() assert given().wait().at_most(ONE_SECOND) == wait().at_most(ONE_SECOND)
def test_retrieve_cause_on_timeout(): with pytest.raises(ConditionTimeoutError) as e: wait().ignore_exceptions().at_most( 100, MILLISECOND).until(raise_zero_division_error) assert isinstance(e.value.__cause__, ZeroDivisionError)
def test_wait_until_condition_passed(): countdown = CountDown() countdown.start_from(3) wait().until(lambda: countdown.done) assert countdown.done
def test_wait_for_async_assertion_to_pass(): with assert_done_after(seconds=0.5) as c: wait().until_asserted(partial(_assert_is_done_async, c))
def test_timeout_when_not_asserted_in_time(): with pytest.raises(ConditionTimeoutError): wait().at_most(ONE_HUNDRED_MILLISECONDS).until_asserted( _failed_assertion)
def test_wait_until_condition_passed_after_using_event_loop(): run(asyncio.sleep(0.1)) with assert_done_after(seconds=0.3) as c: wait().until(lambda: c.done)
def test_reset_default_timeout(): set_default_timeout(200, MILLISECOND) reset_defaults() with assert_done_after(seconds=0.4) as c: wait().until(lambda: c.done)
def test_retrieve_condition_result(): assert wait().until(lambda: 3) == 3
def test_set_default_timeout(): set_default_timeout(500, MILLISECOND) with pytest.raises(ConditionTimeoutError): wait().until(lambda: 1 == 2)
def condition(): return wait().until(lambda: True)
def test_default_delay(): with _verify_delay_is(DEFAULT_POLL_DELAY) as recorder: wait().until(lambda: recorder.record())
def test_should_ignore_all_exceptions(): with pytest.raises(ConditionTimeoutError): wait().ignore_exceptions().at_most(200, MILLISECOND).until(raise_error)
def test_delay_with_specific_value(): with _verify_delay_is(FIVE_HUNDRED_MILLISECONDS) as recorder: wait().poll_delay(FIVE_HUNDRED_MILLISECONDS).until( lambda: recorder.record()) with _verify_delay_is(200 * MILLISECOND) as recorder: wait().poll_delay(200, MILLISECOND).until(lambda: recorder.record())