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


Python exceptions.SchemaError方法代码示例

本文整理汇总了Python中jsonschema.exceptions.SchemaError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.SchemaError方法的具体用法?Python exceptions.SchemaError怎么用?Python exceptions.SchemaError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsonschema.exceptions的用法示例。


在下文中一共展示了exceptions.SchemaError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_draft3_schema_draft4_validator

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import SchemaError [as 别名]
def test_draft3_schema_draft4_validator(self):
        stdout, stderr = StringIO(), StringIO()
        with self.assertRaises(SchemaError):
            cli.run(
                {
                    "validator": Draft4Validator,
                    "schema": {
                        "anyOf": [
                            {"minimum": 20},
                            {"type": "string"},
                            {"required": True},
                        ],
                    },
                    "instances": [1],
                    "error_format": "{error.message}",
                },
                stdout=stdout,
                stderr=stderr,
            ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:test_cli.py

示例2: validate_json

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import SchemaError [as 别名]
def validate_json(self, data):
        try:
            validator = jsonschema.Draft4Validator(self.schema)
            validation_errors = [e for e in validator.iter_errors(data)]

            # Iteratre over all errors and raise as single exception
            if validation_errors:
                exception_msgs = {}
                for err in validation_errors:
                    if err.path:
                        field = '-'.join([str(e) for e in err.path])
                    elif err.schema_path:
                        field = '-'.join([str(e) for e in err.schema_path])
                    else:
                        field = 'error'

                    if field in exception_msgs:
                        exception_msgs[field].append(err.message)
                    else:          
                        exception_msgs[field] = [err.message]  
                raise serializers.ValidationError(exception_msgs)

        except (JSONSchemaValidationError, JSONSchemaError) as e:
            raise serializers.ValidationError(e.message)
        return self.to_internal_value(json.dumps(data)) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:27,代码来源:serializers.py

示例3: _assert_schema

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import SchemaError [as 别名]
def _assert_schema(self, schema, reality):
        try:
            validate(reality, schema, format_checker=FormatChecker())
        except SchemaError as e:
            raise RuntimeError(e)
        except ValidationError as e:
            raise AssertionError(e) 
开发者ID:asyrjasalo,项目名称:RESTinstance,代码行数:9,代码来源:keywords.py

示例4: test_raises_if_schema_is_invalid

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import SchemaError [as 别名]
def test_raises_if_schema_is_invalid(self):
        with self.assertRaises(jse.SchemaError):
            self.schema = """
            {
                "not": "valid schema",
                "but": "Valid json"
            }
            """
            self.given_json({
                'id': 1
            }).validate()


    # response_json_matches_defined_schema() 
开发者ID:behave-restful,项目名称:behave-restful,代码行数:16,代码来源:test_response_validator.py

示例5: test_invalid_schema

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import SchemaError [as 别名]
def test_invalid_schema(self):
        with pytest.raises(SchemaError):

            class TestItem1(JsonSchemaItem):
                jsonschema = invalid_schema 
开发者ID:scrapy-plugins,项目名称:scrapy-jsonschema,代码行数:7,代码来源:test_item.py

示例6: test_invalid_schema

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import SchemaError [as 别名]
def test_invalid_schema(self):
        try:

            class TestItem1(JsonSchemaItem):
                jsonschema = invalid_schema

        except SchemaError:
            pass
        else:
            self.fail('SchemaError was not raised') 
开发者ID:scrapy-plugins,项目名称:scrapy-jsonschema,代码行数:12,代码来源:test_item_schema.py

示例7: validation_errors

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import SchemaError [as 别名]
def validation_errors(schema):
    """
    Given a dict, returns any known JSON Schema validation errors. If there are none,
    implies that the dict is a valid JSON Schema.
    :param schema: dict
    :return: [String, ...]
    """

    errors = []

    if not isinstance(schema, dict):
        errors.append('Parameter `schema` is not a dict, instead found: {}'.format(type(schema)))

    try:
        if not _valid_schema_version(schema):
            errors.append('Schema version must be Draft 4. Found: {}'.format('$schema'))
    except Exception as ex:
        errors = _unexpected_validation_error(errors, ex)

    try:
        Draft4Validator.check_schema(schema)
    except SchemaError as error:
        errors.append(str(error))
    except Exception as ex:
        errors = _unexpected_validation_error(errors, ex)

    try:
        simplify(schema)
    except JSONSchemaError as error:
        errors.append(str(error))
    except Exception as ex:
        errors = _unexpected_validation_error(errors, ex)

    return errors 
开发者ID:datamill-co,项目名称:target-postgres,代码行数:36,代码来源:json_schema.py

示例8: validate_json

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import SchemaError [as 别名]
def validate_json(json_string, schema):
    """
    invokes the validate function of jsonschema
    """
    schema_dict = json.loads(schema)
    schema_title = schema_dict['title']
    try:
        validate(json_string, schema_dict)
    except ValidationError as err:
        title = 'JSON validation failed: {}'.format(err.message)
        description = 'Failed validator: {} : {}'.format(
            err.validator,
            err.validator_value
        )
        LOG.error(title)
        LOG.error(description)
        raise InvalidFormatError(
            title=title,
            description=description,
        )
    except SchemaError as err:
        title = 'SchemaError: Unable to validate JSON: {}'.format(err)
        description = 'Invalid Schema: {}'.format(schema_title)
        LOG.error(title)
        LOG.error(description)
        raise AppError(
            title=title,
            description=description
        )
    except FormatError as err:
        title = 'FormatError: Unable to validate JSON: {}'.format(err)
        description = 'Invalid Format: {}'.format(schema_title)
        LOG.error(title)
        LOG.error(description)
        raise AppError(
            title=title,
            description=description
        )


# The action resource structure 
开发者ID:airshipit,项目名称:shipyard,代码行数:43,代码来源:json_schemas.py


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