Skip to content

Fixes #164, with test-case, as requested by Julian Berman. #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2014
Merged
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
6 changes: 3 additions & 3 deletions jsonschema/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def __str__(self):
return unicode(self).encode("utf-8")

def __unicode__(self):
if _unset in (
self.validator, self.validator_value, self.instance, self.schema,
):
if any(m is _unset for m in (
self.validator, self.validator_value, self.instance, self.schema
)):
return self.message

pschema = pprint.pformat(self.schema, width=72)
Expand Down
20 changes: 20 additions & 0 deletions jsonschema/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,23 @@ def test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error(self):
)
tree = exceptions.ErrorTree([error])
self.assertIsInstance(tree["foo"], exceptions.ErrorTree)


def test_str_works_with_instances_having_overriden_eq_operator(self):
"""
Checks for https://github.com./Julian/jsonschema/issues/164 which
rendered exceptions unusable when a `ValidationError` involved classes
withthe `eq` operator overridden (such as pandas.DataFrame),
caused by a `XX in YYY` check within `__unicode__`() method.
"""

class InstanceWithOverridenEq(object):
def __eq__(self, other):
raise Exception("Instance's __eq__()hould not have been called!")
inst = InstanceWithOverridenEq()
error = exceptions.ValidationError(
"a message", validator="foo", instance=inst, validator_value='some', schema='schema',
)

ex_str = str(error)
self.assertTrue(str(exceptions).find(type(inst).__name__), ex_str)