Begrudgingly make 1 and True unique (and 0 and False).

Closes: #43
This commit is contained in:
Julian Berman
2012-10-31 20:39:51 -04:00
parent 3b3bd00fef
commit db4f74befe
2 changed files with 14 additions and 5 deletions

View File

@@ -657,6 +657,19 @@ def _delist(thing):
return 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): def _uniq(container):
""" """
Check if all of a container's elements are unique. Check if all of a container's elements are unique.
@@ -668,7 +681,7 @@ def _uniq(container):
""" """
try: try:
return len(set(container)) == len(container) return len(set(_unbool(i) for i in container)) == len(container)
except TypeError: except TypeError:
try: try:
sort = sorted(container) sort = sorted(container)

View File

@@ -55,10 +55,6 @@ def load_json_cases(test_dir):
test_class.validator_class, 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" % ( test_name = "test_%s_%s" % (
validating, validating,
re.sub(r"[\W ]+", "_", test["description"]), re.sub(r"[\W ]+", "_", test["description"]),