From db4f74befebd90a03f830bf6fe576a91c70fef93 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 31 Oct 2012 20:39:51 -0400 Subject: [PATCH] Begrudgingly make 1 and True unique (and 0 and False). Closes: #43 --- jsonschema.py | 15 ++++++++++++++- tests.py | 4 ---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/jsonschema.py b/jsonschema.py index 8376511..896f979 100644 --- a/jsonschema.py +++ b/jsonschema.py @@ -657,6 +657,19 @@ def _delist(thing): return thing +def _unbool(element, true=object(), false=object()): + """ + A hack to make True and 1 and False and 0 unique for _uniq. + + """ + + if element is True: + return true + elif element is False: + return false + return element + + def _uniq(container): """ Check if all of a container's elements are unique. @@ -668,7 +681,7 @@ def _uniq(container): """ try: - return len(set(container)) == len(container) + return len(set(_unbool(i) for i in container)) == len(container) except TypeError: try: sort = sorted(container) diff --git a/tests.py b/tests.py index f0e17ee..e324915 100644 --- a/tests.py +++ b/tests.py @@ -55,10 +55,6 @@ def load_json_cases(test_dir): test_class.validator_class, ) - # XXX: Disable some tests due to issue #43 - if case["description"].startswith("uniqueItems bool"): - a_test = expectedFailure(a_test) - test_name = "test_%s_%s" % ( validating, re.sub(r"[\W ]+", "_", test["description"]),