Improve ansible-test match error handling.

This commit is contained in:
Matt Clay 2018-09-20 22:20:08 -07:00
parent 27c10fa502
commit 2056c981ae
6 changed files with 25 additions and 13 deletions

View file

@ -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():