Exemple #1
0
    def testUnifiedExceptionSemantics(self):
        """Test unified exception semantics."""
        from System import Exception, Object
        import exceptions

        e = Exception('Something bad happened')
        self.failUnless(isinstance(e, exceptions.Exception))
        self.failUnless(isinstance(e, Exception))
    def testUnifiedExceptionSemantics(self):
        """Test unified exception semantics."""
        from System import Exception, Object

        e = Exception('Something bad happened')
        if not six.PY3:
            import exceptions
            self.assertTrue(isinstance(e, exceptions.Exception))
        self.assertTrue(isinstance(e, Exception))
Exemple #3
0
    def testPicklingExceptions(self):
        from System import Exception
        try:
            import cPickle as pickle
        except ImportError:
            import pickle

        exc = Exception("test")
        dumped = pickle.dumps(exc)
        loaded = pickle.loads(dumped)

        self.assertEqual(exc.args, loaded.args)
    def testManagedExceptionConversion(self):
        """Test conversion of managed exceptions."""
        from System import Exception, OverflowException
        from Python.Test import ExceptionTest

        e = ExceptionTest.GetBaseException()
        self.assertTrue(isinstance(e, Exception))

        e = ExceptionTest.GetExplicitException()
        self.assertTrue(isinstance(e, OverflowException))
        self.assertTrue(isinstance(e, Exception))

        e = ExceptionTest.GetWidenedException()
        self.assertTrue(isinstance(e, OverflowException))
        self.assertTrue(isinstance(e, Exception))

        v = ExceptionTest.SetBaseException(Exception('error'))
        self.assertTrue(v)

        v = ExceptionTest.SetExplicitException(OverflowException('error'))
        self.assertTrue(v)

        v = ExceptionTest.SetWidenedException(OverflowException('error'))
        self.assertTrue(v)