| 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 import os | 4 import os |
| 5 import traceback | 5 import traceback |
| 6 | 6 |
| 7 from telemetry.page import page_set | 7 from telemetry.page import page_set |
| 8 from telemetry.results import base_test_results_unittest | 8 from telemetry.results import base_test_results_unittest |
| 9 from telemetry.results import gtest_test_results | 9 from telemetry.results import gtest_test_results |
| 10 from telemetry.unittest import simple_mock | 10 from telemetry.unittest import simple_mock |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 exception_trace = ''.join(traceback.format_exception(*exception)) | 62 exception_trace = ''.join(traceback.format_exception(*exception)) |
| 63 expected = ('[ RUN ] http://www.foo.com/\n' | 63 expected = ('[ RUN ] http://www.foo.com/\n' |
| 64 '%s\n' | 64 '%s\n' |
| 65 '[ FAILED ] http://www.foo.com/ (0 ms)\n' | 65 '[ FAILED ] http://www.foo.com/ (0 ms)\n' |
| 66 '[ PASSED ] 0 tests.\n' | 66 '[ PASSED ] 0 tests.\n' |
| 67 '[ FAILED ] 1 test, listed below:\n' | 67 '[ FAILED ] 1 test, listed below:\n' |
| 68 '[ FAILED ] http://www.foo.com/\n\n' | 68 '[ FAILED ] http://www.foo.com/\n\n' |
| 69 '1 FAILED TEST\n\n' % exception_trace) | 69 '1 FAILED TEST\n\n' % exception_trace) |
| 70 self.assertEquals(expected, ''.join(results.output_data)) | 70 self.assertEquals(expected, ''.join(results.output_data)) |
| 71 | 71 |
| 72 def testSingleErrorPage(self): | |
| 73 test_page_set = _MakePageSet() | |
| 74 results = SummaryGtestTestResults() | |
| 75 results.StartTest(test_page_set.pages[0]) | |
| 76 exception = self.CreateException() | |
| 77 results.AddError(test_page_set.pages[0], exception) | |
| 78 results.PrintSummary() | |
| 79 exception_trace = ''.join(traceback.format_exception(*exception)) | |
| 80 expected = ('[ RUN ] http://www.foo.com/\n' | |
| 81 '%s\n' | |
| 82 '[ FAILED ] http://www.foo.com/ (0 ms)\n' | |
| 83 '[ PASSED ] 0 tests.\n' | |
| 84 '[ FAILED ] 1 test, listed below:\n' | |
| 85 '[ FAILED ] http://www.foo.com/\n\n' | |
| 86 '1 FAILED TEST\n\n' % exception_trace) | |
| 87 self.assertEquals(expected, ''.join(results.output_data)) | |
| 88 | |
| 89 def testSingleSkippedPage(self): | 72 def testSingleSkippedPage(self): |
| 90 test_page_set = _MakePageSet() | 73 test_page_set = _MakePageSet() |
| 91 results = SummaryGtestTestResults() | 74 results = SummaryGtestTestResults() |
| 92 results.StartTest(test_page_set.pages[0]) | 75 results.StartTest(test_page_set.pages[0]) |
| 93 self._mock_timer.SetTime(0.007) | 76 self._mock_timer.SetTime(0.007) |
| 94 results.AddSkip(test_page_set.pages[0], 'Page skipped for testing reason') | 77 results.AddSkip(test_page_set.pages[0], 'Page skipped for testing reason') |
| 95 results.PrintSummary() | 78 results.PrintSummary() |
| 96 expected = ('[ RUN ] http://www.foo.com/\n' | 79 expected = ('[ RUN ] http://www.foo.com/\n' |
| 97 '[ OK ] http://www.foo.com/ (7 ms)\n' | 80 '[ OK ] http://www.foo.com/ (7 ms)\n' |
| 98 '[ PASSED ] 0 tests.\n\n') | 81 '[ PASSED ] 0 tests.\n\n') |
| 99 self.assertEquals(expected, ''.join(results.output_data)) | 82 self.assertEquals(expected, ''.join(results.output_data)) |
| 100 | 83 |
| 101 def testPassAndFailedPages(self): | 84 def testPassAndFailedPages(self): |
| 102 test_page_set = _MakePageSet() | 85 test_page_set = _MakePageSet() |
| 103 results = SummaryGtestTestResults() | 86 results = SummaryGtestTestResults() |
| 104 exception = self.CreateException() | 87 exception = self.CreateException() |
| 105 | 88 |
| 106 results.StartTest(test_page_set.pages[0]) | 89 results.StartTest(test_page_set.pages[0]) |
| 107 self._mock_timer.SetTime(0.007) | 90 self._mock_timer.SetTime(0.007) |
| 108 results.AddSuccess(test_page_set.pages[0]) | 91 results.AddSuccess(test_page_set.pages[0]) |
| 109 | 92 |
| 110 results.StartTest(test_page_set.pages[1]) | 93 results.StartTest(test_page_set.pages[1]) |
| 111 self._mock_timer.SetTime(0.009) | 94 self._mock_timer.SetTime(0.009) |
| 112 results.AddError(test_page_set.pages[1], exception) | 95 results.AddFailure(test_page_set.pages[1], exception) |
| 113 | 96 |
| 114 results.StartTest(test_page_set.pages[2]) | 97 results.StartTest(test_page_set.pages[2]) |
| 115 self._mock_timer.SetTime(0.015) | 98 self._mock_timer.SetTime(0.015) |
| 116 results.AddFailure(test_page_set.pages[2], exception) | 99 results.AddFailure(test_page_set.pages[2], exception) |
| 117 | 100 |
| 118 results.StartTest(test_page_set.pages[3]) | 101 results.StartTest(test_page_set.pages[3]) |
| 119 self._mock_timer.SetTime(0.020) | 102 self._mock_timer.SetTime(0.020) |
| 120 results.AddSuccess(test_page_set.pages[3]) | 103 results.AddSuccess(test_page_set.pages[3]) |
| 121 | 104 |
| 122 results.PrintSummary() | 105 results.PrintSummary() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 146 results.StartTest(test_page_set.pages[0]) | 129 results.StartTest(test_page_set.pages[0]) |
| 147 self._mock_timer.SetTime(0.007) | 130 self._mock_timer.SetTime(0.007) |
| 148 results.AddSuccess(test_page_set.pages[0]) | 131 results.AddSuccess(test_page_set.pages[0]) |
| 149 expected = ('[ RUN ] http://www.foo.com/\n' | 132 expected = ('[ RUN ] http://www.foo.com/\n' |
| 150 '[ OK ] http://www.foo.com/ (7 ms)\n') | 133 '[ OK ] http://www.foo.com/ (7 ms)\n') |
| 151 self.assertEquals(expected, ''.join(results.output_data)) | 134 self.assertEquals(expected, ''.join(results.output_data)) |
| 152 | 135 |
| 153 results.StartTest(test_page_set.pages[1]) | 136 results.StartTest(test_page_set.pages[1]) |
| 154 self._mock_timer.SetTime(0.009) | 137 self._mock_timer.SetTime(0.009) |
| 155 exception_trace = ''.join(traceback.format_exception(*exception)) | 138 exception_trace = ''.join(traceback.format_exception(*exception)) |
| 156 results.AddError(test_page_set.pages[1], exception) | 139 results.AddFailure(test_page_set.pages[1], exception) |
| 157 expected = ('[ RUN ] http://www.foo.com/\n' | 140 expected = ('[ RUN ] http://www.foo.com/\n' |
| 158 '[ OK ] http://www.foo.com/ (7 ms)\n' | 141 '[ OK ] http://www.foo.com/ (7 ms)\n' |
| 159 '[ RUN ] http://www.bar.com/\n' | 142 '[ RUN ] http://www.bar.com/\n' |
| 160 '%s\n' | 143 '%s\n' |
| 161 '[ FAILED ] http://www.bar.com/ (2 ms)\n' % exception_trace) | 144 '[ FAILED ] http://www.bar.com/ (2 ms)\n' % exception_trace) |
| 162 | 145 |
| 163 def tearDown(self): | 146 def tearDown(self): |
| 164 gtest_test_results.time.time = self._real_gtest_time_time | 147 gtest_test_results.time.time = self._real_gtest_time_time |
| OLD | NEW |