1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
9 # Language values match constants in Sponge protocol buffer (sponge.proto).
14 class BaseTestResult(object):
15 """A single result from a unit test."""
17 def __init__(self
, name
, log
):
22 class SingleTestResult(BaseTestResult
):
23 """Result information for a single test.
26 full_name: Full name of the test.
27 start_date: Date in milliseconds when the test began running.
28 dur: Duration of the test run in milliseconds.
29 lang: Language of the test (JAVA or PYTHON).
30 log: An optional string listing any errors.
31 error: A tuple of a short error message and a longer version used by Sponge
32 if test resulted in a fail or error. An empty tuple implies a pass.
35 def __init__(self
, full_name
, start_date
, dur
, lang
, log
='', error
=()):
36 BaseTestResult
.__init
__(self
, full_name
, log
)
37 name_pieces
= full_name
.rsplit('#')
38 if len(name_pieces
) > 0:
39 self
.test_name
= name_pieces
[1]
40 self
.class_name
= name_pieces
[0]
42 self
.class_name
= full_name
43 self
.test_name
= full_name
44 self
.start_date
= start_date
50 class TestResults(object):
51 """Results of a test run."""
59 self
.unexpected_pass
= []
60 self
.timed_out
= False
63 def FromOkAndFailed(ok
, failed
, timed_out
=False):
67 ret
.timed_out
= timed_out
71 def FromTestResults(results
):
72 """Combines a list of results in a single TestResults object."""
76 ret
.failed
+= t
.failed
77 ret
.crashed
+= t
.crashed
78 ret
.unknown
+= t
.unknown
79 ret
.disabled
+= t
.disabled
80 ret
.unexpected_pass
+= t
.unexpected_pass
85 def _Log(self
, sorted_list
):
87 logging
.critical(t
.name
)
89 logging
.critical(t
.log
)
91 def GetAllBroken(self
):
92 """Returns the all broken tests including failed, crashed, unknown."""
93 return self
.failed
+ self
.crashed
+ self
.unknown
96 """Output all broken tests or 'passed' if none broken"""
97 logging
.critical('*' * 80)
98 logging
.critical('Final result')
100 logging
.critical('Failed:')
101 self
._Log
(sorted(self
.failed
))
103 logging
.critical('Crashed:')
104 self
._Log
(sorted(self
.crashed
))
106 logging
.critical('Unknown:')
107 self
._Log
(sorted(self
.unknown
))
108 if not self
.GetAllBroken():
109 logging
.critical('Passed')
110 logging
.critical('*' * 80)