From 6451f3f700c1c09405540fb70ac800f56bac27de Mon Sep 17 00:00:00 2001 From: Denis Navarro Date: Wed, 19 Oct 2022 16:35:23 +0200 Subject: [PATCH] fix: make internal command hooks callables again --- aiocli/commander_app.py | 8 +++----- aiocli/test_utils.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/aiocli/commander_app.py b/aiocli/commander_app.py index b594492..7231076 100644 --- a/aiocli/commander_app.py +++ b/aiocli/commander_app.py @@ -566,13 +566,11 @@ async def _execute_command_hooks( command_hooks_ = ( command_hooks if all_hooks - else [ - hook.__call__ - for hook in command_hooks - if isinstance(hook, InternalCommandHook) and not ignore_internal_hooks - ] + else [hook for hook in command_hooks if isinstance(hook, InternalCommandHook) and not ignore_internal_hooks] ) for hook in command_hooks_: + if isinstance(hook, InternalCommandHook): + hook = hook.__call__ self._log( msg='Executing hook "{0}" ({1})'.format( hook.__name__ if hasattr(hook, '__name__') else 'unknown', id(hook) diff --git a/aiocli/test_utils.py b/aiocli/test_utils.py index d3bc49f..9bb8ee8 100644 --- a/aiocli/test_utils.py +++ b/aiocli/test_utils.py @@ -12,16 +12,22 @@ class TestCommander: _app: Application _loop: AbstractEventLoop _runner: Optional[AppRunner] + _all_hooks: bool + _ignore_internal_hooks: bool def __init__( self, app: Union[Application, Callable[[], Application]], *, loop: Optional[AbstractEventLoop] = None, + all_hooks: bool = True, + ignore_internal_hooks: bool = False, ) -> None: self._app = app if isinstance(app, Application) else app() self._loop = loop or get_event_loop() self._runner = None + self._all_hooks = all_hooks + self._ignore_internal_hooks = ignore_internal_hooks async def handle( self, @@ -41,15 +47,15 @@ async def start_commander(self, **kwargs: Any) -> None: if self._runner: return self._runner = await self._make_runner(**kwargs) - await self._runner.setup(all_hooks=True) + await self._runner.setup(all_hooks=self._all_hooks, ignore_internal_hooks=self._ignore_internal_hooks) async def __aenter__(self) -> 'TestCommander': - await self.start_commander() + await self.start_commander(all_hooks=self._all_hooks, ignore_internal_hooks=self._ignore_internal_hooks) return self async def close(self) -> None: if self._runner: - await self._runner.cleanup() + await self._runner.cleanup(all_hooks=self._all_hooks, ignore_internal_hooks=self._ignore_internal_hooks) async def __aexit__( self,