mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-28 03:49:09 -07:00
Improve ansible-test match error handling.
This commit is contained in:
parent
27c10fa502
commit
2056c981ae
6 changed files with 25 additions and 13 deletions
|
@ -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():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue