Пример #1
0
    async def test_cog_app_command_error_from_sub_group_with_handler(
        self,
        mock_bot: commands.Bot,
        mock_interaction: discord.Interaction,
        mock_on_sub_group_error_handler: AsyncMock,
        sub_group_with_handler_class: Type[app_commands.Group],
    ) -> None:
        on_error = AsyncMock()
        error = app_commands.CheckFailure()

        class MyCog(commands.GroupCog):
            my_sub_group = sub_group_with_handler_class()

            def cog_app_command_error(
                self,
                interaction: discord.Interaction,
                error: app_commands.AppCommandError,
            ) -> Coroutine[Any, Any, None]:
                return on_error(self, interaction, error)

        cog = MyCog(mock_bot)

        await cog.my_sub_group.my_sub_group_command._invoke_error_handlers(
            mock_interaction, error)  # type: ignore
        mock_on_sub_group_error_handler.assert_awaited_once_with(
            cog.my_sub_group, mock_interaction, error)
        on_error.assert_awaited_once_with(cog, mock_interaction, error)
Пример #2
0
    async def test_cog_app_command_error_from_command_with_error_handler(
        self,
        mock_bot: commands.Bot,
        mock_interaction: discord.Interaction,
    ) -> None:
        on_error = AsyncMock()
        on_command_error = AsyncMock()
        error = app_commands.CheckFailure()

        class MyCog(commands.GroupCog):
            @app_commands.command()
            async def my_command(self,
                                 interaction: discord.Interaction) -> None:
                ...

            @my_command.error
            async def on_my_command_with_handler_error(
                self,
                interaction: discord.Interaction,
                error: app_commands.AppCommandError,
            ) -> None:
                await on_command_error(self, interaction, error)

            def cog_app_command_error(
                self,
                interaction: discord.Interaction,
                error: app_commands.AppCommandError,
            ) -> Coroutine[Any, Any, None]:
                return on_error(self, interaction, error)

        cog = MyCog(mock_bot)

        await cog.my_command._invoke_error_handlers(mock_interaction, error)
        on_command_error.assert_awaited_once_with(cog, mock_interaction, error)
        on_error.assert_awaited_once_with(cog, mock_interaction, error)