当前位置: 首页>>代码示例>>Python>>正文


Python validators.Draft4Validator方法代码示例

本文整理汇总了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) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:12,代码来源:test_format.py

示例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) 
开发者ID:getavalon,项目名称:core,代码行数:12,代码来源:test_format.py

示例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) 
开发者ID:aamalev,项目名称:aiohttp_apiset,代码行数:5,代码来源:validate.py

示例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) 
开发者ID:open-contracting,项目名称:sample-data,代码行数:14,代码来源:test_fictional_example.py

示例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) 
开发者ID:openstack,项目名称:watcher,代码行数:7,代码来源:test_compute.py

示例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) 
开发者ID:p1c2u,项目名称:openapi-spec-validator,代码行数:10,代码来源:factories.py

示例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] 
开发者ID:avian2,项目名称:jsonmerge,代码行数:47,代码来源:__init__.py


注:本文中的jsonschema.validators.Draft4Validator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。