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


Python exceptions.best_match方法代码示例

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


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

示例1: test_oneOf_and_anyOf_are_weak_matches

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties": 2,
                "anyOf": [{"type": "string"}, {"type": "number"}],
                "oneOf": [{"type": "string"}, {"type": "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:18,代码来源:test_exceptions.py

示例2: test_if_the_most_relevant_error_is_anyOf_it_is_traversed

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "anyOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:27,代码来源:test_exceptions.py

示例3: test_if_the_most_relevant_error_is_oneOf_it_is_traversed

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "oneOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:27,代码来源:test_exceptions.py

示例4: test_nested_context_for_oneOf

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "oneOf": [
                            {"type": "string"},
                            {
                                "oneOf": [
                                    {"type": "string"},
                                    {
                                        "properties": {
                                            "bar": {"type": "array"},
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:26,代码来源:test_exceptions.py

示例5: test_if_the_most_relevant_error_is_allOf_it_is_traversed

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def test_if_the_most_relevant_error_is_allOf_it_is_traversed(self):
        """
        Now, if the error is allOf, we traverse but select the *most* relevant
        error from the context, because all schemas here must match anyways.

        """

        validator = Draft4Validator(
            {
                "properties": {
                    "foo": {
                        "allOf": [
                            {"type": "string"},
                            {"properties": {"bar": {"type": "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo": {"bar": 12}}))
        self.assertEqual(best.validator_value, "string") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:23,代码来源:test_exceptions.py

示例6: test_oneOf_and_anyOf_are_weak_matches

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def test_oneOf_and_anyOf_are_weak_matches(self):
        """
        A property you *must* match is probably better than one you have to
        match a part of.

        """

        validator = Draft4Validator(
            {
                "minProperties" : 2,
                "anyOf" : [{"type" : "string"}, {"type" : "number"}],
                "oneOf" : [{"type" : "string"}, {"type" : "number"}],
            }
        )
        best = self.best_match(validator.iter_errors({}))
        self.assertEqual(best.validator, "minProperties") 
开发者ID:getavalon,项目名称:core,代码行数:18,代码来源:test_exceptions.py

示例7: test_if_the_most_relevant_error_is_anyOf_it_is_traversed

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def test_if_the_most_relevant_error_is_anyOf_it_is_traversed(self):
        """
        If the most relevant error is an anyOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "anyOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:getavalon,项目名称:core,代码行数:27,代码来源:test_exceptions.py

示例8: test_if_the_most_relevant_error_is_oneOf_it_is_traversed

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def test_if_the_most_relevant_error_is_oneOf_it_is_traversed(self):
        """
        If the most relevant error is an oneOf, then we traverse its context
        and select the otherwise *least* relevant error, since in this case
        that means the most specific, deep, error inside the instance.

        I.e. since only one of the schemas must match, we look for the most
        relevant one.

        """

        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {"properties" : {"bar" : {"type" : "array"}}},
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:getavalon,项目名称:core,代码行数:27,代码来源:test_exceptions.py

示例9: test_nested_context_for_oneOf

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def test_nested_context_for_oneOf(self):
        validator = Draft4Validator(
            {
                "properties" : {
                    "foo" : {
                        "oneOf" : [
                            {"type" : "string"},
                            {
                                "oneOf" : [
                                    {"type" : "string"},
                                    {
                                        "properties" : {
                                            "bar" : {"type" : "array"}
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                },
            },
        )
        best = self.best_match(validator.iter_errors({"foo" : {"bar" : 12}}))
        self.assertEqual(best.validator_value, "array") 
开发者ID:getavalon,项目名称:core,代码行数:26,代码来源:test_exceptions.py

示例10: _validate_data

# 需要导入模块: from jsonschema import exceptions [as 别名]
# 或者: from jsonschema.exceptions import best_match [as 别名]
def _validate_data(self, data: dict):
        """
        Validates data against provider schema. Raises :class:`~notifiers.exceptions.BadArguments` if relevant

        :param data: Data to validate
        :raises: :class:`~notifiers.exceptions.BadArguments`
        """
        log.debug("validating provided data")
        e = best_match(self.validator.iter_errors(data))
        if e:
            custom_error_key = f"error_{e.validator}"
            msg = (
                e.schema[custom_error_key]
                if e.schema.get(custom_error_key)
                else e.message
            )
            raise BadArguments(validation_error=msg, provider=self.name, data=data) 
开发者ID:liiight,项目名称:notifiers,代码行数:19,代码来源:core.py


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