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