Skip to content

Commit 2c83d78

Browse files
committed
Make exceptions hashable (but not comparable)
Fixes python-jsonschema#477
1 parent 1a8ea88 commit 2c83d78

15 files changed

+19
-14
lines changed
1.1 KB
Binary file not shown.
8.51 KB
Binary file not shown.
4.72 KB
Binary file not shown.
6.38 KB
Binary file not shown.
Binary file not shown.
222 Bytes
Binary file not shown.
1.66 KB
Binary file not shown.
9.38 KB
Binary file not shown.
20.8 KB
Binary file not shown.

jsonschema/_version.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
# This file is automatically generated by setup.py.
3+
__version__ = '2.5.1.post64'
4+
__sha__ = 'gcb20c89'
5+
__revision__ = 'gcb20c89'

jsonschema/exceptions.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ def __init__(
5555
for error in context:
5656
error.parent = self
5757

58-
def __eq__(self, other):
59-
if not isinstance(other, self.__class__):
60-
return NotImplemented
61-
return self._contents() == other._contents()
62-
63-
def __ne__(self, other):
64-
if not isinstance(other, self.__class__):
65-
return NotImplemented
66-
return not self == other
67-
6858
def __repr__(self):
6959
return "<%s: %r>" % (self.__class__.__name__, self.message)
7060

Binary file not shown.
Binary file not shown.

jsonschema/tests/test_exceptions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def best_match(self, errors):
1212
reversed_best = exceptions.best_match(reversed(errors))
1313
msg = "Didn't return a consistent best match!\nGot: {0}\n\nThen: {1}"
1414
self.assertEqual(
15-
best, reversed_best, msg=msg.format(best, reversed_best),
15+
best._contents(), reversed_best._contents(), msg=msg.format(best, reversed_best),
1616
)
1717
return best
1818

@@ -460,3 +460,9 @@ def __ne__(this, other): # pragma: no cover
460460
schema="schema",
461461
)
462462
self.assertIn(repr(instance), str(error))
463+
464+
465+
class TestHashable(TestCase):
466+
def test_hashable(self):
467+
set([exceptions.ValidationError("")])
468+
set([exceptions.SchemaError("")])

jsonschema/tests/test_validators.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,21 @@ def test_iter_errors(self):
7373
schema = {u"startswith": u"hel"}
7474
iter_errors = self.Validator(schema).iter_errors
7575

76-
self.assertEqual(list(iter_errors(u"hello")), [])
76+
errors = list(iter_errors(u"hello"))
77+
self.assertEqual(errors, [])
7778

78-
error = ValidationError(
79+
expected_error = ValidationError(
7980
u"Whoops!",
8081
instance=u"goodbye",
8182
schema=schema,
8283
validator=u"startswith",
8384
validator_value=u"hel",
8485
schema_path=deque([u"startswith"]),
8586
)
86-
self.assertEqual(list(iter_errors(u"goodbye")), [error])
87+
88+
errors = list(iter_errors(u"goodbye"))
89+
self.assertEqual(len(errors), 1)
90+
self.assertEqual(errors[0]._contents(), expected_error._contents())
8791

8892
def test_if_a_version_is_provided_it_is_registered(self):
8993
Validator = validators.create(

0 commit comments

Comments
 (0)