Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastjsonschema/draft04.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def generate_unique_items(self):
'for k, v in var.items()).items()) '
'if hasattr(var, "items") else tuple(fn(v) '
'for v in var) '
'if isinstance(var, (dict, list)) else str(var) '
'if isinstance(var, (dict, list)) else (bool, var) '
'if isinstance(var, bool) else var')
self.create_variable_with_length()
with self.l('if {variable}_len > len(set(fn({variable}_x) for {variable}_x in {variable})):'):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ def test_unique_items(asserter, value, expected):
}, value, expected)


@pytest.mark.parametrize('draft', ['04', '06', '07'])
@pytest.mark.parametrize('value', [
[True, 'True'],
[False, 'False'],
[[True], ['True']],
[[False], ['False']],
[{'a': True}, {'a': 'True'}],
[{'a': False}, {'a': 'False'}],
[True, 1],
[False, 0],
])
def test_unique_items_distinguishes_booleans(asserter, draft, value):
asserter({
'$schema': 'http://json-schema.org/draft-{}/schema'.format(draft),
'type': 'array',
'uniqueItems': True,
}, value, value)


def test_not_unique_items(asserter):
value = [{'id': 1}, {'id': 1}]
asserter({
Expand Down