示例#1
0
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')
示例#2
0
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)
示例#3
0
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()
示例#4
0
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)
示例#5
0
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)
示例#6
0
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)
示例#7
0
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)
示例#8
0
def test_fail_on_delay_longer_than_max_wait_time():
    with pytest.raises(ValueError):
        wait().poll_delay(11, SECOND).until(lambda: True)
示例#9
0
def test_nested_waits():
    def condition():
        return wait().until(lambda: True)

    assert wait().until(condition)
示例#10
0
def test_fail_on_exception_if_not_ignored():
    with pytest.raises(ZeroDivisionError):
        wait().at_most(ONE_SECOND).until(raise_error)
示例#11
0
def test_wait_until_condition_passed():
    with assert_done_after(seconds=0.3) as c:
        wait().until(lambda: c.done)
示例#12
0
def test_wait_until_condition_fail():
    with assert_done_after(seconds=0.2) as c:
        wait().during(lambda: not c.done)
示例#13
0
def test_start_with_given():
    assert given() == wait()
    assert given().wait().at_most(ONE_SECOND) == wait().at_most(ONE_SECOND)
示例#14
0
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)
示例#15
0
def test_wait_until_condition_passed():
    countdown = CountDown()
    countdown.start_from(3)
    wait().until(lambda: countdown.done)
    assert countdown.done
示例#16
0
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))
示例#17
0
def test_timeout_when_not_asserted_in_time():
    with pytest.raises(ConditionTimeoutError):
        wait().at_most(ONE_HUNDRED_MILLISECONDS).until_asserted(
            _failed_assertion)
示例#18
0
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)
示例#19
0
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)
示例#20
0
def test_retrieve_condition_result():
    assert wait().until(lambda: 3) == 3
示例#21
0
def test_set_default_timeout():
    set_default_timeout(500, MILLISECOND)
    with pytest.raises(ConditionTimeoutError):
        wait().until(lambda: 1 == 2)
示例#22
0
 def condition():
     return wait().until(lambda: True)
示例#23
0
def test_default_delay():
    with _verify_delay_is(DEFAULT_POLL_DELAY) as recorder:
        wait().until(lambda: recorder.record())
示例#24
0
def test_should_ignore_all_exceptions():
    with pytest.raises(ConditionTimeoutError):
        wait().ignore_exceptions().at_most(200, MILLISECOND).until(raise_error)
示例#25
0
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())