forked from kaste/PyTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatchers.py
37 lines (25 loc) · 976 Bytes
/
matchers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import functools
import re
def _get_matches(regex, i, j, k, text, make_abs, testcase=''):
# type: (Regex, int, int, int, str) -> List[Dict]
return [{'file': make_abs(m[i]), 'line': int(m[j]), 'text': m[k],
'testcase': testcase}
for m in regex.findall(text)]
LINE_TB = re.compile(r"^(.*):([0-9]+):(.)(.*)", re.M)
LONG_TB = re.compile(
r"(?:^>.*\n((?:.*?\n)*?))?\n(.*):(\d+):(.?)([\w ]*)$", re.M)
SHORT_TB = re.compile(
r"^(.*):([0-9]+):(.)(?:.*)\n(?:\s{4}.+)+\n((?:E.+\n?)*)", re.M)
Matchers = {
'line': functools.partial(_get_matches, LINE_TB, 0, 1, 3),
'short': functools.partial(_get_matches, SHORT_TB, 0, 1, 3),
'long': functools.partial(_get_matches, LONG_TB, 1, 2, 0),
'auto': functools.partial(_get_matches, LONG_TB, 1, 2, 0)
}
CULPRIT = re.compile(r'^((?:E.+\n?)+)', re.M)
def get_culprit(text):
match = CULPRIT.match(text)
if match:
return match.group(0)
else:
return ''