Skip to content

Commit 456234a

Browse files
committed
Test-case for python-jsonschema#164, ValidationError.__unicode__(): use 'is' operator
instead of '==' for unset-check Currently test-case FAILS with a json-instances that have a screaming __eq__() operator.
1 parent 83e810c commit 456234a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

jsonschema/tests/test_exceptions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,23 @@ def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
268268
)
269269
tree = exceptions.ErrorTree([error])
270270
self.assertIsInstance(tree["foo"], exceptions.ErrorTree)
271+
272+
273+
def test_str_works_with_instances_having_overriden_eq_operator(self):
274+
"""
275+
Checks for https://github.com/Julian/jsonschema/issues/164 which
276+
rendered exceptions unusable when a `ValidationError` involved classes
277+
withthe `eq` operator overridden (such as pandas.DataFrame),
278+
caused by a `XX in YYY` check within `__unicode__`() method.
279+
"""
280+
281+
class InstanceWithOverridenEq(object):
282+
def __eq__(self, other):
283+
raise Exception("Instance's __eq__()hould not have been called!")
284+
inst = InstanceWithOverridenEq()
285+
error = exceptions.ValidationError(
286+
"a message", validator="foo", instance=inst, validator_value='some', schema='schema',
287+
)
288+
289+
ex_str = str(error)
290+
self.assertTrue(str(exceptions).find(type(inst).__name__), ex_str)

0 commit comments

Comments
 (0)