本文整理汇总了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]