diff --git a/test/runner/lib/sanity/__init__.py b/test/runner/lib/sanity/__init__.py index 9f8c9b8f11..beda485a5f 100644 --- a/test/runner/lib/sanity/__init__.py +++ b/test/runner/lib/sanity/__init__.py @@ -15,7 +15,7 @@ from lib.util import ( run_command, import_plugins, load_plugins, - parse_to_dict, + parse_to_list_of_dict, ABC, is_binary_file, read_lines_without_comments, @@ -305,7 +305,7 @@ class SanityCodeSmellTest(SanityTest): if stdout and not stderr: if pattern: - matches = [parse_to_dict(pattern, line) for line in stdout.splitlines()] + matches = parse_to_list_of_dict(pattern, stdout) messages = [SanityMessage( message=m['message'], diff --git a/test/runner/lib/sanity/compile.py b/test/runner/lib/sanity/compile.py index b2ecb8f86b..633d8b70be 100644 --- a/test/runner/lib/sanity/compile.py +++ b/test/runner/lib/sanity/compile.py @@ -18,6 +18,7 @@ from lib.util import ( display, find_python, read_lines_without_comments, + parse_to_list_of_dict, ) from lib.config import ( @@ -72,7 +73,7 @@ class CompileTest(SanityMultipleVersion): pattern = r'^(?P[^:]*):(?P[0-9]+):(?P[0-9]+): (?P.*)$' - results = [re.search(pattern, line).groupdict() for line in stdout.splitlines()] + results = parse_to_list_of_dict(pattern, stdout) results = [SanityMessage( message=r['message'], diff --git a/test/runner/lib/sanity/import.py b/test/runner/lib/sanity/import.py index ebe3893af5..296fce0e82 100644 --- a/test/runner/lib/sanity/import.py +++ b/test/runner/lib/sanity/import.py @@ -20,6 +20,7 @@ from lib.util import ( display, find_python, read_lines_without_comments, + parse_to_list_of_dict, ) from lib.ansible_util import ( @@ -112,7 +113,7 @@ class ImportTest(SanityMultipleVersion): pattern = r'^(?P[^:]*):(?P[0-9]+):(?P[0-9]+): (?P.*)$' - results = [re.search(pattern, line).groupdict() for line in ex.stdout.splitlines()] + results = parse_to_list_of_dict(pattern, ex.stdout) results = [SanityMessage( message=r['message'], diff --git a/test/runner/lib/sanity/pep8.py b/test/runner/lib/sanity/pep8.py index cf48749385..0cec3d6b59 100644 --- a/test/runner/lib/sanity/pep8.py +++ b/test/runner/lib/sanity/pep8.py @@ -16,6 +16,7 @@ from lib.util import ( display, run_command, read_lines_without_comments, + parse_to_list_of_dict, ) from lib.config import ( @@ -80,7 +81,7 @@ class Pep8Test(SanitySingleVersion): if stdout: pattern = '^(?P[^:]*):(?P[0-9]+):(?P[0-9]+): (?P[WE][0-9]{3}) (?P.*)$' - results = [re.search(pattern, line).groupdict() for line in stdout.splitlines()] + results = parse_to_list_of_dict(pattern, stdout) else: results = [] diff --git a/test/runner/lib/sanity/rstcheck.py b/test/runner/lib/sanity/rstcheck.py index 9cd9d8313d..14a0dd0aad 100644 --- a/test/runner/lib/sanity/rstcheck.py +++ b/test/runner/lib/sanity/rstcheck.py @@ -14,7 +14,7 @@ from lib.sanity import ( from lib.util import ( SubprocessError, run_command, - parse_to_dict, + parse_to_list_of_dict, display, find_executable, read_lines_without_comments, @@ -72,7 +72,7 @@ class RstcheckTest(SanitySingleVersion): pattern = r'^(?P[^:]*):(?P[0-9]+): \((?PINFO|WARNING|ERROR|SEVERE)/[0-4]\) (?P.*)$' - results = [parse_to_dict(pattern, line) for line in stderr.splitlines()] + results = parse_to_list_of_dict(pattern, stderr) results = [SanityMessage( message=r['message'], diff --git a/test/runner/lib/util.py b/test/runner/lib/util.py index 373cdaf93d..30808f9fc7 100644 --- a/test/runner/lib/util.py +++ b/test/runner/lib/util.py @@ -741,18 +741,27 @@ def docker_qualify_image(name): return config.get('name', name) -def parse_to_dict(pattern, value): +def parse_to_list_of_dict(pattern, value): """ :type pattern: str :type value: str - :return: dict[str, str] + :return: list[dict[str, str]] """ - match = re.search(pattern, value) + matched = [] + unmatched = [] - if match is None: - raise Exception('Pattern "%s" did not match value: %s' % (pattern, value)) + for line in value.splitlines(): + match = re.search(pattern, line) - return match.groupdict() + if match: + matched.append(match.groupdict()) + else: + unmatched.append(line) + + if unmatched: + raise Exception('Pattern "%s" did not match values:\n%s' % (pattern, '\n'.join(unmatched))) + + return matched def get_available_port():