# # this is a parser function specially designed for the 'expat.log' # import re def log_parse(log_file): # define prefix as a global var # but we set default to "runtests_" prefix = "runtests_" # there is one repeat test, which is named 'test_return_ns_triplet' # we figured out the cause, the second time it showed up was for it # was triggered by test 'test_ns_parser_reset', so the suffix goes like: suffix = "_triggered_by_test_ns_parser_reset" # set up rule for regex reObj = re.compile('^(FAIL|PASS|SKIP+?): (test+?.+)', 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 ("runtestspp" in line): # if detected runtestspp in line, set prefix to ---> runtestspp_ prefix = "runtestspp_" # 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', '') groups = matchs.groups() # rename the case, add a prefix case_name = prefix + groups[1] # if the case is not stored in the result dictionary if case_name not in case_list: # then just add a new key naming after case_name, along with its values case_list[case_name] = [case_name, groups[0], ""] # if the test case has already been in the result list else: # add a suffix for the repeat test case name case_name = prefix + groups[1] + suffix # add it to the result dictionary 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