Ejemplo n.º 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))
Ejemplo n.º 2
0
    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))
Ejemplo n.º 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)
Ejemplo n.º 4
0
    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)