[PATCH] D143516: [lit] [PATCH 1/2] Specify a common interface in a common base class for all report types

Greg Bedwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 7 10:11:02 PST 2023


gbedwell created this revision.
gbedwell added reviewers: yln, haowei.
Herald added a subscriber: delcypher.
Herald added a project: All.
gbedwell requested review of this revision.
Herald added a project: LLVM.

This is just a simple NFCI refactor in preparation for [PATCH 2/2]


https://reviews.llvm.org/D143516

Files:
  llvm/utils/lit/lit/reports.py


Index: llvm/utils/lit/lit/reports.py
===================================================================
--- llvm/utils/lit/lit/reports.py
+++ llvm/utils/lit/lit/reports.py
@@ -1,3 +1,4 @@
+import abc
 import base64
 import datetime
 import itertools
@@ -7,17 +8,24 @@
 
 import lit.Test
 
-
 def by_suite_and_test_path(test):
     # Suite names are not necessarily unique.  Include object identity in sort
     # key to avoid mixing tests of different suites.
     return (test.suite.name, id(test.suite), test.path_in_suite)
 
 
-class JsonReport(object):
+class _ReportBase(abc.ABC):
     def __init__(self, output_file):
         self.output_file = output_file
+        self.skipped_codes = {lit.Test.EXCLUDED,
+                              lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
+
+    @abc.abstractmethod
+    def write_results(self, tests, elapsed):
+        ...
 
+
+class JsonReport(_ReportBase):
     def write_results(self, tests, elapsed):
         unexecuted_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED}
         tests = [t for t in tests if t.result.code not in unexecuted_codes]
@@ -84,12 +92,7 @@
     return s.translate(_invalid_xml_chars_dict)
 
 
-class XunitReport(object):
-    def __init__(self, output_file):
-        self.output_file = output_file
-        self.skipped_codes = {lit.Test.EXCLUDED,
-                              lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
-
+class XunitReport(_ReportBase):
     def write_results(self, tests, elapsed):
         tests.sort(key=by_suite_and_test_path)
         tests_by_suite = itertools.groupby(tests, lambda t: t.suite)
@@ -191,10 +194,7 @@
     return test_data
 
 
-class ResultDBReport(object):
-    def __init__(self, output_file):
-        self.output_file = output_file
-
+class ResultDBReport(_ReportBase):
     def write_results(self, tests, elapsed):
         unexecuted_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED}
         tests = [t for t in tests if t.result.code not in unexecuted_codes]
@@ -239,13 +239,10 @@
             file.write('\n')
 
 
-class TimeTraceReport(object):
-    def __init__(self, output_file):
-        self.output_file = output_file
-        self.skipped_codes = {lit.Test.EXCLUDED,
-                              lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
-
+class TimeTraceReport(_ReportBase):
     def write_results(self, tests, elapsed):
+        del elapsed
+
         # Find when first test started so we can make start times relative.
         first_start_time = min([t.result.start for t in tests])
         events = [self._get_test_event(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143516.495579.patch
Type: text/x-patch
Size: 2556 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230207/a1c77416/attachment.bin>


More information about the llvm-commits mailing list