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
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
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
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
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
def undefined_timeout(): """ Fixture that yields a :class:`~adbtp.timeouts.Timeout` that was created using the timeout sentinel value. """ return timeouts.Timeout(timeouts.UNDEFINED)
def not_started_timeout(): """ Fixture that yields a :class:`~adbtp.timeouts.Timeout` that has not been started. """ return timeouts.Timeout(1)
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