示例#1
0
def test_remaining_milliseconds_computes_delta():
    """
    Assert that :prop:`~adbts.timeouts.Timeout.remaining_milliseconds` computes its value from the
    elapsed time.
    """
    with timeouts.Timeout(5) as timeout:
        time.sleep(1)
        assert timeout.remaining_milliseconds <= 4000
示例#2
0
def stopped_timeout():
    """
    Fixture that yields a :class:`~adbtp.timeouts.Timeout` that has been started and stopped.
    """
    timeout = timeouts.Timeout(1)
    timeout.start()
    timeout.stop()
    return timeout
示例#3
0
def test_timeout_not_exceeded_when_elapsed_less_than_period():
    """
    Assert that :prop:`~adbts.timeouts.Timeout.exceeded` returns `False` when elapsed does not
    exceed the period.
    """
    with timeouts.Timeout(5) as timeout:
        assert not timeout.exceeded
        time.sleep(0.5)
        assert not timeout.exceeded
示例#4
0
def test_timeout_exceeded_when_elapsed_greater_than_period():
    """
    Assert that :prop:`~adbts.timeouts.Timeout.exceeded` returns `True` after period
    has been exhausted.
    """
    with timeouts.Timeout(0.5) as timeout:
        assert not timeout.exceeded
        time.sleep(1)
        assert timeout.exceeded
示例#5
0
def test_elapsed_millisseconds_increments_when_not_stopped():
    """
    Assert that :prop:`~adbts.timeouts.Timeout.elapsed_milliseconds` continues to increment when
    it is not stopped.
    """
    with timeouts.Timeout(5) as timeout:
        for _ in range(0, 3):
            prev = timeout.elapsed_milliseconds
            time.sleep(1)
            assert timeout.elapsed_milliseconds >= prev + 1000
示例#6
0
def undefined_timeout():
    """
    Fixture that yields a :class:`~adbtp.timeouts.Timeout` that was created using the timeout sentinel value.
    """
    return timeouts.Timeout(timeouts.UNDEFINED)
示例#7
0
def not_started_timeout():
    """
    Fixture that yields a :class:`~adbtp.timeouts.Timeout` that has not been started.
    """
    return timeouts.Timeout(1)
示例#8
0
def test_period_property_returns_given_value(valid_period):
    """
    Assert that :prop:`~adbtp.timeouts.Timeout.period` returns the given period time value.
    """
    timeout = timeouts.Timeout(valid_period)
    assert timeout.period == valid_period