diff options
-rw-r--r-- | conftest.py | 81 | ||||
-rw-r--r-- | plugins/agl_test_report.py | 107 | ||||
-rw-r--r-- | template/all_test_suites_tpl.html | 111 | ||||
-rw-r--r-- | template/summary_result_tpl.html | 112 |
4 files changed, 271 insertions, 140 deletions
diff --git a/conftest.py b/conftest.py index 0c42f66..fb89772 100644 --- a/conftest.py +++ b/conftest.py @@ -41,9 +41,17 @@ def setup_compress_function(): date = subprocess.getoutput('date +%Y%m%d') zip_name = "agl-test-log-" + version + '-' + machine_name + '-' + date - #Creat summary report in html - summary_html_data = format_test_suite_table(summary_data) + #Get summary_html_data + summary_html_data = format_html_data(summary_data) summary_html_data["log_zip_name"] = zip_name + + #Get timestamp + date_F = subprocess.getoutput("date +%F") + summary_html_data["date_F"] = date_F + date_T = subprocess.getoutput("date +%T") + summary_html_data["date_T"] = date_T + + #Creat summary report in html env = Environment(loader=FileSystemLoader(conf.get_tpl_dir())) template = env.get_template("all_test_suites_tpl.html") html_path = conf.TMP_LOGS_DIR + "test-report/summary-report.html" @@ -115,49 +123,50 @@ def get_summary_data(report_files): status = "" if (summary_data["summary"]["summary_total"] == summary_data["summary"]["summary_skipped"]): - status = "skip" + status = "skipped" elif (summary_data["summary"]["summary_failed"] == 0): - status = "pass" + status = "passed" else: - status = "fail" + status = "failed" summary_data["summary"]["status"] = status return summary_data -def format_test_suite_table(summary_data): +def format_html_data(summary_data): 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 suite </font></th>\n" - html_data += "\t\t<th><font color = \"" + color + "\"> status </font></th>\n" - html_data += "\t\t<th><font color = \"" + color + "\"> total </font></th>\n" - html_data += "\t\t<th><font color = \"" + color + "\"> pass </font></th>\n" - html_data += "\t\t<th><font color = \"" + color + "\"> xpass </font></th>\n" - html_data += "\t\t<th><font color = \"" + color + "\"> fail </font></th>\n" - html_data += "\t\t<th><font color = \"" + color + "\"> xfail </font></th>\n" - html_data += "\t\t<th><font color = \"" + color + "\"> skip </font></th>\n" - html_data += "\t</tr>\n" - #init all rows - bgcolor = conf.BGCOLOR_DARK for key in summary_data: if(key != "summary"): - html_data += "\t<tr bgcolor = \"" + bgcolor + "\">\n" - html_data += "\t\t<th>" + key + "</th>\n" - html_data += "\t\t<th>" + summary_data[key]["test_status"] + "</th>\n" - html_data += "\t\t<th>" + str(summary_data[key]["total"]) + "</th>\n" - html_data += "\t\t<th>" + str(summary_data[key]["passed"]) + "</th>\n" - html_data += "\t\t<th>" + str(summary_data[key]["xpassed"]) + "</th>\n" - html_data += "\t\t<th>" + str(summary_data[key]["failed"]) + "</th>\n" - html_data += "\t\t<th>" + str(summary_data[key]["xfailed"]) + "</th>\n" - html_data += "\t\t<th>" + str(summary_data[key]["skipped"]) + "</th>\n" - html_data += "\t</tr>\n" - - if (bgcolor == conf.BGCOLOR_DARK): - bgcolor = conf.BGCOLOR_LIGHT - else: - bgcolor = conf.BGCOLOR_DARK + html_data += "\t\t\t<tbody class=\"" + html_data += summary_data[key]["test_status"] + "\">\n" + html_data += "\t\t\t\t<tr>\n" + html_data += "\t\t\t\t<td class=\"col-result\">" + html_data += str.capitalize(summary_data[key]["test_status"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + key + "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["total"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["passed"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["skipped"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["failed"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["xfailed"]) + html_data += "</td>\n" + html_data += "\t\t\t\t<td>" + str(summary_data[key]["xpassed"]) + html_data += "</td>\n" + html_data += "\t\t\t\t</tr>\n" + html_data += "\t\t\t</tbody>\n" + summary_data["test_suite_table_html"] = html_data + + #Create summry status in html + summry_status_html = "" + summry_status_html += "\t\t<p>test suite status : <span class=\"" + summry_status_html += summary_data["summary"]["status"] + "\">" + summry_status_html += str.capitalize(summary_data["summary"]["status"]) + summry_status_html += "</span></p>" + summary_data["summry_status_html"] = summry_status_html + return summary_data 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 diff --git a/template/all_test_suites_tpl.html b/template/all_test_suites_tpl.html index 5b3e0aa..f484385 100644 --- a/template/all_test_suites_tpl.html +++ b/template/all_test_suites_tpl.html @@ -1,17 +1,102 @@ <!DOCTYPE html> <html> - <head> - <title> Summary Report </title> - </head> - <body> - <h1> Summary Report </h1> - <li> Status : {{ data.summary.status }} </li> - <li> Total : {{ data.summary.summary_total }} Pass : {{ data.summary.summary_passed }} Fail : {{ data.summary.summary_failed }} Skip : {{ data.summary.summary_skipped }} </li> - <li> Details : </li> - <table border="1" cellspacing="2"> + <head> + <meta charset="utf-8"/> + <title>Summary Report</title> + <style>body { + font-family: Helvetica, Arial, sans-serif; + font-size: 12px; + min-width: 800px; + color: #999; +} + +h1 { + font-size: 24px; + color: black; +} + +h2 { + font-size: 16px; + color: black; +} + +p { + color: black; +} + +a { + color: #999; +} + +table { + border-collapse: collapse; +} + +/****************************** + * TEST RESULT COLORS + ******************************/ +span.passed, +.passed .col-result { + color: green; +} + +span.skipped, +.skipped .col-result { + color: orange; +} + +span.failed, +.failed .col-result { + color: red; +} + +/****************************** + * RESULTS TABLE + * Table Layout + ******************************/ +#results-table { + border: 1px solid #e6e6e6; + color: #666; + font-size: 12px; + width: 50%; +} +#results-table th, +#results-table td { + padding: 5px; + border: 1px solid #E6E6E6; + text-align: left; +} +#results-table th { + font-weight: bold; +} + + </style> + </head> + + <body> + <h1>Summary Report</h1> + <p>Report generated on {{ data.date_F }} at {{ data.date_T }} by <a href="https://git.automotivelinux.org/src/agl-test-framework/">agl-test-framework</a> </p> + <h2>Summary</h2> +{{ data.summry_status_html }} + <p>{{ data.summary.summary_total }} test suites ran </p> + <span class="passed">{{ data.summary.summary_passed }} passed</span>, + <span class="skipped">{{ data.summary.summary_skipped }} skipped</span>, + <span class="failed">{{ data.summary.summary_failed }} failed</span>, + <h2>Details</h2> + <table id="results-table"> + <thead> + <tr> + <th>Result</th> + <th>Test Suite</th> + <th>Total</th> + <th>Pass</th> + <th>Skip</th> + <th>Fail</th> + <th>Xfail</th> + <th>Xpass</th> + </tr> + </thead> {{ data.test_suite_table_html }} - </table> - <p></p> - <li>Detail log : {{ data.log_zip_name }}.zip</li> - </body> + </table> + </body> </html> diff --git a/template/summary_result_tpl.html b/template/summary_result_tpl.html index 6b173cf..c8f0f99 100644 --- a/template/summary_result_tpl.html +++ b/template/summary_result_tpl.html @@ -1,18 +1,102 @@ <!DOCTYPE html> <html> - <head> - <title>{{ data.test_name }} test report</title> - </head> - <body> - <h1> {{ data.test_name }} test report </h1> - <li> Status : {{ data.test_status }} </li> - <li> Total : {{ data.collected }} Pass : {{ data.passed }} Xpass : {{ data.xpassed }} Fail : {{ data.failed }} Xfail : {{ data.xfailed }} Skip : {{ data.skipped }} </li> - <li> Details : </li> - <table border="1" cellspacing="2"> + <head> + <meta charset="utf-8"/> + <title>{{ data.test_name }} test report</title> + <style>body { + font-family: Helvetica, Arial, sans-serif; + font-size: 12px; + min-width: 800px; + color: #999; +} + +h1 { + font-size: 24px; + color: black; +} + +h2 { + font-size: 16px; + color: black; +} + +p { + color: black; +} + +a { + color: #999; +} + +table { + border-collapse: collapse; +} + +/****************************** + * TEST RESULT COLORS + ******************************/ +span.passed, +.passed .col-result { + color: green; +} + +span.skipped, +span.xfailed, +span.xpassed, +.skipped .col-result, +.xfailed .col-result, +.xpassed .col-result { + color: orange; +} + +span.failed, +.failed .col-result { + color: red; +} + +/****************************** + * RESULTS TABLE + * Table Layout + ******************************/ +#results-table { + border: 1px solid #e6e6e6; + color: #666; + font-size: 12px; + width: 50%; +} +#results-table th, +#results-table td { + padding: 5px; + border: 1px solid #E6E6E6; + text-align: left; +} +#results-table th { + font-weight: bold; +} + + </style> + </head> + + <body> + <h1>{{ data.test_name }} test report</h1> + <p>Report generated on {{ data.date_F }} at {{ data.date_T }} by <a href="https://git.automotivelinux.org/src/agl-test-framework/">agl-test-framework</a> </p> + <h2>Summary</h2> +{{ data.test_suite_status_html }} + <p>{{ data.collected }} test cases ran </p> + <span class="passed">{{ data.passed }} passed</span>, + <span class="skipped">{{ data.skipped }} skipped</span>, + <span class="failed">{{ data.failed }} failed</span>, + <span class="xfailed">{{ data.xfailed }} expected failures</span>, + <span class="xpassed">{{ data.xpassed }} unexpected passes</span> + <h2>Details</h2> + <table id="results-table"> + <thead> + <tr> + <th>Result</th> + <th>Test Case</th> + </tr> + </thead> {{ data.case_status_html }} - </table> - <p></p> - <li>Detail log : {{ data.test_name }}/log.zip</li> - </body> + </table> + </body> </html> - |