diff options
-rw-r--r-- | qtip/collector/parser/grep.py | 5 | ||||
-rw-r--r-- | tests/unit/collector/grep_test.py | 4 |
2 files changed, 6 insertions, 3 deletions
diff --git a/qtip/collector/parser/grep.py b/qtip/collector/parser/grep.py index d7ada485..c3274bc2 100644 --- a/qtip/collector/parser/grep.py +++ b/qtip/collector/parser/grep.py @@ -29,5 +29,6 @@ class GrepParser(BaseActor): def grep_in_file(filename, regex): - with open(filename, 'r') as f: - return filter(lambda x: x is not None, [re.search(regex, line) for line in f]) + with open(filename, "r") as outfile: + return filter(lambda x: x is not None, + list(re.finditer(regex, outfile.read(), re.MULTILINE))) diff --git a/tests/unit/collector/grep_test.py b/tests/unit/collector/grep_test.py index e5d5f8c6..2d4079af 100644 --- a/tests/unit/collector/grep_test.py +++ b/tests/unit/collector/grep_test.py @@ -21,7 +21,9 @@ def logfile(data_root): @pytest.mark.parametrize("regex,expected", [ ('not exist', []), ('Lorem (\S+)', [{'groups': ('ipsum',), 'groupdict': {}}]), - ('nisi ut (?P<name>\S+)', [{'groups': ('aliquip',), 'groupdict': {'name': 'aliquip'}}]) + ('nisi ut (?P<name>\S+)', [{'groups': ('aliquip',), 'groupdict': {'name': 'aliquip'}}]), + ('Lorem\s(\w+)\s.+\nconsectetur\s(\w+)\s.+\n', + [{'groups': ('ipsum', 'adipiscing',), 'groupdict': {}}]) ]) def test_grep_in_file(logfile, regex, expected): matches = grep_in_file(logfile, regex) |