- Invalid.messages() now returns an empty list if there are no messages.

See https://github.com/Pylons/colander/pull/21 .

Fixes #21
This commit is contained in:
Chris McDonough
2012-02-23 01:07:08 -05:00
parent a6b85dd9ba
commit 8f16140bba
3 changed files with 15 additions and 5 deletions

View File

@@ -14,6 +14,9 @@ Next release
https://github.com/Pylons/colander/pull/12 , and
https://github.com/Pylons/colander/issues/2 .
- Invalid.messages() now returns an empty list if there are no messages.
See https://github.com/Pylons/colander/pull/21 .
0.9.6 (2012-02-14)
------------------

View File

@@ -71,13 +71,15 @@ class Invalid(Exception):
self.children = []
def messages(self):
""" Return an iterable of error messages for this exception
using the ``msg`` attribute of this error node. If the
``msg`` attribute is iterable, it is returned. If it is not
iterable, a single-element list containing the ``msg`` value
is returned."""
""" Return an iterable of error messages for this exception using the
``msg`` attribute of this error node. If the ``msg`` attribute is
iterable, it is returned. If it is not iterable, and is
non-``None``, a single-element list containing the ``msg`` value is
returned. If the value is ``None``, an empty list is returned."""
if is_nonstr_iter(self.msg):
return self.msg
if self.msg is None:
return []
return [self.msg]
def add(self, exc, pos=None):

View File

@@ -183,6 +183,11 @@ class TestInvalid(unittest.TestCase):
exc = self._makeOne(node, 'msg')
self.assertEqual(exc.messages(), ['msg'])
def test_messages_msg_None(self):
node = DummySchemaNode(None)
exc = self._makeOne(node, None)
self.assertEqual(exc.messages(), [])
class TestAll(unittest.TestCase):
def _makeOne(self, validators):
from colander import All