示例#1
0
async def test_waiting_until_on_fails_when_not_turned_on():
    toggle = Toggle(False)

    with pytest.raises(asyncio.TimeoutError):
        await asyncio.wait_for(toggle.wait_for_on(), timeout=0.1)

    assert not toggle
示例#2
0
async def test_waiting_until_on_wakes_when_turned_on(timer):
    toggle = Toggle(False)

    async def delayed_turning_on(delay: float):
        await asyncio.sleep(delay)
        await toggle.turn_on()

    with timer:
        asyncio.create_task(delayed_turning_on(0.05))
        await asyncio.wait_for(toggle.wait_for_on(), timeout=1.0)

    assert toggle
    assert timer.seconds < 0.5  # approx. 0.05 plus some code overhead