def test_loop_wrapper(): async def task1(): pass async def task2(): pass async def task3(): pass lw = LoopWrapper(tasks=[task1]) lw.on_startup.append(task2) lw.on_shutdown.append(task3) lw.run_forever(MockedLoop()) assert ctx_storage.get("checked-test-lw-create-task") == task1.__name__ assert ctx_storage.get("checked-test-lw-run-until-complete") == [ task2.__name__, task3.__name__, ] assert ctx_storage.get("checked-test-lw-run-forever")
def __init__( self, token: Optional[str] = None, api: Optional[ABCAPI] = None, polling: Optional[ABCPolling] = None, loop: Optional[AbstractEventLoop] = None, loop_wrapper: Optional[LoopWrapper] = None, router: Optional["ABCRouter"] = None, labeler: Optional["ABCBotLabeler"] = None, error_handler: Optional["ABCErrorHandler"] = None, ): self.api: Union[ABCAPI, API] = API( token) if token is not None else api # type: ignore self.error_handler = error_handler or ErrorHandler() self.loop_wrapper = loop_wrapper or LoopWrapper() self.labeler = labeler or BotLabeler() self.state_dispenser = BuiltinStateDispenser() self._polling = polling or BotPolling(self.api) self._router = router or BotRouter() self._loop = loop
def __init__( self, token: Optional["Token"] = None, api: Optional["ABCAPI"] = None, polling: Optional["ABCPolling"] = None, loop: Optional["AbstractEventLoop"] = None, loop_wrapper: Optional[LoopWrapper] = None, router: Optional["ABCRouter"] = None, labeler: Optional["ABCLabeler"] = None, state_dispenser: Optional["ABCStateDispenser"] = None, error_handler: Optional["ABCErrorHandler"] = None, task_each_event: bool = True, ): self.api: Union["ABCAPI", API] = API(token) if token is not None else api # type: ignore self.error_handler = error_handler or ErrorHandler() self.loop_wrapper = loop_wrapper or LoopWrapper() self.labeler = labeler or UserLabeler() self.state_dispenser = state_dispenser or BuiltinStateDispenser() self._polling = polling or UserPolling(self.api) self._router = router or Router() self._loop = loop self.task_each_event = task_each_event