Skip to content

Commit

Permalink
Unskip and fix the const-related compare bug.
Browse files Browse the repository at this point in the history
Refs: #575
  • Loading branch information
Julian committed Aug 1, 2019
1 parent 584c72a commit 1598940
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 50 deletions.
9 changes: 7 additions & 2 deletions jsonschema/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,16 @@ def ensure_list(thing):
return thing


def equal(one, two):
"""
Check if two things are equal, but evade booleans and ints being equal.
"""
return unbool(one) == unbool(two)


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:
Expand All @@ -195,7 +201,6 @@ def uniq(container):
Successively tries first to rely that the elements are hashable, then
falls back on them being sortable, and finally falls back on brute
force.
"""

try:
Expand Down
23 changes: 15 additions & 8 deletions jsonschema/_validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import re

from jsonschema import _utils
from jsonschema._utils import (
ensure_list,
equal,
extras_msg,
find_additional_properties,
types_msg,
uniq,
)
from jsonschema.exceptions import FormatError, ValidationError
from jsonschema.compat import iteritems

Expand Down Expand Up @@ -34,7 +41,7 @@ def additionalProperties(validator, aP, instance, schema):
if not validator.is_type(instance, "object"):
return

extras = set(_utils.find_additional_properties(instance, schema))
extras = set(find_additional_properties(instance, schema))

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


def items(validator, items, instance, schema):
Expand Down Expand Up @@ -90,12 +97,12 @@ def additionalItems(validator, aI, instance, schema):
error = "Additional items are not allowed (%s %s unexpected)"
yield ValidationError(
error %
_utils.extras_msg(instance[len(schema.get("items", [])):])
extras_msg(instance[len(schema.get("items", [])):])
)


def const(validator, const, instance, schema):
if instance != const:
if not equal(instance, const):
yield ValidationError("%r was expected" % (const,))


Expand Down Expand Up @@ -181,7 +188,7 @@ def uniqueItems(validator, uI, instance, schema):
if (
uI and
validator.is_type(instance, "array") and
not _utils.uniq(instance)
not uniq(instance)
):
yield ValidationError("%r has non-unique elements" % (instance,))

Expand Down Expand Up @@ -255,10 +262,10 @@ def ref(validator, ref, instance, schema):


def type(validator, types, instance, schema):
types = _utils.ensure_list(types)
types = ensure_list(types)

if not any(validator.is_type(instance, type) for type in types):
yield ValidationError(_utils.types_msg(instance, types))
yield ValidationError(types_msg(instance, types))


def properties(validator, properties, instance, schema):
Expand Down
40 changes: 0 additions & 40 deletions jsonschema/tests/test_jsonschema_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,6 @@ def bug(issue=None):
skip=lambda test: (
narrow_unicode_build(test)
or missing_format(draft6_format_checker)(test)
or skip(
message=bug(575),
subject="const",
case_description="const with true does not match 1",
)(test)
or skip(
message=bug(575),
subject="const",
case_description="const with false does not match 0",
)(test)
or skip(
message=bug(575),
subject="const",
case_description="const with 1 does not match true",
)(test)
or skip(
message=bug(575),
subject="const",
case_description="const with 0 does not match false",
)(test)
or skip(
message=bug(575),
subject="enum",
Expand Down Expand Up @@ -267,26 +247,6 @@ def bug(issue=None):
skip=lambda test: (
narrow_unicode_build(test)
or missing_format(draft7_format_checker)(test)
or skip(
message=bug(575),
subject="const",
case_description="const with true does not match 1",
)(test)
or skip(
message=bug(575),
subject="const",
case_description="const with false does not match 0",
)(test)
or skip(
message=bug(575),
subject="const",
case_description="const with 1 does not match true",
)(test)
or skip(
message=bug(575),
subject="const",
case_description="const with 0 does not match false",
)(test)
or skip(
message=bug(575),
subject="enum",
Expand Down

0 comments on commit 1598940

Please sign in to comment.