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')


@@ -1895,28 +1895,277 @@
  not catched or raised')%0D%0A%0D%0A
+    def testBuiltInException(self):%0D%0A        try:%0D%0A            raise LookupError('hoschi')%0D%0A        except LookupError, e:%0D%0A            self.assertEqual(e.name, 'LookupError')%0D%0A            return%0D%0A        self.fail(%22LookupError should be catched%22)%0D%0A

test builtin exceptions