def wrapper(f): coroutine = call_every( # pylint: assignment-from-no-return callback=f, timedelta=td, also_run_immediately=also_run_immediately) self.add_background_task(coroutine) return f
async def test_call_every_run_immediate(run_for, call_counter): await run_for( coroutine=call_every(callback=call_counter, timedelta=timedelta(seconds=0.1), also_run_immediately=True), seconds=0.25, ) assert call_counter.call_count == 3
async def test_call_every_run_immediate(run_for, call_counter, dummy_bus): await run_for( coroutine=call_every( callback=call_counter, timedelta=timedelta(seconds=0.1), also_run_immediately=True, bus_client=dummy_bus.busdummy_bus, ), seconds=0.25, ) assert call_counter.call_count == 3
async def test_call_every_async(run_for): await_count = 0 async def cb(): nonlocal await_count await_count += 1 await run_for( coroutine=call_every(callback=cb, timedelta=timedelta(seconds=0.1), also_run_immediately=False), seconds=0.25, ) assert await_count == 2
async def test_call_every_with_long_execution_time(run_for): """Execution time should get taken into account""" await_count = 0 async def cb(): nonlocal await_count await_count += 1 await asyncio.sleep(0.09) await run_for( coroutine=call_every(callback=cb, timedelta=timedelta(seconds=0.1), also_run_immediately=False), seconds=0.25, ) assert await_count == 2