Skip to content

Commit

Permalink
Teach unbool about deeply nested objects/arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangalamb committed Jun 13, 2020
1 parent 9ffc81e commit 463e087
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 80 deletions.
11 changes: 11 additions & 0 deletions jsonschema/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,23 @@ def equal(one, two):
def unbool(element, true=object(), false=object()):
"""
A hack to make True and 1 and False and 0 unique for ``uniq``.
Recurses through an arbitrarily deep object and unique-ifies True/1 and
False/0. Also converts arrays/objects into immutable/hashable alternatives.
We have to copy the items anyway to avoid unexpected mutations, so we might
as well make the imminent equality check simpler.
"""

if element is True:
return true
elif element is False:
return false
elif isinstance(element, list) or isinstance(element, tuple):
return tuple(map(unbool, element))
elif isinstance(element, dict):
# Convert dicts to frozensets of 2-tuples. For equality checks, that's
# a reasonable hashable alternative to dicts.
return frozenset(map(unbool, element.items()))
return element


Expand Down
80 changes: 0 additions & 80 deletions jsonschema/tests/test_jsonschema_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,6 @@ def narrow_unicode_build(test): # pragma: no cover
subject="host-name",
description="ends with hyphen",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="[0] and [false] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="[1] and [true] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="nested [0] and [false] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="nested [1] and [true] are unique",
)(test)
),
)

Expand Down Expand Up @@ -161,26 +141,6 @@ def narrow_unicode_build(test): # pragma: no cover
subject="hostname",
description="ends with hyphen",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="[0] and [false] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="[1] and [true] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="nested [0] and [false] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="nested [1] and [true] are unique",
)(test)
),
)

Expand Down Expand Up @@ -234,26 +194,6 @@ def narrow_unicode_build(test): # pragma: no cover
subject="hostname",
description="ends with hyphen",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="[0] and [false] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="[1] and [true] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="nested [0] and [false] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="nested [1] and [true] are unique",
)(test)
),
)

Expand Down Expand Up @@ -327,26 +267,6 @@ def narrow_unicode_build(test): # pragma: no cover
"validation of binary-encoded media type documents"
),
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="[0] and [false] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="[1] and [true] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="nested [0] and [false] are unique",
)(test)
or skip(
message=bug(686),
subject="uniqueItems",
description="nested [1] and [true] are unique",
)(test)
),
)

Expand Down

0 comments on commit 463e087

Please sign in to comment.