From a73d1efe56c922661afc6c451e1ce0284ba23260 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 28 Oct 2013 08:06:12 -0400 Subject: Format can apply to instances of any type. Closes #125 --- jsonschema/_validators.py | 5 +---- jsonschema/tests/test_jsonschema_test_suite.py | 18 ++++++++++++++++++ 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( -- cgit v1.2.1