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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
import re
import sys
# log sample
#== Tests result: FAILURE ==
#
#365 tests OK.
#
#8 tests failed:
# test_ctypes test_distutils test_email test_mmap test_shutil
# test_site test_sysconfig test_venv
#
#28 tests skipped:
# test_asdl_parser test_clinic test_curses test_dbm_gnu
# test_dbm_ndbm test_devpoll test_gdb test_idle test_kqueue
# test_msilib test_ossaudiodev test_smtpnet test_socketserver
# test_startfile test_tcl test_timeout test_tix test_tk
# test_ttk_guionly test_ttk_textonly test_turtle test_urllib2net
# test_urllibnet test_winconsoleio test_winreg test_winsound
# test_xmlrpc_net test_zipfile64
#
#Total duration: 1 hour 7 min
#Tests result: FAILURE
def log_parse(log_file):
# init all tests with PASS
case_list = dict()
log_message = 'PASS'
key = '^[0-9]+:[0-9]+:[0-9]+ load avg: .*\\] (test_.+)'
case_list = init_tests(log_file, key, log_message)
# update FAIL test
log_message = "FAIL"
start_key = '^[0-9]+ tests failed:'
end_key = ['^[0-9]+ tests skipped:', '^Total duration: .*']
fail_list = search_tests_with_key(log_file, start_key, end_key)
for item in fail_list.split():
case_list[item] = [item, log_message, ""]
#update skipped tests
log_message = "SKIP"
start_key = '^[0-9]+ tests skipped:'
end_key = ['^Total duration: .*']
skip_list = search_tests_with_key(log_file, start_key, end_key)
for item in skip_list.split():
case_list[item] = [item, log_message, ""]
return case_list
def init_tests(log_file, key, log_message):
case_list = dict()
reObj = re.compile(key, re.MULTILINE)
test_log = open(log_file, 'r')
line = test_log.readline()
while line:
matchs = reObj.search(line)
if matchs:
groups = matchs.groups()
# get the fisrt part from groups[0]
# e.g.
# goups[0]:test_zipimport -- test_zipfile64 skipped (resource denied)
# name:test_zipimport
name = groups[0].split()[0]
case_list[name] = [name, log_message, ""]
line = test_log.readline()
test_log.close()
return case_list
def search_tests_with_key(log_file, start_key, end_key):
# search line with start key
reObj_start = re.compile(start_key, re.MULTILINE)
test_log = open(log_file, 'r')
line = test_log.readline()
while line:
matchs_start = reObj_start.search(line)
if matchs_start:
break;
line = test_log.readline()
line = test_log.readline()
# search tests before end_key
tests_list = ""
while line:
end_flag = False;
for key in end_key:
reObj_end = re.compile(key, re.MULTILINE)
matchs_end = reObj_end.search(line)
if matchs_end:
end_flag = True
break;
if end_flag:
break;
tests_list = tests_list + line.strip() + " "
line = test_log.readline()
test_log.close()
return tests_list
if __name__ == "__main__":
log_file = sys.argv[1]
key = sys.argv[2]
case_list = log_parse(log_file)
for case in case_list:
if case_list[case][1] == key:
print(case_list[case])
|