From 1610e2802dfa846c3c26fed71d03b3fab8dcacab Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 12 Oct 2014 17:46:47 -0400 Subject: [PATCH] Add a simple test and all of the args. --- jsonschema/exceptions.py | 16 ++++++++++++---- jsonschema/tests/test_exceptions.py | 6 +++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index b93ec86..3f3b4b4 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -27,10 +27,18 @@ class _Error(Exception): schema_path=(), parent=None, ): - # Calling __init__ is important, because otherwise __reduce__ will - # return empty args tuple on Py2.7 and unpickling will fail because - # init requires at least one argument. - super(_Error, self).__init__(message) + super(_Error, self).__init__( + message, + validator, + path, + cause, + context, + validator_value, + instance, + schema, + schema_path, + parent, + ) self.message = message self.path = self.relative_path = deque(path) self.schema_path = self.relative_schema_path = deque(schema_path) diff --git a/jsonschema/tests/test_exceptions.py b/jsonschema/tests/test_exceptions.py index 9e5793c..cbe3363 100644 --- a/jsonschema/tests/test_exceptions.py +++ b/jsonschema/tests/test_exceptions.py @@ -273,7 +273,7 @@ class TestErrorTree(unittest.TestCase): self.assertIsInstance(tree["foo"], exceptions.ErrorTree) -class TestErrorReprStr(unittest.TestCase): +class TestErrorInitReprStr(unittest.TestCase): def make_error(self, **kwargs): defaults = dict( message=u"hello", @@ -295,6 +295,10 @@ class TestErrorReprStr(unittest.TestCase): self.assertEqual(message_line, error.message) self.assertEqual(rest, expected) + def test_it_calls_super_and_sets_args(self): + error = self.make_error() + self.assertGreater(len(error.args), 1) + def test_repr(self): self.assertEqual( repr(exceptions.ValidationError(message="Hello!")),