コード例 #1
0
ファイル: test_snekbox.py プロジェクト: denene12/bot2
    async def test_send_eval_with_paste_link(self):
        """Test the send_eval function with a too long output that generate a paste link."""
        ctx = MockContext()
        ctx.message = MockMessage()
        ctx.send = AsyncMock()
        ctx.author.mention = '@LemonLemonishBeard#0042'

        self.cog.post_eval = AsyncMock(return_value={'stdout': 'Way too long beard', 'returncode': 0})
        self.cog.get_results_message = MagicMock(return_value=('Return code 0', ''))
        self.cog.get_status_emoji = MagicMock(return_value=':yay!:')
        self.cog.format_output = AsyncMock(return_value=('Way too long beard', 'lookatmybeard.com'))

        mocked_filter_cog = MagicMock()
        mocked_filter_cog.filter_eval = AsyncMock(return_value=False)
        self.bot.get_cog.return_value = mocked_filter_cog

        await self.cog.send_eval(ctx, 'MyAwesomeCode')
        ctx.send.assert_called_once_with(
            '@LemonLemonishBeard#0042 :yay!: Return code 0.'
            '\n\n```\nWay too long beard\n```\nFull output: lookatmybeard.com'
        )
        self.cog.post_eval.assert_called_once_with('MyAwesomeCode')
        self.cog.get_status_emoji.assert_called_once_with({'stdout': 'Way too long beard', 'returncode': 0})
        self.cog.get_results_message.assert_called_once_with({'stdout': 'Way too long beard', 'returncode': 0})
        self.cog.format_output.assert_called_once_with('Way too long beard')
コード例 #2
0
ファイル: test_snekbox.py プロジェクト: Aurelius41/song
    async def test_send_eval_with_non_zero_eval(self):
        """Test the send_eval function with a code returning a non-zero code."""
        ctx = MockContext()
        ctx.message = MockMessage()
        ctx.send = AsyncMock()
        ctx.author.mention = '@LemonLemonishBeard#0042'
        self.cog.post_eval = AsyncMock(return_value={
            'stdout': 'ERROR',
            'returncode': 127
        })
        self.cog.get_results_message = MagicMock(
            return_value=('Return code 127', 'Beard got stuck in the eval'))
        self.cog.get_status_emoji = MagicMock(return_value=':nope!:')
        self.cog.format_output = AsyncMock()  # This function isn't called

        await self.cog.send_eval(ctx, 'MyAwesomeCode')
        ctx.send.assert_called_once_with(
            '@LemonLemonishBeard#0042 :nope!: Return code 127.\n\n```py\nBeard got stuck in the eval\n```'
        )
        self.cog.post_eval.assert_called_once_with('MyAwesomeCode')
        self.cog.get_status_emoji.assert_called_once_with({
            'stdout': 'ERROR',
            'returncode': 127
        })
        self.cog.get_results_message.assert_called_once_with({
            'stdout': 'ERROR',
            'returncode': 127
        })
        self.cog.format_output.assert_not_called()
コード例 #3
0
ファイル: test_snekbox.py プロジェクト: Aurelius41/song
    async def test_send_eval(self):
        """Test the send_eval function."""
        ctx = MockContext()
        ctx.message = MockMessage()
        ctx.send = AsyncMock()
        ctx.author.mention = '@LemonLemonishBeard#0042'

        self.cog.post_eval = AsyncMock(return_value={
            'stdout': '',
            'returncode': 0
        })
        self.cog.get_results_message = MagicMock(return_value=('Return code 0',
                                                               ''))
        self.cog.get_status_emoji = MagicMock(return_value=':yay!:')
        self.cog.format_output = AsyncMock(return_value=('[No output]', None))

        await self.cog.send_eval(ctx, 'MyAwesomeCode')
        ctx.send.assert_called_once_with(
            '@LemonLemonishBeard#0042 :yay!: Return code 0.\n\n```py\n[No output]\n```'
        )
        self.cog.post_eval.assert_called_once_with('MyAwesomeCode')
        self.cog.get_status_emoji.assert_called_once_with({
            'stdout': '',
            'returncode': 0
        })
        self.cog.get_results_message.assert_called_once_with({
            'stdout': '',
            'returncode': 0
        })
        self.cog.format_output.assert_called_once_with('')
コード例 #4
0
ファイル: test_snekbox.py プロジェクト: denene12/bot2
 async def test_eval_command_reject_two_eval_at_the_same_time(self):
     """Test if the eval command rejects an eval if the author already have a running eval."""
     ctx = MockContext()
     ctx.author.id = 42
     ctx.author.mention = '@LemonLemonishBeard#0042'
     ctx.send = AsyncMock()
     self.cog.jobs = (42,)
     await self.cog.eval_command(self.cog, ctx=ctx, code='MyAwesomeCode')
     ctx.send.assert_called_once_with(
         "@LemonLemonishBeard#0042 You've already got a job running - please wait for it to finish!"
     )