diff options
author | duerpei <duep.fnst@fujitsu.com> | 2022-10-22 16:55:45 +0800 |
---|---|---|
committer | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2023-01-20 16:02:58 +0000 |
commit | 2f9db91f9e63e7b746770b17c2c9204ff663a7de (patch) | |
tree | e59ac3cdf3426472f60932fc0874cc4d6123ac29 /plugins/agl_test_report.py | |
parent | 4c5dbc9e8b311b605e750534b51dbb899fb8ccce (diff) |
agl-test-framework: optimize the generated html report
Optimize the generated html report, make its format more beautiful
and readable.
Bug-AGL: SPEC-4345
Signed-off-by: duerpei <duep.fnst@fujitsu.com>
Change-Id: I0b779e0998ded00b348e23f2c1ac5b8acf5b8fd8
Diffstat (limited to 'plugins/agl_test_report.py')
-rw-r--r-- | plugins/agl_test_report.py | 107 |
1 files changed, 30 insertions, 77 deletions
diff --git a/plugins/agl_test_report.py b/plugins/agl_test_report.py index 5896722..ad7b9e6 100644 --- a/plugins/agl_test_report.py +++ b/plugins/agl_test_report.py @@ -1,5 +1,6 @@ import json import shutil +import subprocess import plugins.agl_test_conf as conf @@ -103,58 +104,6 @@ def write_data_to_json(THIS_TEST,test_set_status,summary,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>" - - #<head> </head> - html = html + "<head>" - html = html + "<title>" - html = html + THIS_TEST + "test report" - html = html + "</title>" - html = html + "</head>" - - #<body> </body> - html = html + "<body>" - html = html + "<h1>" + THIS_TEST + " test report" + "</h1>" - html = html + "<p>" + "Status :" + test_set_status + "</p>" - html = html + "<p>" + "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]) + "</p>" - html = html + "<p>Details : </p>" - - #<table> </table> - html = html + "<table border=\"1\" cellspacing=\"2\" >" - html = html + "<tr bgcolor = \"2400B0\">" - html = html + "<th><font color = \"white\">test case</font></th>" - html = html + "<th><font color = \"white\">status</font></th>" - html = html + "</tr>" - - #Add content to the table - bgcolor = 0 - for test_case in case_status: - if bgcolor == 0: - html = html + "<tr bgcolor = \"CCCBE4\">" - bgcolor = 1 - else: - html = html + "<tr bgcolor = \"E8E7F2\">" - bgcolor = 0 - html = html + "<th>" + test_case + "</th>" - html = html + "<th>" + case_status[test_case] + "</th>" - html = html + "</tr>" - - html = html + "</table>" - html = html + "<p></p>" - html = html + "<font>Detail log :</font>" - #TODO update the link address for log.zip - html = html + "<a href=\"" + THIS_TEST + "/log.zip" + "\">log.zip</a>" - html = html + "</body>" - html = html + "</html>" - - return html - def write_to_html_file(THIS_TEST,html): html_path = conf.get_html_filename(THIS_TEST) html_file = open(html_path,"w") @@ -162,6 +111,11 @@ def write_to_html_file(THIS_TEST,html): html_file.close() def create_gen_web_page(filename, tlpname, html_data): + #Get timestamp + date_F = subprocess.getoutput("date +%F") + html_data["date_F"] = date_F + date_T = subprocess.getoutput("date +%T") + html_data["date_T"] = date_T # here, jinja2 module should be installed first from jinja2 import Environment,FileSystemLoader env = Environment(loader=FileSystemLoader(conf.get_tpl_dir())) @@ -190,38 +144,37 @@ def change_json_to_html(test_set_name): json_file = conf.get_json_filename(test_set_name) html_file = conf.get_html_filename(test_set_name) #read data from json file - html_data = dict() + summary_data = dict() with open(json_file,'r') as f: - html_data = json.load(f) + summary_data = json.load(f) f.close() #format json data to html data - html_data["case_status_html"] = format_case_status_table(html_data["case_status"]) + html_data = format_html_data(summary_data) #save data to html file write_data_to_file(html_data, "html") -def format_case_status_table(case_status): - html_data = "" - #init table title - bgcolor = conf.BGCOLOR_TABLE_TITLE - color = conf.COLOR_TABLE_TITLE - html_data += "\t<tr bgcolor = \"" + bgcolor + "\">\n" - html_data += "\t\t<th><font color = \"" + color + "\"> test case </font></th>\n" - html_data += "\t\t<th><font color = \"" + color + "\"> status </font></th>\n" - html_data += "\t</tr>\n" - +#def format_case_status_table(case_status): +def format_html_data(summary_data): #init all rows - bgcolor = conf.BGCOLOR_DARK + case_status = summary_data["case_status"] + html_data = "" for key in case_status: - if ( bgcolor == conf.BGCOLOR_DARK ): - html_data += "\t<tr bgcolor = \"" + bgcolor + "\">\n" - bgcolor = conf.BGCOLOR_LIGHT - else: - html_data += "\t<tr bgcolor = \"" + bgcolor + "\">\n" - bgcolor = conf.BGCOLOR_DARK - html_data += "\t\t<th>" + key + "</th>\n" - html_data += "\t\t<th>" + case_status[key] + "</th>\n" - html_data += "\t</tr>\n" - return html_data - + html_data += "\t\t\t<tbody class=\"" + case_status[key] + "\">\n" + html_data += "\t\t\t\t<tr>\n" + html_data += "\t\t\t\t<td class=\"col-result\">" + html_data += str.capitalize(case_status[key]) +"</td>\n" + html_data += "\t\t\t\t<td>" + key + "</td>\n" + html_data += "\t\t\t\t</tr>\n" + html_data += "\t\t\t</tbody>\n" + summary_data["case_status_html"] = html_data + + #Create summry status in html + status_html = "" + status_html += "\t\t<p>test suite status : <span class=\"" + status_html += summary_data["test_status"] + "\">" + status_html += str.capitalize(summary_data["test_status"]) + "</span></p>" + summary_data["test_suite_status_html"] = status_html + + return summary_data |