@@ -93,10 +93,6 @@ def from_args(cls, args, name, dest_prefix, test_count):
9393 if args .verbosity == 0 :
9494 return cls (test_count = test_count )
9595
96- @classmethod
97- def add_parser_arguments (self , parser , name , option_prefix , dest_prefix ):
98- pass
99-
10096 def get_test_description (self , test ):
10197 return get_test_description (test , descriptions = self .descriptions )
10298
@@ -111,36 +107,8 @@ def start_test_run(self):
111107
112108 def stop_test_run (self ):
113109 self .stop_time = time .time ()
114- self .print_errors ()
115110 self .print_summary ()
116111
117- def print_errors (self ):
118- """Print all errors and failures to the console.
119-
120- """
121- self .stream .writeln ()
122- self .print_error_list ('ERROR' , self .errors )
123- self .print_error_list ('FAIL' , self .failures )
124-
125- def print_error_list (self , error_kind , errors ):
126- """Print the list of errors or failures.
127-
128- Parameters
129- ----------
130- error_kind : str
131- ``'ERROR'`` or ``'FAIL'``
132- errors : list
133- List of :class:`~haas.result.TestResult`
134-
135- """
136- for result in errors :
137- self .stream .writeln (self .separator1 )
138- self .stream .writeln (
139- '%s: %s' % (error_kind , self .get_test_description (
140- result .test )))
141- self .stream .writeln (self .separator2 )
142- self .stream .writeln (result .exception )
143-
144112 def print_summary (self ):
145113 self .stream .writeln (self .separator2 )
146114 time_taken = self .stop_time - self .start_time
@@ -249,6 +217,116 @@ def __call__(self, result):
249217 self .stream .flush ()
250218
251219
220+ class ListSummaryHandler (IResultHandlerPlugin ):
221+
222+ _result_formats = {
223+ TestCompletionStatus .failure : 'FAIL' ,
224+ TestCompletionStatus .error : 'ERROR' ,
225+ TestCompletionStatus .unexpected_success : 'UNEXPECTED' ,
226+ TestCompletionStatus .expected_failure : 'EXPECTED' ,
227+ TestCompletionStatus .skipped : 'SKIPPED' ,
228+ }
229+
230+ def __init__ (
231+ self , list_skipped , list_expected_failures ,
232+ list_unexpected_successes ):
233+ self .enabled = True
234+ self .stream = _WritelnDecorator (sys .stderr )
235+ self ._collectors = collectors = {
236+ TestCompletionStatus .failure : [],
237+ TestCompletionStatus .error : [],
238+ }
239+ if list_skipped :
240+ collectors [TestCompletionStatus .skipped ] = []
241+ if list_expected_failures :
242+ collectors [TestCompletionStatus .expected_failure ] = []
243+ if list_unexpected_successes :
244+ collectors [TestCompletionStatus .unexpected_success ] = []
245+
246+ @classmethod
247+ def add_parser_arguments (cls , parser , name , option_prefix , dest_prefix ):
248+ parser .add_argument (
249+ '--report-skipped' , action = 'store' , type = bool ,
250+ metavar = 'REPORT_SKIPPED_TESTS' ,
251+ default = cls .OPTION_DEFAULT ,
252+ help = ('Report skipped tests' ))
253+ parser .add_argument (
254+ '--report-expected-failures' , action = 'store' , type = bool ,
255+ metavar = 'REPORT_EXPECTED_FAILURE_TESTS' ,
256+ default = cls .OPTION_DEFAULT ,
257+ help = ('Report expected failure tests' ))
258+ parser .add_argument (
259+ '--report-unexpected-success' , action = 'store' , type = bool ,
260+ metavar = 'REPORT_UNEXPECTED_SUCCESS_TESTS' ,
261+ default = cls .OPTION_DEFAULT ,
262+ help = ('Report unexpected success tests' ))
263+ parser .add_argument (
264+ '--report-all' , action = 'store' , type = bool ,
265+ metavar = 'REPORT_ALL_TESTS' ,
266+ default = cls .OPTION_DEFAULT ,
267+ help = ('Report list for all test types' ))
268+
269+ @classmethod
270+ def from_args (cls , args , name , dest_prefix , test_count ):
271+ return cls (
272+ args .list_skipped ,
273+ args .list_expected_failures ,
274+ args .list_unexpected_successes )
275+
276+ def start_test (self , test ):
277+ pass
278+
279+ def stop_test (self , test ):
280+ pass
281+
282+ def start_test_run (self ):
283+ pass
284+
285+ def stop_test_run (self ):
286+ self .print_list_summary (TestCompletionStatus .error )
287+ self .print_list_summary (TestCompletionStatus .failure )
288+ skipped = TestCompletionStatus .skipped
289+ expected = TestCompletionStatus .expected_failure
290+ unexpected = TestCompletionStatus .unexpected_success
291+ if unexpected in self ._collectors :
292+ self .print_list_summary (unexpected )
293+ if skipped in self ._collectors :
294+ self .print_list_summary (skipped )
295+ if expected in self ._collectors :
296+ self .print_list_summary (expected )
297+
298+ def print_list_summary (self , status ):
299+ """Print the list of tests of a given status.
300+
301+ Parameters
302+ ----------
303+ status : TestCompletionStatus
304+
305+ """
306+ results = self ._collectors [status ]
307+ template = self ._result_formats ['status' ] + ': %s'
308+ stream = self .stream
309+ raised_exception = status in (
310+ TestCompletionStatus .error , TestCompletionStatus .failure )
311+ if not raised_exception :
312+ stream .writeln (self .separator1 )
313+ for result in results :
314+ if raised_exception :
315+ stream .writeln (self .separator1 )
316+ stream .writeln (
317+ template % self .get_test_description (result .test ))
318+ if raised_exception :
319+ stream .writeln (self .separator2 )
320+ stream .writeln (result .exception )
321+ if not raised_exception :
322+ stream .writeln (self .separator2 )
323+
324+ def __call__ (self , result ):
325+ collector = self ._collectors .get (result .status )
326+ if collector is not None :
327+ collector .append (result )
328+
329+
252330class TimingResultHandler (IResultHandlerPlugin ):
253331 separator1 = '=' * 70
254332 separator2 = separator2
0 commit comments