<commit_before>from UnitTest import UnitTest

class MyException:

    def toString(self):
        return "MyException"

class MyException2:

    def toString(self):
        return "MyException2"

class ExceptionTest(UnitTest):
    def __init__(self):
        UnitTest.__init__(self)

    def getName(self):
        return "Exception"

    def testExceptionOrdTrigger(self):
        try:
            x = ord(5) # shouldn't be a number
        except:
            self.assertTrue(True, "the exception should have happened")
            return
        self.assertTrue(False, "mustn't be able to do ord() on a number")

    def testExceptionOrdNoTrigger(self):
        try:
            x = ord("5")
        except:
            self.assertTrue(False, "the exception shouldn't have happened")
            return
        self.assertTrue(True, "the exception should have happened")


    def testRaiseException(self):
        try:
            raise MyException()
        except:
            return
        self.fail('MyException was not raised')

    def testCatchClassException(self):
        try:
            raise MyException()
        except MyException, e:
            self.assertEqual(e.toString(), 'MyException',
                             "Catched exception does not match")
            return
        self.fail('MyException was not catched or raised')

    def testCatchMultiClassException(self):
        try:
            raise MyException()
        except (MyException, MyException2), e:
            self.assertEqual(e.toString(), 'MyException',
                             "Catched exception does not match")
            return
        self.fail('MyException was not catched or raised')

    def testCatchStringException(self):
        try:
            raise "test"
        except "test":
            return
        self.fail('"test" was not catched or raised')
<commit_msg>test builtin exceptions<commit_after>from UnitTest import UnitTest

class MyException:

    def toString(self):
        return "MyException"

class MyException2:

    def toString(self):
        return "MyException2"

class ExceptionTest(UnitTest):
    def __init__(self):
        UnitTest.__init__(self)

    def getName(self):
        return "Exception"

    def testExceptionOrdTrigger(self):
        try:
            x = ord(5) # shouldn't be a number
        except:
            self.assertTrue(True, "the exception should have happened")
            return
        self.assertTrue(False, "mustn't be able to do ord() on a number")

    def testExceptionOrdNoTrigger(self):
        try:
            x = ord("5")
        except:
            self.assertTrue(False, "the exception shouldn't have happened")
            return
        self.assertTrue(True, "the exception should have happened")


    def testRaiseException(self):
        try:
            raise MyException()
        except:
            return
        self.fail('MyException was not raised')

    def testCatchClassException(self):
        try:
            raise MyException()
        except MyException, e:
            self.assertEqual(e.toString(), 'MyException',
                             "Catched exception does not match")
            return
        self.fail('MyException was not catched or raised')

    def testCatchMultiClassException(self):
        try:
            raise MyException()
        except (MyException, MyException2), e:
            self.assertEqual(e.toString(), 'MyException',
                             "Catched exception does not match")
            return
        self.fail('MyException was not catched or raised')

    def testCatchStringException(self):
        try:
            raise "test"
        except "test":
            return
        self.fail('"test" was not catched or raised')

    def testBuiltInException(self):
        try:
            raise LookupError('hoschi')
        except LookupError, e:
            self.assertEqual(e.name, 'LookupError')
            return
        self.fail("LookupError should be catched")
{'fraction_non_alphanumeric': 0.08424725822532403, 'fraction_numerical': 0.0024925224327018943, 'mean_word_length': 1.9572586588061902, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7128977', 'n_tokens_mistral': 1023, 'n_tokens_neox': 1007, 'n_words': 299}