diff options
Diffstat (limited to 'tests/bzip2/parser.py')
-rw-r--r-- | tests/bzip2/parser.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/bzip2/parser.py b/tests/bzip2/parser.py new file mode 100644 index 0000000..276e811 --- /dev/null +++ b/tests/bzip2/parser.py @@ -0,0 +1,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 |