本文整理匯總了Python中jsonschema.validators.Draft4Validator方法的典型用法代碼示例。如果您正苦於以下問題:Python validators.Draft4Validator方法的具體用法?Python validators.Draft4Validator怎麽用?Python validators.Draft4Validator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jsonschema.validators
的用法示例。
在下文中一共展示了validators.Draft4Validator方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_format_error_causes_become_validation_error_causes
# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import Draft4Validator [as 別名]
def test_format_error_causes_become_validation_error_causes(self):
checker = FormatChecker()
checker.checks("foo", raises=ValueError)(self.fn)
cause = self.fn.side_effect = ValueError()
validator = Draft4Validator({"format": "foo"}, format_checker=checker)
with self.assertRaises(ValidationError) as cm:
validator.validate("bar")
self.assertIs(cm.exception.__cause__, cause)
示例2: test_format_error_causes_become_validation_error_causes
# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import Draft4Validator [as 別名]
def test_format_error_causes_become_validation_error_causes(self):
checker = FormatChecker()
checker.checks("foo", raises=ValueError)(self.fn)
cause = self.fn.side_effect = ValueError()
validator = Draft4Validator({"format" : "foo"}, format_checker=checker)
with self.assertRaises(ValidationError) as cm:
validator.validate("bar")
self.assertIs(cm.exception.__cause__, cause)
示例3: factory
# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import Draft4Validator [as 別名]
def factory(cls, *args, **kwargs):
factory = extend(Draft4Validator, dict(required=cls._required))
return factory(*args, format_checker=cls.format_checker, **kwargs)
示例4: test_valid
# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import Draft4Validator [as 別名]
def test_valid(filename, schema):
errors = 0
with open(filename) as f:
data = json.load(f)
for error in validator(schema, format_checker=FormatChecker()).iter_errors(data):
errors += 1
warnings.warn(json.dumps(error.instance, indent=2, separators=(',', ': ')))
warnings.warn('{} ({})\n'.format(error.message, '/'.join(error.absolute_schema_path)))
assert errors == 0, '{} is invalid. See warnings below.'.format(filename)
示例5: test_compute_schema
# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import Draft4Validator [as 別名]
def test_compute_schema(self):
test_scope = fake_scopes.compute_scope
validators.Draft4Validator(
audit_template.AuditTemplatePostType._build_schema()
).validate(test_scope)
示例6: from_resolver
# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import Draft4Validator [as 別名]
def from_resolver(cls, spec_resolver):
"""Creates a customized Draft4ExtendedValidator.
:param spec_resolver: resolver for the spec
:type resolver: :class:`jsonschema.RefResolver`
"""
spec_validators = cls._get_spec_validators(spec_resolver)
return validators.extend(Draft4Validator, spec_validators)
示例7: __init__
# 需要導入模塊: from jsonschema import validators [as 別名]
# 或者: from jsonschema.validators import Draft4Validator [as 別名]
def __init__(self, schema, strategies=(), objclass_def='dict', objclass_menu=None,
validatorclass=Draft4Validator):
"""Create a new Merger object.
schema -- JSON schema to use when merging.
strategies -- Any additional merge strategies to use during merge.
objclass_def -- Name of the default class for JSON objects.
objclass_menu -- Any additional classes for JSON objects.
validatorclass -- JSON Schema validator class.
strategies argument should be a dict mapping strategy names to
instances of Strategy subclasses.
objclass_def specifies the default class used for JSON objects when one
is not specified in the schema. It should be 'dict' (dict built-in),
'OrderedDict' (collections.OrderedDict) or one of the names specified
in the objclass_menu argument. If not specified, 'dict' is used.
objclass_menu argument should be a dictionary that maps a string name
to a function or class that will return an empty dictionary-like object
to use as a JSON object. The function must accept either no arguments
or a dictionary-like object.
validatorclass argument can be used to supply a validator class from
jsonschema. This can be used for example to specify which JSON Schema
draft version will be used during merge.
"""
self.schema = schema
if hasattr(validatorclass, 'ID_OF'):
resolver = LocalRefResolver.from_schema(schema, id_of=validatorclass.ID_OF)
else:
# jsonschema<3.0.0
resolver = LocalRefResolver.from_schema(schema)
self.validator = validatorclass(schema, resolver=resolver)
self.strategies = dict(self.STRATEGIES)
self.strategies.update(strategies)
self.objclass_menu = { 'dict': dict, 'OrderedDict': OrderedDict }
if objclass_menu:
self.objclass_menu.update(objclass_menu)
self.objclass_menu['_default'] = self.objclass_menu[objclass_def]