本文整理汇总了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")
示例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")
示例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")
示例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")
示例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")
示例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")
示例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")
示例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")
示例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")
示例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)