From c39ff078a4820ab1e09e7600646adce52445382f Mon Sep 17 00:00:00 2001 From: walidsi <42148514+walidsi@users.noreply.github.com> Date: Sat, 19 Nov 2022 07:22:24 +0200 Subject: [PATCH 1/4] fix: Updated to work with python 3.11 --- HTMLTestRunner.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/HTMLTestRunner.py b/HTMLTestRunner.py index 8d60600..3536bdf 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 @@ -639,7 +639,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 +650,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 +695,7 @@ def generateReport(self, test, result): report = report, ending = ending, ) - self.stream.write(output.encode('utf8')) + self.stream.write(output) def _generate_stylesheet(self): @@ -774,13 +774,13 @@ 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 = e else: ue = e From 4049f705c36688f71d5b45848bc28c21bd8dd5c1 Mon Sep 17 00:00:00 2001 From: walidsi <42148514+walidsi@users.noreply.github.com> Date: Sat, 19 Nov 2022 07:34:53 +0200 Subject: [PATCH 2/4] feat: Added handling for subTests --- HTMLTestRunner.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/HTMLTestRunner.py b/HTMLTestRunner.py index 3536bdf..f2d6b52 100644 --- a/HTMLTestRunner.py +++ b/HTMLTestRunner.py @@ -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 From d65227164305d276e5b873575bc7dd12820585a2 Mon Sep 17 00:00:00 2001 From: walidsi <42148514+walidsi@users.noreply.github.com> Date: Sat, 19 Nov 2022 07:39:56 +0200 Subject: [PATCH 3/4] feat: Added test case class name to subtest section in report --- HTMLTestRunner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HTMLTestRunner.py b/HTMLTestRunner.py index f2d6b52..81fc5bf 100644 --- a/HTMLTestRunner.py +++ b/HTMLTestRunner.py @@ -740,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 From 48ac68268088f2df0e5b8bde8c8bfe4889a5b413 Mon Sep 17 00:00:00 2001 From: walidsi <42148514+walidsi@users.noreply.github.com> Date: Sat, 19 Nov 2022 13:27:27 +0200 Subject: [PATCH 4/4] feat: feat: Stripped test case file path to just file name Stripped test case file path to just file name for better looking html assertion error message --- HTMLTestRunner.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/HTMLTestRunner.py b/HTMLTestRunner.py index 81fc5bf..5eadf24 100644 --- a/HTMLTestRunner.py +++ b/HTMLTestRunner.py @@ -767,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 @@ -787,9 +819,9 @@ def _generate_report_test(self, rows, cid, tid, n, t, o, e): 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 + ue = self.strip_file_path(e) else: - ue = e + ue = self.strip_file_path(e) script = self.REPORT_TEST_OUTPUT_TMPL % dict( id = tid,