Add a simple test and all of the args.

This commit is contained in:
Julian Berman 2014-10-12 17:46:47 -04:00
parent ff426eb870
commit 1610e2802d
No known key found for this signature in database
GPG Key ID: 3F8D9C8C011729F8
2 changed files with 17 additions and 5 deletions

View File

@ -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)

View File

@ -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!")),