Beispiel #1
0
    def test_result_errors(self):
        """Test each error code and ensure the user will be alerted of
        errors via private message instead of in compiled replies.
        """
        with patch('{}.cb.compile'.format(__name__)) as mock_compile:
            for error_code in [13, 17, 19, 20, 12]:
                mock_compile.return_value = {
                    'cmpinfo': "",
                    'input': "",
                    'langName': "Python",
                    'output': "Test",
                    'result': error_code,
                    'stderr': "Error message",
                    'link': ""
                }
                body = ("+/u/{user} python\n\n"
                        "    error\n\n".format(user=self.user))
                comment = self.Comment(body)
                reply = cb.create_reply(comment)
                self.assertIsInstance(reply, cb.MessageReply)

            body = ("+/u/{user} python --include-errors\n\n"
                    "    error\n\n".format(user=self.user))
            comment = self.Comment(body)
            reply = cb.create_reply(comment)
            self.assertIsInstance(reply, cb.CompiledReply)
Beispiel #2
0
    def test_result_errors(self):
        """Test each error code and ensure the user will be alerted of
        errors via private message instead of in compiled replies.
        """
        with patch('{}.cb.compile'.format(__name__)) as mock_compile:
            for error_code in [13, 17, 19, 20, 12]:
                mock_compile.return_value = {
                    'cmpinfo': "",
                    'input': "",
                    'langName': "Python",
                    'output': "Test",
                    'result': error_code,
                    'stderr': "Error message",
                    'link': ""
                }
                body = ("+/u/{user} python\n\n"
                        "    error\n\n".format(user=self.user))
                comment = self.Comment(body)
                reply = cb.create_reply(comment)
                self.assertIsInstance(reply, cb.MessageReply)

            body = ("+/u/{user} python --include-errors\n\n"
                    "    error\n\n".format(user=self.user))
            comment = self.Comment(body)
            reply = cb.create_reply(comment)
            self.assertIsInstance(reply, cb.CompiledReply)
Beispiel #3
0
 def test_result_errors(self):
     # Test each error code and ensure the user will be alerted of
     # errors via private message instead of in compiled replies.
     for error_code in [13, 17, 19, 20, 12]:
         def compile(*args, **kwargs):
             return {
                 'cmpinfo': "",
                 'input': "",
                 'langName': "Python",
                 'output': "Test",
                 'result': error_code,
                 'stderr': "Error message",
                 'link': ""
             }
         cb.compile = compile
         body = ("+/u/{user} python\n\n"
                 "    error\n\n".format(user=self.user))
         comment = self.Comment(body)
         reply = cb.create_reply(comment)
         self.assertIsInstance(reply, cb.MessageReply)
     body = ("+/u/{user} python --include-errors\n\n"
             "    error\n\n".format(user=self.user))
     comment = self.Comment(body)
     reply = cb.create_reply(comment)
     self.assertIsInstance(reply, cb.CompiledReply)
Beispiel #4
0
    def test_result_errors(self):
        # Test each error code and ensure the user will be alerted of
        # errors via private message instead of in compiled replies.
        for error_code in [13, 17, 19, 20, 12]:

            def compile(*args, **kwargs):
                return {
                    'cmpinfo': "",
                    'input': "",
                    'langName': "Python",
                    'output': "Test",
                    'result': error_code,
                    'stderr': "Error message",
                    'link': ""
                }

            cb.compile = compile
            body = ("+/u/{user} python\n\n"
                    "    error\n\n".format(user=self.user))
            comment = self.Comment(body)
            reply = cb.create_reply(comment)
            self.assertIsInstance(reply, cb.MessageReply)
        body = ("+/u/{user} python --include-errors\n\n"
                "    error\n\n".format(user=self.user))
        comment = self.Comment(body)
        reply = cb.create_reply(comment)
        self.assertIsInstance(reply, cb.CompiledReply)
Beispiel #5
0
 def test_missing_language(self):
     def compile(*args, **kwargs):
         raise cb.ideone.LanguageNotFoundError(error_msg, similar_langs)
     cb.compile = compile
     error_msg = "Language Error Message"
     similar_langs = ["FooBar", "BazzScript", "Z 1-X"]
     # When the compile function returns an LanguageNotFoundError,
     # compilebot should notify the user the possible languages they 
     # were looking for via message reply.
     body = "+/u/{user} Foo\n\n    print(\"Test\")\n\n".format(user=self.user)
     comment = self.Comment(body)
     reply = cb.create_reply(comment)
     self.assertIsInstance(reply, cb.MessageReply)
     self.assertTrue(all(lang in reply.text for lang in similar_langs))
Beispiel #6
0
 def test_create_reply(self):
     with patch('{}.cb.compile'.format(__name__)) as mock_compile:
         mock_compile.return_value = {
             'cmpinfo': "",
             'input': "",
             'langName': "Python",
             'output': "Test",
             'result': 15,
             'stderr': "",
             'link': ""
         }
         body = ("+/u/{user} python\n\n"
                 "    print(\"Test\")\n\n".format(user=self.user))
         comment = self.Comment(body)
         reply = cb.create_reply(comment)
     self.assertIn("Output:\n\n    Test\n", reply.text)
Beispiel #7
0
 def test_create_reply(self):
     with patch('{}.cb.compile'.format(__name__)) as mock_compile:
         mock_compile.return_value = {
             'cmpinfo': "",
             'input': "",
             'langName': "Python",
             'output': "Test",
             'result': 15,
             'stderr': "",
             'link': ""
         }
         body = ("+/u/{user} python\n\n"
         "    print(\"Test\")\n\n".format(user=self.user))
         comment = self.Comment(body)
         reply = cb.create_reply(comment)
     self.assertIn("Output:\n\n    Test\n", reply.text)
Beispiel #8
0
    def test_missing_language(self):
        def compile(*args, **kwargs):
            raise cb.ideone.LanguageNotFoundError(error_msg, similar_langs)

        cb.compile = compile
        error_msg = "Language Error Message"
        similar_langs = ["FooBar", "BazzScript", "Z 1-X"]
        # When the compile function returns an LanguageNotFoundError,
        # compilebot should notify the user the possible languages they
        # were looking for via message reply.
        body = "+/u/{user} Foo\n\n    print(\"Test\")\n\n".format(
            user=self.user)
        comment = self.Comment(body)
        reply = cb.create_reply(comment)
        self.assertIsInstance(reply, cb.MessageReply)
        self.assertTrue(all(lang in reply.text for lang in similar_langs))
Beispiel #9
0
    def test_missing_language(self):
        """When the compile function returns an LanguageNotFoundError,
        compilebot should notify the user the possible languages they
        were looking for via message reply.
        """
        error_msg = "language error message"
        similar_langs = ["FooBar", "BazzScript", "Z 1-X"]

        body = "+/u/{user} Foo\n\n    print(\"Test\")\n\n".format(user=self.user)
        comment = self.Comment(body)

        with patch('{}.cb.compile'.format(__name__)) as mock_compile:
            mock_compile.side_effect = cb.ideone.LanguageNotFoundError(error_msg, similar_langs)
            mock_compile.return_value = {}
            reply = cb.create_reply(comment)
        self.assertIsInstance(reply, cb.MessageReply)
        self.assertTrue(all(lang in reply.text for lang in similar_langs))
Beispiel #10
0
 def test_create_reply(self):
     def compile(*args, **kwargs):
         return {
             'cmpinfo': "",
             'input': "",
             'langName': "Python",
             'output': "Test",
             'result': 15,
             'stderr': "",
             'link': ""
         }
     cb.compile = compile
     body = ("+/u/{user} python\n\n"
             "    print(\"Test\")\n\n".format(user=self.user))
     comment = self.Comment(body)
     reply = cb.create_reply(comment)
     self.assertIn("Output:\n\n    Test\n", reply.text)
Beispiel #11
0
    def test_create_reply(self):
        def compile(*args, **kwargs):
            return {
                'cmpinfo': "",
                'input': "",
                'langName': "Python",
                'output': "Test",
                'result': 15,
                'stderr': "",
                'link': ""
            }

        cb.compile = compile
        body = ("+/u/{user} python\n\n"
                "    print(\"Test\")\n\n".format(user=self.user))
        comment = self.Comment(body)
        reply = cb.create_reply(comment)
        self.assertIn("Output:\n\n    Test\n", reply.text)
Beispiel #12
0
    def test_missing_language(self):
        """When the compile function returns an LanguageNotFoundError,
        compilebot should notify the user the possible languages they
        were looking for via message reply.
        """
        error_msg = "language error message"
        similar_langs = ["FooBar", "BazzScript", "Z 1-X"]

        body = "+/u/{user} Foo\n\n    print(\"Test\")\n\n".format(
            user=self.user)
        comment = self.Comment(body)

        with patch('{}.cb.compile'.format(__name__)) as mock_compile:
            mock_compile.side_effect = cb.ideone.LanguageNotFoundError(
                error_msg, similar_langs)
            mock_compile.return_value = {}
            reply = cb.create_reply(comment)
        self.assertIsInstance(reply, cb.MessageReply)
        self.assertTrue(all(lang in reply.text for lang in similar_langs))
Beispiel #13
0
 def test_bad_format(self):
     body = "+/u/{user} Formatted incorrectly".format(user=self.user)
     comment = self.Comment(body)
     reply = cb.create_reply(comment)
     self.assertIsInstance(reply, cb.MessageReply)
     self.assertIn(cb.FORMAT_ERROR_TEXT, reply.text)
Beispiel #14
0
 def test_bad_format(self):
     body = "+/u/{user} Formatted incorrectly".format(user=self.user)
     comment = self.Comment(body)
     reply = cb.create_reply(comment)
     self.assertIsInstance(reply, cb.MessageReply)
     self.assertIn(cb.FORMAT_ERROR_TEXT, reply.text)