Skip to content

Commit 1598940

Browse files
committed
Unskip and fix the const-related compare bug.
Refs: #575
1 parent 584c72a commit 1598940

File tree

3 files changed

+22
-50
lines changed

3 files changed

+22
-50
lines changed

jsonschema/_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,16 @@ def ensure_list(thing):
175175
return thing
176176

177177

178+
def equal(one, two):
179+
"""
180+
Check if two things are equal, but evade booleans and ints being equal.
181+
"""
182+
return unbool(one) == unbool(two)
183+
184+
178185
def unbool(element, true=object(), false=object()):
179186
"""
180187
A hack to make True and 1 and False and 0 unique for ``uniq``.
181-
182188
"""
183189

184190
if element is True:
@@ -195,7 +201,6 @@ def uniq(container):
195201
Successively tries first to rely that the elements are hashable, then
196202
falls back on them being sortable, and finally falls back on brute
197203
force.
198-
199204
"""
200205

201206
try:

jsonschema/_validators.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import re
22

3-
from jsonschema import _utils
3+
from jsonschema._utils import (
4+
ensure_list,
5+
equal,
6+
extras_msg,
7+
find_additional_properties,
8+
types_msg,
9+
uniq,
10+
)
411
from jsonschema.exceptions import FormatError, ValidationError
512
from jsonschema.compat import iteritems
613

@@ -34,7 +41,7 @@ def additionalProperties(validator, aP, instance, schema):
3441
if not validator.is_type(instance, "object"):
3542
return
3643

37-
extras = set(_utils.find_additional_properties(instance, schema))
44+
extras = set(find_additional_properties(instance, schema))
3845

3946
if validator.is_type(aP, "object"):
4047
for extra in extras:
@@ -55,7 +62,7 @@ def additionalProperties(validator, aP, instance, schema):
5562
yield ValidationError(error)
5663
else:
5764
error = "Additional properties are not allowed (%s %s unexpected)"
58-
yield ValidationError(error % _utils.extras_msg(extras))
65+
yield ValidationError(error % extras_msg(extras))
5966

6067

6168
def items(validator, items, instance, schema):
@@ -90,12 +97,12 @@ def additionalItems(validator, aI, instance, schema):
9097
error = "Additional items are not allowed (%s %s unexpected)"
9198
yield ValidationError(
9299
error %
93-
_utils.extras_msg(instance[len(schema.get("items", [])):])
100+
extras_msg(instance[len(schema.get("items", [])):])
94101
)
95102

96103

97104
def const(validator, const, instance, schema):
98-
if instance != const:
105+
if not equal(instance, const):
99106
yield ValidationError("%r was expected" % (const,))
100107

101108

@@ -181,7 +188,7 @@ def uniqueItems(validator, uI, instance, schema):
181188
if (
182189
uI and
183190
validator.is_type(instance, "array") and
184-
not _utils.uniq(instance)
191+
not uniq(instance)
185192
):
186193
yield ValidationError("%r has non-unique elements" % (instance,))
187194

@@ -255,10 +262,10 @@ def ref(validator, ref, instance, schema):
255262

256263

257264
def type(validator, types, instance, schema):
258-
types = _utils.ensure_list(types)
265+
types = ensure_list(types)
259266

260267
if not any(validator.is_type(instance, type) for type in types):
261-
yield ValidationError(_utils.types_msg(instance, types))
268+
yield ValidationError(types_msg(instance, types))
262269

263270

264271
def properties(validator, properties, instance, schema):

jsonschema/tests/test_jsonschema_test_suite.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -174,26 +174,6 @@ def bug(issue=None):
174174
skip=lambda test: (
175175
narrow_unicode_build(test)
176176
or missing_format(draft6_format_checker)(test)
177-
or skip(
178-
message=bug(575),
179-
subject="const",
180-
case_description="const with true does not match 1",
181-
)(test)
182-
or skip(
183-
message=bug(575),
184-
subject="const",
185-
case_description="const with false does not match 0",
186-
)(test)
187-
or skip(
188-
message=bug(575),
189-
subject="const",
190-
case_description="const with 1 does not match true",
191-
)(test)
192-
or skip(
193-
message=bug(575),
194-
subject="const",
195-
case_description="const with 0 does not match false",
196-
)(test)
197177
or skip(
198178
message=bug(575),
199179
subject="enum",
@@ -267,26 +247,6 @@ def bug(issue=None):
267247
skip=lambda test: (
268248
narrow_unicode_build(test)
269249
or missing_format(draft7_format_checker)(test)
270-
or skip(
271-
message=bug(575),
272-
subject="const",
273-
case_description="const with true does not match 1",
274-
)(test)
275-
or skip(
276-
message=bug(575),
277-
subject="const",
278-
case_description="const with false does not match 0",
279-
)(test)
280-
or skip(
281-
message=bug(575),
282-
subject="const",
283-
case_description="const with 1 does not match true",
284-
)(test)
285-
or skip(
286-
message=bug(575),
287-
subject="const",
288-
case_description="const with 0 does not match false",
289-
)(test)
290250
or skip(
291251
message=bug(575),
292252
subject="enum",

0 commit comments

Comments
 (0)