Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing yaml blocks #31

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions tap2junit/tap13.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
RE_EXPLANATION = re.compile(r"^\s*#\s*(?P<explanation>.+)?\s*$")
RE_YAMLISH_START = re.compile(r"^\s*---.*$")
RE_YAMLISH_END = re.compile(r"^\s*\.\.\.\s*$")
RE_YAML_BLOCK = re.compile(r"^.*:\s*[|>][+-]?\s*$")


class Test:
Expand All @@ -49,6 +50,7 @@ def __init__(self, result, id, description=None, directive=None, comment=None):
self.comment = comment
self.yaml = None
self._yaml_buffer = None
self._yaml_block_indentation = None
self.diagnostics = []


Expand All @@ -65,21 +67,33 @@ def _parse(self, source):

in_test = False
in_yaml = False
in_yaml_block = False
for line in source:
if not seek_version and RE_VERSION.match(line):
if not seek_version and not in_yaml and RE_VERSION.match(line):
# refack: breaking TAP13 spec, to allow multiple TAP headers
seek_version = True
seek_plan = False
seek_test = False
in_test = False
in_yaml = False
in_yaml_block = False
self.__tests_counter = 0
# raise ValueError("Bad TAP format, multiple TAP headers")

if in_yaml:
if RE_YAMLISH_END.match(line):
indentation = len(line) - len(line.lstrip())
if (
in_yaml_block
and indentation > self.tests[-1]._yaml_block_indentation
):
continue
elif RE_YAML_BLOCK.match(line):
self.tests[-1]._yaml_block_indentation = indentation
in_yaml_block = True
elif RE_YAMLISH_END.match(line):
self.tests[-1]._yaml_buffer.append(line.strip())
in_yaml = False
in_yaml_block = False
self.tests[-1].yaml = yamlish.load(self.tests[-1]._yaml_buffer)
else:
self.tests[-1]._yaml_buffer.append(line.rstrip())
Expand All @@ -94,6 +108,7 @@ def _parse(self, source):
if RE_YAMLISH_START.match(line):
self.tests[-1]._yaml_buffer = [line.strip()]
in_yaml = True
in_yaml_block = False
continue

# this is "beginning" of the parsing, skip all lines until
Expand Down
Loading