- 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:
@@ -14,6 +14,9 @@ Next release
|
|||||||
https://github.com/Pylons/colander/pull/12 , and
|
https://github.com/Pylons/colander/pull/12 , and
|
||||||
https://github.com/Pylons/colander/issues/2 .
|
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)
|
0.9.6 (2012-02-14)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|||||||
@@ -71,13 +71,15 @@ class Invalid(Exception):
|
|||||||
self.children = []
|
self.children = []
|
||||||
|
|
||||||
def messages(self):
|
def messages(self):
|
||||||
""" Return an iterable of error messages for this exception
|
""" Return an iterable of error messages for this exception using the
|
||||||
using the ``msg`` attribute of this error node. If the
|
``msg`` attribute of this error node. If the ``msg`` attribute is
|
||||||
``msg`` attribute is iterable, it is returned. If it is not
|
iterable, it is returned. If it is not iterable, and is
|
||||||
iterable, a single-element list containing the ``msg`` value
|
non-``None``, a single-element list containing the ``msg`` value is
|
||||||
is returned."""
|
returned. If the value is ``None``, an empty list is returned."""
|
||||||
if is_nonstr_iter(self.msg):
|
if is_nonstr_iter(self.msg):
|
||||||
return self.msg
|
return self.msg
|
||||||
|
if self.msg is None:
|
||||||
|
return []
|
||||||
return [self.msg]
|
return [self.msg]
|
||||||
|
|
||||||
def add(self, exc, pos=None):
|
def add(self, exc, pos=None):
|
||||||
|
|||||||
@@ -183,6 +183,11 @@ class TestInvalid(unittest.TestCase):
|
|||||||
exc = self._makeOne(node, 'msg')
|
exc = self._makeOne(node, 'msg')
|
||||||
self.assertEqual(exc.messages(), ['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):
|
class TestAll(unittest.TestCase):
|
||||||
def _makeOne(self, validators):
|
def _makeOne(self, validators):
|
||||||
from colander import All
|
from colander import All
|
||||||
|
|||||||
Reference in New Issue
Block a user