blob: 276e811186a42525763da8210c137b0e189e2efa (
plain)
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
|
#
# this is a parser function specially designed for the 'bzip2.log'
#
import re
def log_parse(log_file):
# set up rule for regex
reObj = re.compile('^(PASS|FAIL+?): (.+)', re.MULTILINE)
# init a dictionary, it stores the return result
case_list = dict()
# open file
test_log = open(log_file, 'r')
# start to read the new line
line = test_log.readline()
while line:
if ("Testing decompression and recompression..." in line):
# dectect trigger line for part 2, change regex rule
reObj = re.compile('^(PASS|FAIL+?): /usr/lib/bzip2/ptest/bzip2-tests/(.+)', re.MULTILINE)
elif ("Testing detection of bad input data..." in line):
# dectect trigger line for part 3, change regex rule
reObj = re.compile('^(PASS|FAIL+?): .+/usr/lib/bzip2/ptest/bzip2-tests/(.+)', re.MULTILINE)
# checking regex status in line
matchs = reObj.search(line)
# if the line fits the regex rule
if matchs:
# spliting elements into a tuple
# it looks like ('PASS', '<File_Name Test_Name>')
groups = matchs.groups()
# adjust name
tmp_name = groups[1]
tmp_name = tmp_name.strip()
case_name = tmp_name.replace('.bad', '.bad Check Integrity')
# then just add a new key naming after case_name, along with its values
case_list[case_name] = [case_name, groups[0], ""]
# jump out if-else, read next line
line = test_log.readline()
test_log.close()
return case_list
|