當前位置: 首頁>>代碼示例>>Python>>正文


Python _testcapi.raise_exception方法代碼示例

本文整理匯總了Python中_testcapi.raise_exception方法的典型用法代碼示例。如果您正苦於以下問題:Python _testcapi.raise_exception方法的具體用法?Python _testcapi.raise_exception怎麽用?Python _testcapi.raise_exception使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在_testcapi的用法示例。


在下文中一共展示了_testcapi.raise_exception方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testSettingException

# 需要導入模塊: import _testcapi [as 別名]
# 或者: from _testcapi import raise_exception [as 別名]
def testSettingException(self):
        # test that setting an exception at the C level works even if the
        # exception object can't be constructed.

        class BadException:
            def __init__(self_):
                raise RuntimeError, "can't instantiate BadException"

        def test_capi1():
            import _testcapi
            try:
                _testcapi.raise_exception(BadException, 1)
            except TypeError, err:
                exc, err, tb = sys.exc_info()
                co = tb.tb_frame.f_code
                self.assertEqual(co.co_name, "test_capi1")
                self.assertTrue(co.co_filename.endswith('test_exceptions'+os.extsep+'py'))
            else: 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_exceptions.py

示例2: testSettingException

# 需要導入模塊: import _testcapi [as 別名]
# 或者: from _testcapi import raise_exception [as 別名]
def testSettingException(self):
        # test that setting an exception at the C level works even if the
        # exception object can't be constructed.

        class BadException:
            def __init__(self_):
                raise RuntimeError, "can't instantiate BadException"

        def test_capi1():
            import _testcapi
            try:
                _testcapi.raise_exception(BadException, 1)
            except TypeError, err:
                exc, err, tb = sys.exc_info()
                co = tb.tb_frame.f_code
                self.assertEquals(co.co_name, "test_capi1")
                self.assert_(co.co_filename.endswith('test_exceptions'+os.extsep+'py'))
            else: 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:20,代碼來源:test_exceptions.py

示例3: test_capi2

# 需要導入模塊: import _testcapi [as 別名]
# 或者: from _testcapi import raise_exception [as 別名]
def test_capi2():
            import _testcapi
            try:
                _testcapi.raise_exception(BadException, 0)
            except RuntimeError, err:
                exc, err, tb = sys.exc_info()
                co = tb.tb_frame.f_code
                self.assertEqual(co.co_name, "__init__")
                self.assertTrue(co.co_filename.endswith('test_exceptions'+os.extsep+'py'))
                co2 = tb.tb_frame.f_back.f_code
                self.assertEqual(co2.co_name, "test_capi2") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_exceptions.py

示例4: test_capi2

# 需要導入模塊: import _testcapi [as 別名]
# 或者: from _testcapi import raise_exception [as 別名]
def test_capi2():
            import _testcapi
            try:
                _testcapi.raise_exception(BadException, 0)
            except RuntimeError, err:
                exc, err, tb = sys.exc_info()
                co = tb.tb_frame.f_code
                self.assertEquals(co.co_name, "__init__")
                self.assert_(co.co_filename.endswith('test_exceptions'+os.extsep+'py'))
                co2 = tb.tb_frame.f_back.f_code
                self.assertEquals(co2.co_name, "test_capi2") 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:13,代碼來源:test_exceptions.py

示例5: testSettingException

# 需要導入模塊: import _testcapi [as 別名]
# 或者: from _testcapi import raise_exception [as 別名]
def testSettingException(self):
        # test that setting an exception at the C level works even if the
        # exception object can't be constructed.

        class BadException(Exception):
            def __init__(self_):
                raise RuntimeError("can't instantiate BadException")

        class InvalidException:
            pass

        def test_capi1():
            import _testcapi
            try:
                _testcapi.raise_exception(BadException, 1)
            except TypeError as err:
                exc, err, tb = sys.exc_info()
                co = tb.tb_frame.f_code
                self.assertEqual(co.co_name, "test_capi1")
                self.assertTrue(co.co_filename.endswith('test_exceptions.py'))
            else:
                self.fail("Expected exception")

        def test_capi2():
            import _testcapi
            try:
                _testcapi.raise_exception(BadException, 0)
            except RuntimeError as err:
                exc, err, tb = sys.exc_info()
                co = tb.tb_frame.f_code
                self.assertEqual(co.co_name, "__init__")
                self.assertTrue(co.co_filename.endswith('test_exceptions.py'))
                co2 = tb.tb_frame.f_back.f_code
                self.assertEqual(co2.co_name, "test_capi2")
            else:
                self.fail("Expected exception")

        def test_capi3():
            import _testcapi
            self.assertRaises(SystemError, _testcapi.raise_exception,
                              InvalidException, 1)

        if not sys.platform.startswith('java'):
            test_capi1()
            test_capi2()
            test_capi3() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:48,代碼來源:test_exceptions.py


注:本文中的_testcapi.raise_exception方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。