Skip to content

Commit

Permalink
Reduce complexity of parse function
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
  • Loading branch information
fmartinsons committed Jul 18, 2022
1 parent a30b431 commit e009f49
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions tap2junit/tap13.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ def __init__(self):
self.__tests_counter = 0
self.tests_planned = None

def _parse_yaml(self, line, in_yaml, in_yaml_block):
indentation = len(line) - len(line.lstrip())
if (
in_yaml_block
and indentation > self.tests[-1]._yaml_block_indentation
):
return in_yaml, in_yaml_block
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())

return in_yaml, in_yaml_block

def _parse(self, source):
seek_version = True
seek_plan = False
Expand Down Expand Up @@ -102,22 +122,7 @@ def _parse(self, source):
# raise ValueError("Bad TAP format, multiple TAP headers")

if in_yaml:
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())
in_yaml, in_yaml_block = self._parse_yaml(line, in_yaml, in_yaml_block)
continue

line = line.strip()
Expand Down

0 comments on commit e009f49

Please sign in to comment.