Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions aiocli/commander_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions aiocli/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down