summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Maynard <glenn@zewt.org>2012-05-31 16:52:38 +0000
committerGlenn Maynard <glenn@zewt.org>2012-05-31 16:52:38 +0000
commitcaf0d6334adea122a9e28180ecbab4a1affdcf77 (patch)
tree9a2259c6f9666755c61640553249e2045d649c68
parent09b36567dd1f0da38f7086a20286322cbf513142 (diff)
downloadjsonschema-caf0d6334adea122a9e28180ecbab4a1affdcf77.tar.gz
Fix divisibleBy when the item isn't a number.
The spec doesn't actually say this one--there's no "when the type is a number", but that seems like an oversight, since it doesn't otherwise specify what should happen and that's how all other number-based constraints work.
-rw-r--r--jsonschema.py3
-rw-r--r--tests.py1
2 files changed, 4 insertions, 0 deletions
diff --git a/jsonschema.py b/jsonschema.py
index c504986..d00835b 100644
--- a/jsonschema.py
+++ b/jsonschema.py
@@ -504,6 +504,9 @@ class Validator(object):
self.error("%r is not one of %r" % (instance, enums))
def validate_divisibleBy(self, dB, instance, schema):
+ if not self.is_type(instance, "number"):
+ return
+
if isinstance(dB, float):
mod = instance % dB
failed = (mod > EPSILON) and (dB - mod) > EPSILON
diff --git a/tests.py b/tests.py
index c451f5d..9e6133d 100644
--- a/tests.py
+++ b/tests.py
@@ -242,6 +242,7 @@ class TestValidate(ParameterizedTestCase, unittest.TestCase):
validate("x", {"type": ["string", "number"], "maximum": 10})
validate(1, {"type": ["integer", "object"], "properties": {"x": {}}})
validate(1, {"type": ["integer", "array"], "items": {"type": "string"}})
+ validate("x", {"type": ["integer", "string"], "divisibleBy": 10})
def test_additionalProperties_allowed_by_default(self):
schema = {