diff --git a/HTMLTestRunner.py b/HTMLTestRunner.py index 8d60600..5eadf24 100644 --- a/HTMLTestRunner.py +++ b/HTMLTestRunner.py @@ -94,7 +94,7 @@ # TODO: simplify javascript using ,ore than 1 class in the class attribute? import datetime -import StringIO +from io import StringIO import sys import time import unittest @@ -527,7 +527,7 @@ class _TestResult(TestResult): def __init__(self, verbosity=1): TestResult.__init__(self) - self.outputBuffer = StringIO.StringIO() + self.outputBuffer = StringIO() self.stdout0 = None self.stderr0 = None self.success_count = 0 @@ -575,6 +575,13 @@ def stopTest(self, test): # We must disconnect stdout in stopTest(), which is guaranteed to be called. self.complete_output() + def addSubTest(self, test, subtest, err): + if err is not None: + self.addFailure(subtest, err) + else: + self.addSuccess(subtest) + super(_TestResult, self).addSubTest(test, subtest, err) + def addSuccess(self, test): self.success_count += 1 @@ -639,7 +646,7 @@ def run(self, test): test(result) self.stopTime = datetime.datetime.now() self.generateReport(test, result) - print >>sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime) + print('\nTime Elapsed: %s' % (self.stopTime-self.startTime), file = sys.stderr) return result @@ -650,7 +657,7 @@ def sortResult(self, result_list): classes = [] for n,t,o,e in result_list: cls = t.__class__ - if not rmap.has_key(cls): + if cls not in rmap: rmap[cls] = [] classes.append(cls) rmap[cls].append((n,t,o,e)) @@ -695,7 +702,7 @@ def generateReport(self, test, result): report = report, ending = ending, ) - self.stream.write(output.encode('utf8')) + self.stream.write(output) def _generate_stylesheet(self): @@ -733,7 +740,7 @@ def _generate_report(self, result): if cls.__module__ == "__main__": name = cls.__name__ else: - name = "%s.%s" % (cls.__module__, cls.__name__) + name = "%s.%s.%s" % (desc, cls.__module__, cls.__name__) doc = cls.__doc__ and cls.__doc__.split("\n")[0] or "" desc = doc and '%s: %s' % (name, doc) or name @@ -760,6 +767,38 @@ def _generate_report(self, result): ) return report + def strip_file_path(self, e: str): + n = len(e) + + i = 0 + se = '' + + found_dq = False + + while i < n: + if e[i] != '"': + se = se + e[i] + i += 1 + else: + se = se + e[i] + if not found_dq: + found_dq = True + j = i + 1 + while j < n: + if e[j] != '"': + j += 1 + else: + # Backtrack to start of file name: + while j > i: + if e[j] != '\\': + j -= 1 + else: + i = j + break + break + i += 1 + + return se def _generate_report_test(self, rows, cid, tid, n, t, o, e): # e.g. 'pt1.1', 'ft1.1', etc @@ -774,15 +813,15 @@ def _generate_report_test(self, rows, cid, tid, n, t, o, e): if isinstance(o,str): # TODO: some problem with 'string_escape': it escape \n and mess up formating # uo = unicode(o.encode('string_escape')) - uo = o.decode('latin-1') + uo = o else: uo = o if isinstance(e,str): # TODO: some problem with 'string_escape': it escape \n and mess up formating # ue = unicode(e.encode('string_escape')) - ue = e.decode('latin-1') + ue = self.strip_file_path(e) else: - ue = e + ue = self.strip_file_path(e) script = self.REPORT_TEST_OUTPUT_TMPL % dict( id = tid,