diff --git a/lib/utils/text.py b/lib/utils/text.py index 3da8f83160532c04b0b60e3178229adb62ac4004..84de0bb99608e07e1c2edb5ad3edd96d98a4edfd 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 e1181821fe48929ff1fde8b3ddbf923c6c3e48b9..16dd6ace8ee64725eeaf6bb9deb958f282b7b768 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",