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