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


Python FormatChecker.check方法代碼示例

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


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

示例1: test_format_checkers_come_with_defaults

# 需要導入模塊: from jsonschema import FormatChecker [as 別名]
# 或者: from jsonschema.FormatChecker import check [as 別名]
 def test_format_checkers_come_with_defaults(self):
     # This is bad :/ but relied upon.
     # The docs for quite awhile recommended people do things like
     # validate(..., format_checker=FormatChecker())
     # We should change that, but we can't without deprecation...
     checker = FormatChecker()
     with self.assertRaises(FormatError):
         checker.check(instance="not-an-ipv4", format="ipv4")
開發者ID:Julian,項目名稱:jsonschema,代碼行數:10,代碼來源:test_format.py

示例2: test_it_catches_registered_errors

# 需要導入模塊: from jsonschema import FormatChecker [as 別名]
# 或者: from jsonschema.FormatChecker import check [as 別名]
    def test_it_catches_registered_errors(self):
        checker = FormatChecker()
        checker.checks("boom", raises=type(BOOM))(boom)

        with self.assertRaises(FormatError) as cm:
            checker.check(instance=12, format="boom")

        self.assertIs(cm.exception.cause, BOOM)
        self.assertIs(cm.exception.__cause__, BOOM)

        # Unregistered errors should not be caught
        with self.assertRaises(type(BANG)):
            checker.check(instance="bang", format="boom")
開發者ID:Julian,項目名稱:jsonschema,代碼行數:15,代碼來源:test_format.py

示例3: test_it_catches_registered_errors

# 需要導入模塊: from jsonschema import FormatChecker [as 別名]
# 或者: from jsonschema.FormatChecker import check [as 別名]
 def test_it_catches_registered_errors(self):
     checker = FormatChecker()
     checker.checks("foo", raises=ValueError)(self.fn)
     # Registered errors should be caught and turned into FormatErrors
     cause = ValueError()
     self.fn.side_effect = cause
     with self.assertRaises(FormatError) as cm:
         checker.check("bar", "foo")
     # Original exception should be attached to cause attribute
     self.assertIs(cm.exception.cause, cause)
     # Unregistered errors should not be caught
     self.fn.side_effect = AttributeError
     with self.assertRaises(AttributeError):
         checker.check("bar", "foo")
開發者ID:alexstrat,項目名稱:jsonschema,代碼行數:16,代碼來源:tests.py

示例4: test_it_catches_registered_errors

# 需要導入模塊: from jsonschema import FormatChecker [as 別名]
# 或者: from jsonschema.FormatChecker import check [as 別名]
    def test_it_catches_registered_errors(self):
        checker = FormatChecker()
        cause = self.fn.side_effect = ValueError()

        checker.checks("foo", raises=ValueError)(self.fn)

        with self.assertRaises(FormatError) as cm:
            checker.check("bar", "foo")

        self.assertIs(cm.exception.cause, cause)
        self.assertIs(cm.exception.__cause__, cause)

        # Unregistered errors should not be caught
        self.fn.side_effect = AttributeError
        with self.assertRaises(AttributeError):
            checker.check("bar", "foo")
開發者ID:BarnetteME1,項目名稱:DnD-stuff,代碼行數:18,代碼來源:test_format.py


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