本文整理匯總了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")
示例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")
示例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")
示例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")