config: Lists need to handle missing values

This commit is contained in:
Thomas Adamcik 2014-06-21 14:11:24 +02:00
parent 3c196ed645
commit 58976ef52d
2 changed files with 8 additions and 0 deletions

View File

@ -185,6 +185,8 @@ class List(ConfigValue):
return tuple(values)
def serialize(self, value, display=False):
if not value:
return b''
return b'\n ' + b'\n '.join(encode(v) for v in value if v)

View File

@ -268,6 +268,12 @@ class ListTest(unittest.TestCase):
self.assertIsInstance(result, bytes)
self.assertRegexpMatches(result, r'foo\n\s*bar\n\s*baz')
def test_serialize_none(self):
value = types.List()
result = value.serialize(None)
self.assertIsInstance(result, bytes)
self.assertEqual(result, '')
class LogLevelTest(unittest.TestCase):
levels = {'critical': logging.CRITICAL,