import pytest import re ''' Process the log and init test_cases_values_and_status. log : the path of default log default log format : -> case_name: TEST-PASS -> case_name: TEST-FAIL -> case_name: TEST-SKIP ''' def log_process_default(log): pattern = '^ -> (.+?): (.+?)$' parse_result = log_parse(log, pattern) test_cases_values_and_status = [["test_id","values","status"]] if parse_result: for item in parse_result: item_result = [item[0], item[1], ""] test_cases_values_and_status.append(item_result) return test_cases_values_and_status ''' Process the log and init test_cases_values_and_status. log : the path of default log default log format : -> case_name: TEST-PASS -> case_name: TEST-FAIL -> case_name: TEST-SKIP ''' def log_process(log): pattern = '^ -> (.+?): (.+?)$' parse_result = log_parse(log, pattern) case_list = dict() if parse_result: for item in parse_result: case_list[item[0]] = [item[0], item[1], ""] return case_list ''' Process the log create by gnome_desktop_testing and init test_cases_values_and_status. log : the path of gnome_desktop_testing log gnome_desktop_testing log format: PASS: glib/tls-database.test FAIL: glib/markup-escape.test SKIP: glib/testname.test XFAIL: test/nfs/nfsacl.test XPASS: xxx/xxxx.test ERROR: xxx/xxxx.test ''' def log_process_gnome_desktop_testing(log): pattern = '^(FAIL|PASS|SKIP|XFAIL|XPASS|ERROR+?): (.+test?)' return log_process_with_pattern(log, pattern) ''' Process the log and init test_cases_values_and_status. log : the path of log file log format: PASS: case_name FAIL: case_name SKIP: case_name XFAIL: case_name XPASS: case_name ERROR: case_name ''' def log_process_gnu(log): pattern = '^(FAIL|PASS|SKIP|XFAIL|XPASS|ERROR+?): (.+)' return log_process_with_pattern(log, pattern) def log_process_with_pattern(log, pattern): parse_result = log_parse(log, pattern) case_list = dict() if parse_result: for item in parse_result: case_list[item[1]] = [item[1], item[0], ""] return case_list # parse log file with pattern def log_parse(log, pattern): regex = re.compile(pattern, re.MULTILINE) test_log = open(log, 'r') parse_result = [] line = test_log.readline() while line: matchs = regex.search(line) if matchs: groups = matchs.groups() parse_result.append(groups) line=test_log.readline() test_log.close() return parse_result