From: Michael Hanselmann Date: Thu, 4 Oct 2012 17:58:45 +0000 (+0200) Subject: utils.FilterEmptyLinesAndComments: Return list X-Git-Tag: v2.7.0beta1~883 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/6a9b977826a6a45b28a9d9226c5d9b56ce8d72a6?hp=555b6cb18c14d6f7145b7fc754a1eb5231b92314 utils.FilterEmptyLinesAndComments: Return list We don't use generators often and lists are easier to re-use. Signed-off-by: Michael Hanselmann Reviewed-by: Bernardo Dal Seno --- diff --git a/lib/utils/text.py b/lib/utils/text.py index 3da8f83..84de0bb 100644 --- a/lib/utils/text.py +++ b/lib/utils/text.py @@ -598,12 +598,9 @@ def FilterEmptyLinesAndComments(text): @type text: string @param text: Input string - @rtype: generator + @rtype: list """ - for line in text.splitlines(): - line = line.strip() - - # Ignore empty lines and comments - if line and not line.startswith("#"): - yield line + return [line for line in map(lambda s: s.strip(), text.splitlines()) + # Ignore empty lines and comments + if line and not line.startswith("#")] diff --git a/test/ganeti.utils.text_unittest.py b/test/ganeti.utils.text_unittest.py index e118182..16dd6ac 100755 --- a/test/ganeti.utils.text_unittest.py +++ b/test/ganeti.utils.text_unittest.py @@ -594,15 +594,11 @@ class TestTruncate(unittest.TestCase): class TestFilterEmptyLinesAndComments(unittest.TestCase): - @staticmethod - def _Test(text): - return list(utils.FilterEmptyLinesAndComments(text)) - def testEmpty(self): - self.assertEqual(self._Test(""), []) - self.assertEqual(self._Test("\n"), []) - self.assertEqual(self._Test("\n" * 100), []) - self.assertEqual(self._Test("\n \n\t \n"), []) + self.assertEqual(utils.FilterEmptyLinesAndComments(""), []) + self.assertEqual(utils.FilterEmptyLinesAndComments("\n"), []) + self.assertEqual(utils.FilterEmptyLinesAndComments("\n" * 100), []) + self.assertEqual(utils.FilterEmptyLinesAndComments("\n \n\t \n"), []) def test(self): text = """ @@ -618,7 +614,7 @@ class TestFilterEmptyLinesAndComments(unittest.TestCase): # multiple places Hello World! """ - self.assertEqual(self._Test(text), [ + self.assertEqual(utils.FilterEmptyLinesAndComments(text), [ "This", "is", "a",