6171ca2e28e2011ff4754ab86809c7234b00dbd4
[babeltrace.git] / tests / utils / python / tap / directive.py
1 # Copyright (c) 2016, Matt Layman
2
3 import re
4
5
6 class Directive(object):
7 """A representation of a result line directive."""
8
9 skip_pattern = re.compile(
10 r"""^SKIP\S*
11 (?P<whitespace>\s*) # Optional whitespace.
12 (?P<reason>.*) # Slurp up the rest.""",
13 re.IGNORECASE | re.VERBOSE)
14 todo_pattern = re.compile(
15 r"""^TODO\b # The directive name
16 (?P<whitespace>\s*) # Immediately following must be whitespace.
17 (?P<reason>.*) # Slurp up the rest.""",
18 re.IGNORECASE | re.VERBOSE)
19
20 def __init__(self, text):
21 """Initialize the directive by parsing the text.
22
23 The text is assumed to be everything after a '#\s*' on a result line.
24 """
25 self._text = text
26 self._skip = False
27 self._todo = False
28 self._reason = None
29
30 match = self.skip_pattern.match(text)
31 if match:
32 self._skip = True
33 self._reason = match.group('reason')
34
35 match = self.todo_pattern.match(text)
36 if match:
37 if match.group('whitespace'):
38 self._todo = True
39 else:
40 # Catch the case where the directive has no descriptive text.
41 if match.group('reason') == '':
42 self._todo = True
43 self._reason = match.group('reason')
44
45 @property
46 def text(self):
47 """Get the entire text."""
48 return self._text
49
50 @property
51 def skip(self):
52 """Check if the directive is a SKIP type."""
53 return self._skip
54
55 @property
56 def todo(self):
57 """Check if the directive is a TODO type."""
58 return self._todo
59
60 @property
61 def reason(self):
62 """Get the reason for the directive."""
63 return self._reason
This page took 0.030709 seconds and 3 git commands to generate.