Ejemplo n.º 1
0
    async def test_command_decorator_single(self, alias: str):
        """
        Verify`Commands.command` decorator can handle string registrations
        """
        Commands._flush()

        # bunch of commands to test

        @Commands.command(alias)
        async def potato(bot: pydle.Client, channel: str, sender: str):
            # print(f"bot={bot}\tchannel={channel}\tsender={sender}")
            return bot, channel, sender

        assert alias.lower() in Commands._registered_commands.keys()
Ejemplo n.º 2
0
    async def test_command_preserves_arguments(self, trigger_message: str,
                                               name: str, bot_fx):
        """
        Verifies commands do not mutate argument words
            - because someone had the bright idea of casting ALL words to lower...
            (that would break things)
        """
        Commands._flush()
        ftrigger = f"!{name} {trigger_message}"
        words = [name] + trigger_message.split(" ")

        @Commands.command(name)
        async def the_command(context: Context):
            """asserts its arguments equal the outer scope"""
            assert words == context.words

        ctx = await Context.from_message(bot_fx, "#unit_test", "unit_test",
                                         ftrigger)
        await Commands.trigger(ctx)
Ejemplo n.º 3
0
    async def test_call_command(self, alias, bot_fx):
        """
        Verifiy that found commands can be invoked via Commands.Trigger()
        """
        Commands._flush()

        trigger_alias = f"{Commands.prefix}{alias}"

        @Commands.command(alias)
        async def potato(context: Context):
            # print(f"bot={bot}\tchannel={channel}\tsender={sender}")
            return context.bot, context.channel, context.user.nickname

        ctx = await Context.from_message(bot_fx, "#unittest", "unit_test",
                                         trigger_alias)
        retn = await Commands.trigger(ctx)
        out_bot, out_channel, out_sender = retn

        assert 'unit_test' == out_sender
        assert "#unittest" == out_channel
Ejemplo n.º 4
0
def Setup_fx(bot_fx):
    """Sets up the test environment"""
    Commands._flush()
    Commands.bot = bot_fx