async def test_returns_task_wrapping_given_coroutine(self, mocker, dummy_coroutine): spy_create_task = mocker.spy(asyncio, "create_task") coro_obj = dummy_coroutine() result = asyncio_compat.create_task(coro_obj) assert isinstance(result, asyncio.Task) assert spy_create_task.call_count == 1 assert spy_create_task.call_args == mocker.call(coro_obj)
async def test_returns_task_wrapping_given_coroutine_py36orless_compat( self, mocker, dummy_coroutine): spy_ensure_future = mocker.spy(asyncio, "ensure_future") coro_obj = dummy_coroutine() result = asyncio_compat.create_task(coro_obj) assert isinstance(result, asyncio.Task) assert spy_ensure_future.call_count == 1 assert spy_ensure_future.call_args == mocker.call(coro_obj)
def _add_handler_task(self, handler_name): """Create, and store a task for running a handler """ # First check if the handler task already exists if self._handler_tasks[handler_name] is not None: raise AsyncHandlerManagerException( "Cannot create task for handler: {}. Task already exists". format(handler_name)) inbox = self._get_inbox_for_handler(handler_name) if inbox: coro = self._run_inbox_handler(inbox, handler_name) else: coro = self._run_event_handler(handler_name) task = asyncio_compat.create_task(coro) # TODO: what happens if an exception is raised? self._handler_tasks[handler_name] = task