OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 import sys | 6 import sys |
7 import time | 7 import time |
8 import unittest | |
9 | 8 |
10 from telemetry.results import page_test_results | 9 from telemetry.results import page_test_results |
11 | 10 |
12 | 11 |
13 class GTestTestResults(page_test_results.PageTestResults): | 12 class GTestTestResults(page_test_results.PageTestResults): |
14 def __init__(self, output_stream): | 13 def __init__(self, output_stream): |
15 super(GTestTestResults, self).__init__(output_stream) | 14 super(GTestTestResults, self).__init__(output_stream) |
16 self._timestamp = None | 15 self._timestamp = None |
17 | 16 |
18 def _GetMs(self): | 17 def _GetMs(self): |
19 return (time.time() - self._timestamp) * 1000 | 18 return (time.time() - self._timestamp) * 1000 |
20 | 19 |
21 @property | 20 @property |
22 def num_errors(self): | 21 def num_errors(self): |
23 return len(self.errors) + len(self.failures) | 22 return len(self.errors) + len(self.failures) |
24 | 23 |
25 @staticmethod | 24 def _emitFailure(self, page, err): |
26 def _formatTestname(test): | 25 print >> self._output_stream, self._GetStringFromExcInfo(err) |
27 if isinstance(test, unittest.TestCase): | 26 print >> self._output_stream, '[ FAILED ]', page.display_name, ( |
28 chunks = test.id().split('.')[2:] | |
29 return '.'.join(chunks) | |
30 else: | |
31 return str(test) | |
32 | |
33 def _emitFailure(self, test, err): | |
34 print >> self._output_stream, self._exc_info_to_string(err, test) | |
35 test_name = GTestTestResults._formatTestname(test) | |
36 print >> self._output_stream, '[ FAILED ]', test_name, ( | |
37 '(%0.f ms)' % self._GetMs()) | 27 '(%0.f ms)' % self._GetMs()) |
38 sys.stdout.flush() | 28 sys.stdout.flush() |
39 | 29 |
40 def addError(self, test, err): | 30 def AddError(self, page, err): |
41 super(GTestTestResults, self).addError(test, err) | 31 super(GTestTestResults, self).AddError(page, err) |
42 self._emitFailure(test, err) | 32 self._emitFailure(page, err) |
43 | 33 |
44 def addFailure(self, test, err): | 34 def AddFailure(self, page, err): |
45 super(GTestTestResults, self).addFailure(test, err) | 35 super(GTestTestResults, self).AddFailure(page, err) |
46 self._emitFailure(test, err) | 36 self._emitFailure(page, err) |
47 | 37 |
48 def startTest(self, test): | 38 def StartTest(self, page): |
49 super(GTestTestResults, self).startTest(test) | |
Ken Russell (switch to Gerrit)
2014/06/16 20:21:42
Was this super call accidentally lost?
nednguyen
2014/06/16 20:36:13
I made it a complete override, because PageTestRes
| |
50 print >> self._output_stream, '[ RUN ]', ( | 39 print >> self._output_stream, '[ RUN ]', ( |
51 GTestTestResults._formatTestname(test)) | 40 page.display_name) |
52 sys.stdout.flush() | 41 sys.stdout.flush() |
53 self._timestamp = time.time() | 42 self._timestamp = time.time() |
54 | 43 |
55 def addSuccess(self, test): | 44 def AddSuccess(self, page): |
56 super(GTestTestResults, self).addSuccess(test) | 45 super(GTestTestResults, self).AddSuccess(page) |
57 test_name = GTestTestResults._formatTestname(test) | 46 test_name = page.display_name |
58 print >> self._output_stream, '[ OK ]', test_name, ( | 47 print >> self._output_stream, '[ OK ]', test_name, ( |
59 '(%0.f ms)' % self._GetMs()) | 48 '(%0.f ms)' % self._GetMs()) |
60 sys.stdout.flush() | 49 sys.stdout.flush() |
61 | 50 |
62 def addSkip(self, test, reason): | 51 def AddSkip(self, page, reason): |
63 super(GTestTestResults, self).addSkip(test, reason) | 52 super(GTestTestResults, self).AddSkip(page, reason) |
64 test_name = GTestTestResults._formatTestname(test) | 53 test_name = page.display_name |
65 logging.warning('===== SKIPPING TEST %s: %s =====', test_name, reason) | 54 logging.warning('===== SKIPPING TEST %s: %s =====', test_name, reason) |
66 if self._timestamp == None: | 55 if self._timestamp == None: |
67 self._timestamp = time.time() | 56 self._timestamp = time.time() |
68 print >> self._output_stream, '[ OK ]', test_name, ( | 57 print >> self._output_stream, '[ OK ]', test_name, ( |
69 '(%0.f ms)' % self._GetMs()) | 58 '(%0.f ms)' % self._GetMs()) |
70 sys.stdout.flush() | 59 sys.stdout.flush() |
71 | 60 |
72 def PrintSummary(self): | 61 def PrintSummary(self): |
73 unit = 'test' if len(self.successes) == 1 else 'tests' | 62 unit = 'test' if len(self.successes) == 1 else 'tests' |
74 print >> self._output_stream, '[ PASSED ]', ( | 63 print >> self._output_stream, '[ PASSED ]', ( |
75 '%d %s.' % (len(self.successes), unit)) | 64 '%d %s.' % (len(self.successes), unit)) |
76 if self.errors or self.failures: | 65 if self.errors or self.failures: |
77 all_errors = self.errors[:] | 66 all_errors = self.errors[:] |
78 all_errors.extend(self.failures) | 67 all_errors.extend(self.failures) |
79 unit = 'test' if len(all_errors) == 1 else 'tests' | 68 unit = 'test' if len(all_errors) == 1 else 'tests' |
80 print >> self._output_stream, '[ FAILED ]', ( | 69 print >> self._output_stream, '[ FAILED ]', ( |
81 '%d %s, listed below:' % (len(all_errors), unit)) | 70 '%d %s, listed below:' % (len(all_errors), unit)) |
82 for test, _ in all_errors: | 71 for page, _ in all_errors: |
83 print >> self._output_stream, '[ FAILED ] ', ( | 72 print >> self._output_stream, '[ FAILED ] ', ( |
84 GTestTestResults._formatTestname(test)) | 73 page.display_name) |
85 if not self.wasSuccessful(): | |
86 print >> self._output_stream | 74 print >> self._output_stream |
87 count = len(self.errors) + len(self.failures) | 75 count = len(self.errors) + len(self.failures) |
88 unit = 'TEST' if count == 1 else 'TESTS' | 76 unit = 'TEST' if count == 1 else 'TESTS' |
89 print >> self._output_stream, '%d FAILED %s' % (count, unit) | 77 print >> self._output_stream, '%d FAILED %s' % (count, unit) |
90 print >> self._output_stream | 78 print >> self._output_stream |
91 sys.stdout.flush() | 79 sys.stdout.flush() |
OLD | NEW |