summaryrefslogtreecommitdiff
path: root/jsonschema/tests/test_validators.py
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-23 10:37:14 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-23 10:37:14 +0100
commitaca914c0508bca7bb862f060b503bb01a3b98d92 (patch)
treee3c536ab94709fce40e950e9d6a897e760fb30ff /jsonschema/tests/test_validators.py
parente38e5cfa97065cb5dbbcdf0e05ca2db3dbc06751 (diff)
downloadjsonschema-aca914c0508bca7bb862f060b503bb01a3b98d92.tar.gz
Fix the schema path used by prefixItems errors.
Also simplify its implementation, what it's doing is just zip.
Diffstat (limited to 'jsonschema/tests/test_validators.py')
-rw-r--r--jsonschema/tests/test_validators.py51
1 files changed, 50 insertions, 1 deletions
diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py
index 85f6b4f..2406cb1 100644
--- a/jsonschema/tests/test_validators.py
+++ b/jsonschema/tests/test_validators.py
@@ -418,7 +418,7 @@ class TestValidationErrorMessages(TestCase):
message = self.message_for(instance=[1, 2, 3], schema={"maxItems": 2})
self.assertEqual(message, "[1, 2, 3] is too long")
- def test_prefixItems(self):
+ def test_prefixItems_with_items(self):
message = self.message_for(
instance=[1, 2, "foo", 5],
schema={"items": False, "prefixItems": [{}, {}]},
@@ -1114,6 +1114,55 @@ class TestValidationErrorDetails(TestCase):
),
)
+ def test_prefixItems(self):
+ schema = {"prefixItems": [{"type": "string"}, {}, {}, {"maximum": 3}]}
+ validator = validators.Draft202012Validator(schema)
+ type_error, min_error = validator.iter_errors([1, 2, "foo", 5])
+ self.assertEqual(
+ (
+ type_error.message,
+ type_error.validator,
+ type_error.validator_value,
+ type_error.instance,
+ type_error.absolute_path,
+ type_error.schema,
+ type_error.schema_path,
+ type_error.json_path,
+ ),
+ (
+ "1 is not of type 'string'",
+ "type",
+ "string",
+ 1,
+ deque([]),
+ {"type": "string"},
+ deque(["prefixItems", 0, "type"]),
+ "$",
+ ),
+ )
+ self.assertEqual(
+ (
+ min_error.message,
+ min_error.validator,
+ min_error.validator_value,
+ min_error.instance,
+ min_error.absolute_path,
+ min_error.schema,
+ min_error.schema_path,
+ min_error.json_path,
+ ),
+ (
+ "5 is greater than the maximum of 3",
+ "maximum",
+ 3,
+ 5,
+ deque([]),
+ {"maximum": 3},
+ deque(["prefixItems", 3, "maximum"]),
+ "$",
+ ),
+ )
+
class MetaSchemaTestsMixin(object):
# TODO: These all belong upstream