-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatter.py
32 lines (28 loc) · 1.16 KB
/
formatter.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
# -*- coding: utf-8 -*-
import re
TEST_NAME = re.compile(r'.*\stest_([:\w]+)\s.*')
TEST_RESULTS = re.compile(r".*'(.*)'.*'(.*)'.*")
tests = []
with open('test_data.py') as f:
for i, l in enumerate(f):
tests.append((l, i+1))
with open('test.txt') as text:
with open('readable.txt', 'w') as out:
for line in text:
if line.startswith('FAIL:') or line.startswith('AssertionError:'):
res = TEST_NAME.search(line)
if res is not None:
test_name = res.group(1)
pat = '"{0}"'.format(test_name)
line_n = 0
for te, line_num in tests:
if pat in te:
line_n = line_num
break
out.write('{0} (line {1})\n'.format(test_name, line_n))
res = TEST_RESULTS.search(line)
if res is not None:
out.write(' {0}\n'.format(res.group(1)))
out.write(' {0}\n\n'.format(res.group(2)))
if line.startswith('Ran') or line.startswith('FAILED'):
out.write(line)