OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 | |
7 import logging | |
8 | |
9 | |
10 # Language values match constants in Sponge protocol buffer (sponge.proto). | |
11 JAVA = 5 | |
12 PYTHON = 7 | |
13 | |
14 | |
15 class BaseTestResult(object): | |
16 """A single result from a unit test.""" | |
17 | |
18 def __init__(self, name, log): | |
19 self.name = name | |
20 self.log = log | |
21 | |
22 | |
23 class SingleTestResult(BaseTestResult): | |
24 """Result information for a single test. | |
25 | |
26 Args: | |
27 full_name: Full name of the test. | |
28 start_date: Date in milliseconds when the test began running. | |
29 dur: Duration of the test run in milliseconds. | |
30 lang: Language of the test (JAVA or PYTHON). | |
31 log: An optional string listing any errors. | |
32 error: A tuple of a short error message and a longer version used by Sponge | |
33 if test resulted in a fail or error. An empty tuple implies a pass. | |
34 """ | |
35 | |
36 def __init__(self, full_name, start_date, dur, lang, log='', error=()): | |
37 BaseTestResult.__init__(self, full_name, log) | |
38 name_pieces = full_name.rsplit('#') | |
39 if len(name_pieces) > 0: | |
40 self.test_name = name_pieces[1] | |
41 self.class_name = name_pieces[0] | |
42 else: | |
43 self.class_name = full_name | |
44 self.test_name = full_name | |
45 self.start_date = start_date | |
46 self.dur = dur | |
47 self.error = error | |
48 self.lang = lang | |
49 | |
50 | |
51 class TestResults(object): | |
52 """Results of a test run.""" | |
53 | |
54 def __init__(self): | |
55 self.ok = [] | |
56 self.failed = [] | |
57 self.crashed = [] | |
58 self.unknown = [] | |
59 self.disabled = [] | |
60 self.unexpected_pass = [] | |
61 | |
62 @staticmethod | |
63 def FromOkAndFailed(ok, failed): | |
64 ret = TestResults() | |
65 ret.ok = ok | |
66 ret.failed = failed | |
67 return ret | |
68 | |
69 @staticmethod | |
70 def FromTestResults(results): | |
71 """Combines a list of results in a single TestResults object.""" | |
72 ret = TestResults() | |
73 for t in results: | |
74 ret.ok += t.ok | |
75 ret.failed += t.failed | |
76 ret.crashed += t.crashed | |
77 ret.unknown += t.unknown | |
78 ret.disabled += t.disabled | |
79 ret.unexpected_pass += t.unexpected_pass | |
80 return ret | |
81 | |
82 def _Log(self, sorted_list): | |
83 for t in sorted_list: | |
84 logging.critical(t.name) | |
85 if t.log: | |
86 logging.critical(t.log) | |
87 | |
88 def GetAllBroken(self): | |
Nirnimesh
2011/10/24 18:02:34
docstring please
michaelbai
2011/10/24 18:33:51
Done.
| |
89 return self.failed + self.crashed + self.unknown | |
90 | |
91 def LogFull(self): | |
Nirnimesh
2011/10/24 18:02:34
docstring please
michaelbai
2011/10/24 18:33:51
Done.
| |
92 logging.critical('*' * 80) | |
93 logging.critical('Final result') | |
94 if self.failed: | |
95 logging.critical('Failed:') | |
96 self._Log(sorted(self.failed)) | |
97 if self.crashed: | |
98 logging.critical('Crashed:') | |
99 self._Log(sorted(self.crashed)) | |
100 if self.unknown: | |
101 logging.critical('Unknown:') | |
102 self._Log(sorted(self.unknown)) | |
103 if not self.GetAllBroken(): | |
104 logging.critical('Passed') | |
105 logging.critical('*' * 80) | |
OLD | NEW |