Skip to content

Commit

Permalink
- Invalid.messages() now returns an empty list if there are no messages.
Browse files Browse the repository at this point in the history
  See #21 .

Fixes #21
  • Loading branch information
mcdonc committed Feb 23, 2012
1 parent a6b85dd commit 8f16140
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

Expand Down
12 changes: 7 additions & 5 deletions colander/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ def __init__(self, node, msg=None, value=None):
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):
Expand Down
5 changes: 5 additions & 0 deletions colander/tests/test_colander.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ def test_messages_msg_not_iterable(self):
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
Expand Down

0 comments on commit 8f16140

Please sign in to comment.