chiptools.testing.custom_runners.HTMLTestRunner module
A TestRunner for use with the Python unit testing framework. It generates a HTML report to show the result at a glance.
The simplest way to use this is to invoke its main method. E.g.:
import unittest
import HTMLTestRunner
... define your tests ...
if __name__ == '__main__':
HTMLTestRunner.main()
For more customization options, instantiates a HTMLTestRunner object. HTMLTestRunner is a counterpart to unittest’s TextTestRunner. E.g.:
# output to a file
fp = file('my_report.html', 'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title='My unit test',
description='This demonstrates the report output by HTMLTestRunner.'
)
# Use an external stylesheet.
# See the Template_mixin class for more customizable options
runner.STYLESHEET_TMPL = '<link rel="stylesheet" href="my_stylesheet.css" type="text/css">'
# run the test
runner.run(my_test_suite)
- class chiptools.testing.custom_runners.HTMLTestRunner.HTMLTestRunner(stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, verbosity=1, title=None, description=None)[source]
Bases:
chiptools.testing.custom_runners.HTMLTestRunner.Template_mixin
- class chiptools.testing.custom_runners.HTMLTestRunner.OutputRedirector(fp)[source]
Bases:
object
Wrapper to redirect stdout or stderr
- class chiptools.testing.custom_runners.HTMLTestRunner.Template_mixin[source]
Bases:
object
Define a HTML template for report customerization and generation.
Overall structure of an HTML report:
HTML +------------------------+ |<html> | | <head> | | | | STYLESHEET | | +----------------+ | | | | | | +----------------+ | | | | </head> | | | | <body> | | | | HEADING | | +----------------+ | | | | | | +----------------+ | | | | REPORT | | +----------------+ | | | | | | +----------------+ | | | | ENDING | | +----------------+ | | | | | | +----------------+ | | | | </body> | |</html> | +------------------------+
- DEFAULT_DESCRIPTION = ''
- DEFAULT_TITLE = 'Unit Test Report'
- ENDING_TMPL = "<div id='ending'> </div>"
- HEADING_ATTRIBUTE_TMPL = "<p class='attribute'><strong>%(name)s:</strong> %(value)s</p>\n"
- HEADING_TMPL = "<div class='heading'>\n<h1>%(title)s</h1>\n%(parameters)s\n<p class='description'>%(description)s</p>\n</div>\n\n"
- HTML_TMPL = '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n <title>%(title)s</title>\n <meta name="generator" content="%(generator)s"/>\n <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n %(stylesheet)s\n</head>\n<body>\n<script language="javascript" type="text/javascript"><!--\noutput_list = Array();\n\n/* level - 0:Summary; 1:Failed; 2:All */\nfunction showCase(level) {\n trs = document.getElementsByTagName("tr");\n for (var i = 0; i < trs.length; i++) {\n tr = trs[i];\n id = tr.id;\n if (id.substr(0,2) == \'ft\') {\n if (level < 1) {\n tr.className = \'hiddenRow\';\n }\n else {\n tr.className = \'\';\n }\n }\n if (id.substr(0,2) == \'pt\') {\n if (level > 1) {\n tr.className = \'\';\n }\n else {\n tr.className = \'hiddenRow\';\n }\n }\n }\n}\n\n\nfunction showClassDetail(cid, count) {\n var id_list = Array(count);\n var toHide = 1;\n for (var i = 0; i < count; i++) {\n tid0 = \'t\' + cid.substr(1) + \'.\' + (i+1);\n tid = \'f\' + tid0;\n tr = document.getElementById(tid);\n if (!tr) {\n tid = \'p\' + tid0;\n tr = document.getElementById(tid);\n }\n id_list[i] = tid;\n if (tr.className) {\n toHide = 0;\n }\n }\n for (var i = 0; i < count; i++) {\n tid = id_list[i];\n if (toHide) {\n document.getElementById(\'div_\'+tid).style.display = \'none\'\n document.getElementById(tid).className = \'hiddenRow\';\n }\n else {\n document.getElementById(tid).className = \'\';\n }\n }\n}\n\n\nfunction showTestDetail(div_id){\n var details_div = document.getElementById(div_id)\n var displayState = details_div.style.display\n // alert(displayState)\n if (displayState != \'block\' ) {\n displayState = \'block\'\n details_div.style.display = \'block\'\n }\n else {\n details_div.style.display = \'none\'\n }\n}\n\n\nfunction html_escape(s) {\n s = s.replace(/&/g,\'&\');\n s = s.replace(/</g,\'<\');\n s = s.replace(/>/g,\'>\');\n return s;\n}\n\n/* obsoleted by detail in <div>\nfunction showOutput(id, name) {\n var w = window.open("", //url\n name,\n "resizable,scrollbars,status,width=800,height=450");\n d = w.document;\n d.write("<pre>");\n d.write(html_escape(output_list[id]));\n d.write("\\n");\n d.write("<a href=\'javascript:window.close()\'>close</a>\\n");\n d.write("</pre>\\n");\n d.close();\n}\n*/\n--></script>\n\n%(heading)s\n%(report)s\n%(ending)s\n\n</body>\n</html>\n'
- REPORT_CLASS_TMPL = '\n<tr class=\'%(style)s\'>\n <td>%(desc)s</td>\n <td>%(count)s</td>\n <td>%(Pass)s</td>\n <td>%(fail)s</td>\n <td>%(error)s</td>\n <td><a href="javascript:showClassDetail(\'%(cid)s\',%(count)s)">Detail</a></td>\n</tr>\n'
- REPORT_TEST_NO_OUTPUT_TMPL = "\n<tr id='%(tid)s' class='%(Class)s'>\n <td class='%(style)s'><div class='testcase'>%(desc)s</div></td>\n <td colspan='5' align='center'>%(status)s</td>\n</tr>\n"
- REPORT_TEST_OUTPUT_TMPL = '\n%(id)s: %(output)s\n'
- REPORT_TEST_WITH_OUTPUT_TMPL = '\n<tr id=\'%(tid)s\' class=\'%(Class)s\'>\n <td class=\'%(style)s\'><div class=\'testcase\'>%(desc)s</div></td>\n <td colspan=\'5\' align=\'center\'>\n\n <!--css div popup start-->\n <a class="popup_link" onfocus=\'this.blur();\' href="javascript:showTestDetail(\'div_%(tid)s\')" >\n %(status)s</a>\n\n <div id=\'div_%(tid)s\' class="popup_window">\n <div style=\'text-align: right; color:red;cursor:pointer\'>\n <a onfocus=\'this.blur();\' onclick="document.getElementById(\'div_%(tid)s\').style.display = \'none\' " >\n [x]</a>\n </div>\n <pre>\n %(script)s\n </pre>\n </div>\n <!--css div popup end-->\n\n </td>\n</tr>\n'
- REPORT_TMPL = "\n<p id='show_detail_line'>Show\n<a href='javascript:showCase(0)'>Summary</a>\n<a href='javascript:showCase(1)'>Failed</a>\n<a href='javascript:showCase(2)'>All</a>\n</p>\n<table id='result_table'>\n<colgroup>\n<col align='left' />\n<col align='right' />\n<col align='right' />\n<col align='right' />\n<col align='right' />\n<col align='right' />\n</colgroup>\n<tr id='header_row'>\n <td>Test Group/Test case</td>\n <td>Count</td>\n <td>Pass</td>\n <td>Fail</td>\n <td>Error</td>\n <td>View</td>\n</tr>\n%(test_list)s\n<tr id='total_row'>\n <td>Total</td>\n <td>%(count)s</td>\n <td>%(Pass)s</td>\n <td>%(fail)s</td>\n <td>%(error)s</td>\n <td> </td>\n</tr>\n</table>\n"
- STATUS = {0: 'pass', 1: 'fail', 2: 'error'}
- STYLESHEET_TMPL = '\n<style type="text/css" media="screen">\nbody { font-family: verdana, arial, helvetica, sans-serif; font-size: 80%; }\ntable { font-size: 100%; }\npre { }\n\n/* -- heading ---------------------------------------------------------------------- */\nh1 {\n font-size: 16pt;\n color: gray;\n}\n.heading {\n margin-top: 0ex;\n margin-bottom: 1ex;\n}\n\n.heading .attribute {\n margin-top: 1ex;\n margin-bottom: 0;\n}\n\n.heading .description {\n margin-top: 4ex;\n margin-bottom: 6ex;\n}\n\n/* -- css div popup ------------------------------------------------------------------------ */\na.popup_link {\n}\n\na.popup_link:hover {\n color: red;\n}\n\n.popup_window {\n display: none;\n position: relative;\n left: 0px;\n top: 0px;\n /*border: solid #627173 1px; */\n padding: 10px;\n background-color: #E6E6D6;\n font-family: "Lucida Console", "Courier New", Courier, monospace;\n text-align: left;\n font-size: 8pt;\n width: 500px;\n}\n\n}\n/* -- report ------------------------------------------------------------------------ */\n#show_detail_line {\n margin-top: 3ex;\n margin-bottom: 1ex;\n}\n#result_table {\n width: 80%;\n border-collapse: collapse;\n border: 1px solid #777;\n}\n#header_row {\n font-weight: bold;\n color: white;\n background-color: #777;\n}\n#result_table td {\n border: 1px solid #777;\n padding: 2px;\n}\n#total_row { font-weight: bold; }\n.passClass { background-color: #6c6; }\n.failClass { background-color: #c60; }\n.errorClass { background-color: #c00; }\n.passCase { color: #6c6; }\n.failCase { color: #c60; font-weight: bold; }\n.errorCase { color: #c00; font-weight: bold; }\n.hiddenRow { display: none; }\n.testcase { margin-left: 2em; }\n\n\n/* -- ending ---------------------------------------------------------------------- */\n#ending {\n}\n\n</style>\n'
- class chiptools.testing.custom_runners.HTMLTestRunner.TestProgram(module='__main__', defaultTest=None, argv=None, testRunner=None, testLoader=<unittest.loader.TestLoader object>, exit=True, verbosity=1, failfast=None, catchbreak=None, buffer=None, warnings=None, *, tb_locals=False)[source]
Bases:
unittest.main.TestProgram
A variation of the unittest.TestProgram. Please refer to the base class for command line parameters.
- chiptools.testing.custom_runners.HTMLTestRunner.main
alias of
chiptools.testing.custom_runners.HTMLTestRunner.TestProgram