summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2015-09-17 07:56:34 -0400
committerJulian Berman <Julian@GrayVines.com>2015-09-17 07:56:34 -0400
commit94c60a45a52a89318c2149ca45267acee7688258 (patch)
treeeaa1bec023671e2675d94b0df61e6083b2ba02a6
parent96c5f476a1cb5152e61eef8d4771260328d1345b (diff)
parent7c4eefb881e8d366b21cffb492173f57f8e3ee22 (diff)
downloadjsonschema-94c60a45a52a89318c2149ca45267acee7688258.tar.gz
Merge remote-tracking branch 'playpauseandstop/master'
* playpauseandstop/master: Provide test cases to previous fix to ensure proper error handling items errors. Fix formatting error for unique items if instance is tuple.
-rw-r--r--jsonschema/_validators.py2
-rw-r--r--jsonschema/tests/test_validators.py60
2 files changed, 61 insertions, 1 deletions
diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py
index f566f6d..40fe340 100644
--- a/jsonschema/_validators.py
+++ b/jsonschema/_validators.py
@@ -133,7 +133,7 @@ def uniqueItems(validator, uI, instance, schema):
validator.is_type(instance, "array") and
not _utils.uniq(instance)
):
- yield ValidationError("%r has non-unique elements" % instance)
+ yield ValidationError("%r has non-unique elements" % (instance,))
def pattern(validator, patrn, instance, schema):
diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py
index e34efca..4e3fe61 100644
--- a/jsonschema/tests/test_validators.py
+++ b/jsonschema/tests/test_validators.py
@@ -899,6 +899,66 @@ class TestRefResolver(unittest.TestCase):
self.assertIn("Failed to pop the scope", str(exc.exception))
+OVERRIDE_ARRAY_TYPES = Draft4Validator.DEFAULT_TYPES.copy()
+OVERRIDE_ARRAY_TYPES['array'] = (list, tuple)
+
+
+class ItemsErrorsMixin(object):
+
+ array_type = list
+ schema = {
+ 'type': 'array',
+ 'items': {
+ 'type': 'number',
+ },
+ 'minItems': 2,
+ 'maxItems': 3,
+ 'uniqueItems': True,
+ }
+ validator_class = None
+
+ def check_error_message(self, instance):
+ self.assertIsNotNone(self.validator_class)
+ self.assertRaises(ValidationError,
+ validate,
+ instance,
+ self.schema,
+ self.validator_class)
+
+ def test_min_items(self):
+ self.check_error_message(self.array_type([1]))
+
+ def test_max_items(self):
+ self.check_error_message(self.array_type([1, 2, 3, 4]))
+
+ def test_unique_items(self):
+ self.check_error_message(self.array_type([1, 1, 2]))
+
+ def test_valid(self):
+ self.assertIsNotNone(self.validator_class)
+ validate(self.array_type([1, 2]), self.schema, self.validator_class)
+
+
+class OverrideArrayTypeValidator(Draft4Validator):
+
+ DEFAULT_TYPES = OVERRIDE_ARRAY_TYPES
+
+
+class TestItemsErrorsDraft3(ItemsErrorsMixin, unittest.TestCase):
+
+ validator_class = Draft3Validator
+
+
+class TestItemsErrorsDraft4(ItemsErrorsMixin, unittest.TestCase):
+
+ validator_class = Draft4Validator
+
+
+class TestItemsErrorMessagesCustom(ItemsErrorsMixin, unittest.TestCase):
+
+ validator_class = OverrideArrayTypeValidator
+
+
def sorted_errors(errors):
def key(error):
return (