Address review comments.
This commit is contained in:
parent
822c75f653
commit
124b81a129
|
@ -30,13 +30,16 @@ def additionalProperties(validator, aP, instance, schema):
|
||||||
yield error
|
yield error
|
||||||
elif not aP and extras:
|
elif not aP and extras:
|
||||||
if "patternProperties" in schema:
|
if "patternProperties" in schema:
|
||||||
patterns = sorted(schema["patternProperties"].keys())
|
patterns = sorted(schema["patternProperties"])
|
||||||
if len(extras) == 1:
|
if len(extras) == 1:
|
||||||
verb = "does"
|
verb = "does"
|
||||||
else:
|
else:
|
||||||
verb = "do"
|
verb = "do"
|
||||||
error = "%s %s not match any of the regexs: %s" % (
|
error = "%s %s not match any of the regexes: %s" % (
|
||||||
", ".join(map(repr, sorted(extras))), verb, ", ".join(patterns))
|
", ".join(map(repr, sorted(extras))),
|
||||||
|
verb,
|
||||||
|
", ".join(map(repr, patterns)),
|
||||||
|
)
|
||||||
yield ValidationError(error)
|
yield ValidationError(error)
|
||||||
else:
|
else:
|
||||||
error = "Additional properties are not allowed (%s %s unexpected)"
|
error = "Additional properties are not allowed (%s %s unexpected)"
|
||||||
|
|
|
@ -195,21 +195,25 @@ class TestValidationErrorMessages(unittest.TestCase):
|
||||||
schema = {u"type": u"object",
|
schema = {u"type": u"object",
|
||||||
u"additionalProperties": False,
|
u"additionalProperties": False,
|
||||||
u"patternProperties": {
|
u"patternProperties": {
|
||||||
u"$abc^": {u"type": u"string"},
|
u"^abc$": {u"type": u"string"},
|
||||||
u"$def^": {u"type": u"string"}
|
u"^def$": {u"type": u"string"}
|
||||||
}}
|
}}
|
||||||
message = self.message_for({u"zebra": 123}, schema,
|
message = self.message_for({u"zebra": 123}, schema,
|
||||||
cls=Draft4Validator)
|
cls=Draft4Validator)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
message,
|
message,
|
||||||
"{} does not match any of the regexs: $abc^, $def^".format(
|
"{} does not match any of the regexes: {}, {}".format(
|
||||||
repr(u"zebra")))
|
repr(u"zebra"), repr(u"^abc$"), repr(u"^def$"),
|
||||||
|
),
|
||||||
|
)
|
||||||
message = self.message_for({u"zebra": 123, u"fish": 456}, schema,
|
message = self.message_for({u"zebra": 123, u"fish": 456}, schema,
|
||||||
cls=Draft4Validator)
|
cls=Draft4Validator)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
message,
|
message,
|
||||||
"{}, {} do not match any of the regexs: $abc^, $def^".format(
|
"{}, {} do not match any of the regexes: {}, {}".format(
|
||||||
repr(u"fish"), repr(u"zebra")))
|
repr(u"fish"), repr(u"zebra"), repr(u"^abc$"), repr(u"^def$")
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestValidationErrorDetails(unittest.TestCase):
|
class TestValidationErrorDetails(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue