import json import shutil import plugins.agl_test_conf as conf #Compress the tmp log to .zip def log_compress(THIS_TEST): base_name = conf.get_log_dir(THIS_TEST) root_dir = conf.get_tmp_log_dir(THIS_TEST) shutil.make_archive(base_name,'zip',root_dir) #Get all test cases status #The type of test_cases_values_and_status is list,it's looks like that: #[['test_id', 'values', 'status'], ['rpm01', 'TEST-PASS', 'passed'],....] #The type of case_status is directory,it's looks like: #{'rpm03': 'passed', 'rpm02': 'passed', 'rpm01': 'passed'} def get_case_status(test_cases_values_and_status): num = len(test_cases_values_and_status) case_status = {} for i in range(num): if (i==0): continue case_status[test_cases_values_and_status[i][0]] = test_cases_values_and_status[i][2] return case_status #Input format # { # "test_id": ['test_id', 'values', 'status'], # "test_id": ['test_id', 'values', 'status'] # } #Output format # { # 'test_id': 'status', # 'test_id': 'status' # } def format_caselist(case_info_list: dict): case_status = dict() for key in case_info_list: case_info = case_info_list[key] case_status[key] = case_info[2] return case_status #Input format # { # "test_id": ['test_id', 'values', 'status'], # "test_id": ['test_id', 'values', 'status'] # } #Output format # { # 'collected': collected_num, # 'passed': passed_num, # 'failed': failed_num, # 'skipped": skipped_num # } def format_summary(case_info_list): collected_num = passed_num = xpassed_num = failed_num = xfailed_num = skipped_num = 0 for key in case_info_list: case_info = case_info_list[key] collected_num = collected_num + 1 if (case_info[2] == "passed"): passed_num = passed_num + 1 elif (case_info[2] == "xpassed"): xpassed_num = xpassed_num + 1 elif (case_info[2] == "failed"): failed_num = failed_num + 1 elif (case_info[2] == "xfailed"): xfailed_num = xfailed_num + 1 else: skipped_num = skipped_num + 1 summary = dict() summary["collected"] = collected_num summary["passed"] = passed_num summary["xpassed"] = xpassed_num summary["failed"] = failed_num summary["xfailed"] = xfailed_num summary["skipped"] = skipped_num return summary def format_json_data(name, test_set_status, summary, case_status): data = summary data["test_name"] = name data["test_status"] = test_set_status data["case_status"] = case_status return summary #Write the test result to a json file def write_data_to_json(THIS_TEST,test_set_status,summary,case_status): #The data that will be written into the json file data = { 'test_status': test_set_status, 'test_name': THIS_TEST, 'collected': summary[0][1], 'passed': summary[1][1], 'xpassed': summary[2][1], 'failed': summary[3][1], 'xfailed': summary[4][1], 'skipped': summary[5][1], 'case_status': case_status } #Write the "data" to the json file write_data_to_file(data, "json") def get_report_html(THIS_TEST,test_set_status,summary,case_status): html = "" #
html = html + "" html = html + "" + "Status :" + test_set_status + "
" html = html + "" + "Total: " + str(summary[0][1]) html = html + " Pass: " + str(summary[1][1]) html = html + " Xpass: " + str(summary[2][1]) html = html + " Fail: " + str(summary[3][1]) html = html + " Xfail: " + str(summary[4][1]) html = html + " Skip: " + str(summary[5][1]) + "
" html = html + "Details :
" #test case | " html = html + "status | " html = html + "
---|---|
" + test_case + " | " html = html + "" + case_status[test_case] + " | " html = html + "