admin 管理员组

文章数量: 1184232


2024年3月6日发(作者:eclipse创建类快捷键)

__version__ = "0.8.2""""Change HistoryVersion 0.8.2* Show output inline instead of popup window (Viorel Lupu).Version in 0.8.1* Validated XHTML (Wolfgang Borgert).* Added description of test classes and test n in 0.8.0* Define Template_mixin class for customization.* Workaround a IE 6 bug that it does not treat %(heading)s%(report)s%(ending)s""" # variables: (title, generator, stylesheet, heading, report, ending) # ------------------------------------------------------------------------ # Stylesheet # # alternatively use a for external style sheet, e.g. # STYLESHEET_TMPL = """""" # ------------------------------------------------------------------------ # Heading # HEADING_TMPL = """

%(title)s

%(parameters)s

%(description)s

""" # variables: (title, parameters, description) HEADING_ATTRIBUTE_TMPL = """

%(name)s: %(value)s

""" # variables: (name, value) # ------------------------------------------------------------------------ # Report # REPORT_TMPL = """

ShowSummaryFailedAll

%(test_list)s
Test Group/Test case Count Pass Fail Error View
Total %(count)s %(Pass)s %(fail)s %(error)s  
""" # variables: (test_list, count, Pass, fail, error) REPORT_CLASS_TMPL = r""" %(desc)s %(count)s %(Pass)s %(fail)s %(error)s Detail""" # variables: (style, desc, count, Pass, fail, error, cid) REPORT_TEST_WITH_OUTPUT_TMPL = r"""
%(desc)s
%(status)s """ # variables: (tid, Class, style, desc, status)

REPORT_TEST_NO_OUTPUT_TMPL = r"""

%(desc)s
%(status)s""" # variables: (tid, Class, style, desc, status) REPORT_TEST_OUTPUT_TMPL = r"""%(id)s: %(output)s""" # variables: (id, output) # ------------------------------------------------------------------------ # ENDING # ENDING_TMPL = """
 
"""# -------------------- The end of the Template class -------------------TestResult = sultclass _TestResult(TestResult): # note: _TestResult is a pure representation of results. # It lacks the output and reporting ability compares to unittest._TextTestResult. def __init__(self, verbosity=1): TestResult.__init__(self) 0 = None 0 = None s_count = 0 e_count = 0 _count = 0 ity = verbosity # result is a list of result in 4 tuple # ( # result code (0: success; 1: fail; 2: error), # TestCase object, # Test output (byte string), # stack trace, # ) = [] def startTest(self, test): est(self, test) # just one buffer for both stdout and stderr # 2.7版本为 Buffer = IO() Buffer = IO() stdout_ = Buffer stderr_ = Buffer 0 = 0 = = stdout_redirector = stderr_redirector def complete_output(self): """ Disconnect output redirection and return buffer. Safe to call multiple times. """ if 0: = 0 = 0 0 = None 0 = None return ue() def stopTest(self, test): # Usually one of addSuccess, addError or addFailure would have been called. # But there are some path in unittest that would bypass this. # We must disconnect stdout in stopTest(), which is guaranteed to be called. te_output() def addSuccess(self, test): s_count += 1

cess(self, test) output = te_output() ((0, test, output, '')) if ity > 1: ('ok ') (str(test)) ('n') else: ('.') def addError(self, test, err): _count += 1 or(self, test, err) _, _exc_str = [-1] output = te_output() ((2, test, output, _exc_str)) if ity > 1: ('E ') (str(test)) ('n') else: ('E') def addFailure(self, test, err): e_count += 1 lure(self, test, err) _, _exc_str = es[-1] output = te_output() ((1, test, output, _exc_str)) if ity > 1: ('F ') (str(test)) ('n') else: ('F')class HTMLTestRunner(Template_mixin): """ """ def __init__(self, stream=, verbosity=1, title=None, description=None): = stream ity = verbosity if title is None: = T_TITLE else: = title if description is None: ption = T_DESCRIPTION else: ption = description ime = () def run(self, test): "Run the given test case or test suite." result = _TestResult(ity) test(result) me = () teReport(test, result) print(,'nTime Elapsed=%s' %(ime)) #2.7版本 print >>, 'nTime Elapsed: %s' % (ime) return result def sortResult(self, result_list): # unittest does not seems to run in any particular order. # Here at least we want to group them together by class. rmap = {} classes = [] for n,t,o,e in result_list: cls = t.__class__ # 2.7版本 if not _key(cls) if not cls in rmap: rmap[cls] = [] (cls) rmap[cls].append((n,t,o,e)) r = [(cls, rmap[cls]) for cls in classes] return r def getReportAttributes(self, result):

""" Return report attributes as a list of (name, value). Override this to add custom attributes. """ startTime = str(ime)[:19] duration = str(me - ime) status = [] if s_count: ('Pass %s' % s_count) if e_count: ('Failure %s' % e_count) if _count: ('Error %s' % _count ) if status: status = ' '.join(status) else: status = 'none' return [ ('Start Time', startTime), ('Duration', duration), ('Status', status), ] def generateReport(self, test, result): report_attrs = ortAttributes(result) generator = 'HTMLTestRunner %s' % __version__ stylesheet = self._generate_stylesheet() heading = self._generate_heading(report_attrs) report = self._generate_report(result) ending = self._generate_ending() output = _TMPL % dict( title = (), generator = generator, stylesheet = stylesheet, heading = heading, report = report, ending = ending, ) (('utf8')) def _generate_stylesheet(self): return HEET_TMPL def _generate_heading(self, report_attrs): a_lines = [] for name, value in report_attrs: line = G_ATTRIBUTE_TMPL % dict( name = (name), value = (value), ) a_(line) heading = G_TMPL % dict( title = (), parameters = ''.join(a_lines), description = (ption), ) return heading def _generate_report(self, result): rows = [] sortedResult = sult() for cid, (cls, cls_results) in enumerate(sortedResult): # subtotal for a class np = nf = ne = 0 for n,t,o,e in cls_results: if n == 0: np += 1 elif n == 1: nf += 1 else: ne += 1 # format class description if cls.__module__ == "__main__": name = cls.__name__ else: name = "%s.%s" % (cls.__module__, cls.__name__) doc = cls.__doc__ and cls.__doc__.split("n")[0] or "" desc = doc and '%s: %s' % (name, doc) or name row = _CLASS_TMPL % dict( style = ne > 0 and 'errorClass' or nf > 0 and 'failClass' or 'passClass', desc = desc, count = np+nf+ne, Pass = np, fail = nf,

error = ne, cid = 'c%s' % (cid+1), ) (row) for tid, (n,t,o,e) in enumerate(cls_results): self._generate_report_test(rows, cid, tid, n, t, o, e) report = _TMPL % dict( test_list = ''.join(rows), count = str(s_count+e_count+_count), Pass = str(s_count), fail = str(e_count), error = str(_count), ) return report def _generate_report_test(self, rows, cid, tid, n, t, o, e): # e.g. 'pt1.1', 'ft1.1', etc has_output = bool(o or e) tid = (n == 0 and 'p' or 'f') + 't%s.%s' % (cid+1,tid+1) name = ().split('.')[-1] doc = escription() or "" desc = doc and ('%s: %s' % (name, doc)) or name tmpl = has_output and _TEST_WITH_OUTPUT_TMPL or _TEST_NO_OUTPUT_TMPL # o and e should be byte string because they are collected from stdout and stderr? if isinstance(o,str): uo = e # TODO: some problem with 'string_escape': it escape n and mess up formating # uo = unicode(('string_escape')) # 2.7版本uo = ('latin-1') else: uo = o if isinstance(e,str): ue = e # TODO: some problem with 'string_escape': it escape n and mess up formating # ue = unicode(('string_escape')) # 2.7 版本 ue = ('latin-1') else: ue = e script = _TEST_OUTPUT_TMPL % dict( id = tid, output = (uo+ue), ) row = tmpl % dict( tid = tid, Class = (n == 0 and 'hiddenRow' or 'none'), style = n == 2 and 'errorCase' or (n == 1 and 'failCase' or 'none'), desc = desc, script = script, status = [n], ) (row) if not has_output: return def _generate_ending(self): return _TMPL############################################################################### Facilities for running tests from the command line############################################################################### Note: Reuse ogram to launch test. In the future we may# build our own launcher to support more specific command line# parameters like test title, CSS, TestProgram(ogram): """ A variation of the ogram. Please refer to the base class for command line parameters. """ def runTests(self): # Pick HTMLTestRunner as the default test runner. # base class's testRunner parameter is not useful because it means # we have to instantiate HTMLTestRunner before we know ity. if nner is None: nner = HTMLTestRunner(verbosity=ity) ts(self)


本文标签: 创建 快捷键 作者