From c3481155481325f87aa302cff9f09f3f5100092f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Wed, 11 Mar 2020 15:52:47 +0100 Subject: [PATCH] Replace read_stripped_lines with generator --- mycroft/util/file_utils.py | 5 ++++- test/unittests/util/test_util.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mycroft/util/file_utils.py b/mycroft/util/file_utils.py index 1d95a46236f..ec8f3781cba 100644 --- a/mycroft/util/file_utils.py +++ b/mycroft/util/file_utils.py @@ -88,7 +88,10 @@ def read_stripped_lines(filename): (list) list of lines stripped from leading and ending white chars. """ with open(filename, 'r') as f: - return [line.strip() for line in f] + for line in f: + line = line.strip() + if line: + yield line def read_dict(filename, div='='): diff --git a/test/unittests/util/test_util.py b/test/unittests/util/test_util.py index 8b98f7ec19e..2383d93ed75 100644 --- a/test/unittests/util/test_util.py +++ b/test/unittests/util/test_util.py @@ -92,7 +92,7 @@ def test_read_stripped_lines(self): expected = ['Once upon a time', 'there was a great Dragon', 'It was red and cute', 'The end'] unstripped_path = join(TestReadFiles.base, 'unstripped_lines.txt') - self.assertEqual(read_stripped_lines(unstripped_path), expected) + self.assertEqual(list(read_stripped_lines(unstripped_path)), expected) def test_read_dict(self): expected = {'fraggle': 'gobo', 'muppet': 'miss piggy'}