X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Futils%2Fpython%2Ftap%2Fdirective.py;fp=tests%2Futils%2Fpython%2Ftap%2Fdirective.py;h=6171ca2e28e2011ff4754ab86809c7234b00dbd4;hb=b85894a3df84e5a19736e0fa7ea848e56f696c63;hp=0000000000000000000000000000000000000000;hpb=1b8fb86234d51aff255b8e97435d4dbb3316eaec;p=babeltrace.git diff --git a/tests/utils/python/tap/directive.py b/tests/utils/python/tap/directive.py new file mode 100644 index 00000000..6171ca2e --- /dev/null +++ b/tests/utils/python/tap/directive.py @@ -0,0 +1,63 @@ +# Copyright (c) 2016, Matt Layman + +import re + + +class Directive(object): + """A representation of a result line directive.""" + + skip_pattern = re.compile( + r"""^SKIP\S* + (?P\s*) # Optional whitespace. + (?P.*) # Slurp up the rest.""", + re.IGNORECASE | re.VERBOSE) + todo_pattern = re.compile( + r"""^TODO\b # The directive name + (?P\s*) # Immediately following must be whitespace. + (?P.*) # Slurp up the rest.""", + re.IGNORECASE | re.VERBOSE) + + def __init__(self, text): + """Initialize the directive by parsing the text. + + The text is assumed to be everything after a '#\s*' on a result line. + """ + self._text = text + self._skip = False + self._todo = False + self._reason = None + + match = self.skip_pattern.match(text) + if match: + self._skip = True + self._reason = match.group('reason') + + match = self.todo_pattern.match(text) + if match: + if match.group('whitespace'): + self._todo = True + else: + # Catch the case where the directive has no descriptive text. + if match.group('reason') == '': + self._todo = True + self._reason = match.group('reason') + + @property + def text(self): + """Get the entire text.""" + return self._text + + @property + def skip(self): + """Check if the directive is a SKIP type.""" + return self._skip + + @property + def todo(self): + """Check if the directive is a TODO type.""" + return self._todo + + @property + def reason(self): + """Get the reason for the directive.""" + return self._reason