def wrapper(f): coroutine = call_on_schedule( callback=f, schedule=schedule, also_run_immediately=also_run_immediately) self.add_background_task(coroutine) return f
async def test_call_on_schedule_run_immediate(run_for, call_counter): await run_for( coroutine=call_on_schedule(callback=call_counter, schedule=schedule.every(0.1).seconds, also_run_immediately=True), seconds=0.25, ) assert call_counter.call_count == 3
async def test_call_on_schedule(run_for, call_counter, dummy_bus): await run_for( coroutine=call_on_schedule( callback=call_counter, schedule=schedule.every(0.1).seconds, also_run_immediately=False, bus_client=dummy_bus.client, ), seconds=0.25, ) assert call_counter.call_count == 2
async def test_call_on_schedule_async(run_for): import schedule await_count = 0 async def cb(): nonlocal await_count await_count += 1 await run_for( coroutine=call_on_schedule(callback=cb, schedule=schedule.every(0.1).seconds, also_run_immediately=False), seconds=0.25, ) assert await_count == 2
async def test_call_on_schedule_with_long_execution_time(run_for): """Execution time should get taken into account""" import schedule await_count = 0 async def cb(): nonlocal await_count await_count += 1 await asyncio.sleep(0.09) await run_for( coroutine=call_on_schedule(callback=cb, schedule=schedule.every(0.1).seconds, also_run_immediately=False), seconds=0.25, ) assert await_count == 2