@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("#")]
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 = """
# multiple places
Hello World!
"""
- self.assertEqual(self._Test(text), [
+ self.assertEqual(utils.FilterEmptyLinesAndComments(text), [
"This",
"is",
"a",