summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2013-10-28 08:06:12 -0400
committerJulian Berman <Julian@GrayVines.com>2013-10-28 08:06:12 -0400
commita73d1efe56c922661afc6c451e1ce0284ba23260 (patch)
treed3c06001f49bca4c6e65f5b5073de7140d7b0e11
parent11dd8a53a856aba6df76ec8fd2c5cee2e5007236 (diff)
downloadjsonschema-a73d1efe56c922661afc6c451e1ce0284ba23260.tar.gz
Format can apply to instances of any type.
Closes #125
-rw-r--r--jsonschema/_validators.py5
-rw-r--r--jsonschema/tests/test_jsonschema_test_suite.py18
2 files changed, 19 insertions, 4 deletions
diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py
index c8cf05c..a37d6a9 100644
--- a/jsonschema/_validators.py
+++ b/jsonschema/_validators.py
@@ -150,10 +150,7 @@ def pattern(validator, patrn, instance, schema):
def format(validator, format, instance, schema):
- if (
- validator.format_checker is not None and
- validator.is_type(instance, "string")
- ):
+ if validator.format_checker is not None:
try:
validator.format_checker.check(instance, format)
except FormatError as error:
diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py
index 54deb09..146bf3e 100644
--- a/jsonschema/tests/test_jsonschema_test_suite.py
+++ b/jsonschema/tests/test_jsonschema_test_suite.py
@@ -180,6 +180,24 @@ class FormatMixin(object):
# Make sure original cause is attached
self.assertIs(cm.exception.cause, cause)
+ def test_it_validates_formats_of_any_type(self):
+ checker = mock.Mock(spec=FormatChecker)
+ validator = self.validator_class(
+ {"format" : "foo"}, format_checker=checker,
+ )
+
+ validator.validate([1, 2, 3])
+
+ checker.check.assert_called_once_with([1, 2, 3], "foo")
+
+ cause = ValueError()
+ checker.check.side_effect = FormatError('aoeu', cause=cause)
+
+ with self.assertRaises(ValidationError) as cm:
+ validator.validate([1, 2, 3])
+ # Make sure original cause is attached
+ self.assertIs(cm.exception.cause, cause)
+
@load_json_cases("draft3/*.json", ignore_glob="draft3/refRemote.json")
@load_json_cases(