Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Unified Diff: tools/telemetry/telemetry/results/gtest_test_results_unittest.py

Issue 332513002: Add unittest for gtest_test_results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Tony's comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/results/gtest_test_results_unittest.py
diff --git a/tools/telemetry/telemetry/results/gtest_test_results_unittest.py b/tools/telemetry/telemetry/results/gtest_test_results_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..7175f10aa5de3b1806f736500b22023f7013b198
--- /dev/null
+++ b/tools/telemetry/telemetry/results/gtest_test_results_unittest.py
@@ -0,0 +1,130 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+import os
+import traceback
+
+from telemetry.page import page_set
+from telemetry.results import base_test_results_unittest
+from telemetry.results import gtest_test_results
+from telemetry.unittest import simple_mock
+
+
+def _MakePageSet():
+ ps = page_set.PageSet(file_path=os.path.dirname(__file__))
+ ps.AddPageWithDefaultRunNavigate('http://www.foo.com/')
+ ps.AddPageWithDefaultRunNavigate('http://www.bar.com/')
+ ps.AddPageWithDefaultRunNavigate('http://www.baz.com/')
+ ps.AddPageWithDefaultRunNavigate('http://www.roz.com/')
+ return ps
+
+
+class SummaryGtestTestResults(
+ gtest_test_results.GTestTestResults):
+
+ def __init__(self):
+ super(SummaryGtestTestResults, self).__init__(
+ base_test_results_unittest.TestOutputStream())
+ self.output_data = self._output_stream.output_data
+
+
+class GTestTestResultsTest(
+ base_test_results_unittest.BaseTestResultsUnittest):
+
+ def setUp(self):
+ super(GTestTestResultsTest, self).setUp()
+ self._mock_timer = simple_mock.MockTimer()
+ self._real_gtest_time_time = gtest_test_results.time.time
+ gtest_test_results.time.time = self._mock_timer.GetTime
+
+ def testSingleSuccessPage(self):
+ test_page_set = _MakePageSet()
+
+ results = SummaryGtestTestResults()
+ results.StartTest(test_page_set.pages[0])
+ self._mock_timer.SetTime(0.007)
+ results.AddSuccess(test_page_set.pages[0])
+
+ results.PrintSummary()
+ expected = ('[ RUN ] http://www.foo.com/\n'
+ '[ OK ] http://www.foo.com/ (7 ms)\n'
+ '[ PASSED ] 1 test.\n\n')
+ self.assertEquals(expected, ''.join(results.output_data))
+
+ def testSingleFailedPage(self):
+ test_page_set = _MakePageSet()
+
+ results = SummaryGtestTestResults()
+ results.StartTest(test_page_set.pages[0])
+ exception = self.CreateException()
+ results.AddFailure(test_page_set.pages[0], exception)
+ results.PrintSummary()
+ exception_trace = ''.join(traceback.format_exception(*exception))
+ expected = ('[ RUN ] http://www.foo.com/\n'
+ '%s\n'
+ '[ FAILED ] http://www.foo.com/ (0 ms)\n'
+ '[ PASSED ] 0 tests.\n'
+ '[ FAILED ] 1 test, listed below:\n'
+ '[ FAILED ] http://www.foo.com/\n\n'
+ '1 FAILED TEST\n\n' % exception_trace)
+ self.assertEquals(expected, ''.join(results.output_data))
+
+ def testSingleErrorPage(self):
+ test_page_set = _MakePageSet()
+ results = SummaryGtestTestResults()
+ results.StartTest(test_page_set.pages[0])
+ exception = self.CreateException()
+ results.AddError(test_page_set.pages[0], exception)
+ results.PrintSummary()
+ exception_trace = ''.join(traceback.format_exception(*exception))
+ expected = ('[ RUN ] http://www.foo.com/\n'
+ '%s\n'
+ '[ FAILED ] http://www.foo.com/ (0 ms)\n'
+ '[ PASSED ] 0 tests.\n'
+ '[ FAILED ] 1 test, listed below:\n'
+ '[ FAILED ] http://www.foo.com/\n\n'
+ '1 FAILED TEST\n\n' % exception_trace)
+ self.assertEquals(expected, ''.join(results.output_data))
+
+ def testPassAndFailedPages(self):
+ test_page_set = _MakePageSet()
+ results = SummaryGtestTestResults()
+ exception = self.CreateException()
+
+ results.StartTest(test_page_set.pages[0])
+ self._mock_timer.SetTime(0.007)
+ results.AddSuccess(test_page_set.pages[0])
+
+ results.StartTest(test_page_set.pages[1])
+ self._mock_timer.SetTime(0.009)
+ results.AddError(test_page_set.pages[1], exception)
+
+ results.StartTest(test_page_set.pages[2])
+ self._mock_timer.SetTime(0.015)
+ results.AddFailure(test_page_set.pages[2], exception)
+
+ results.StartTest(test_page_set.pages[3])
+ self._mock_timer.SetTime(0.020)
+ results.AddSuccess(test_page_set.pages[3])
+
+ results.PrintSummary()
+ exception_trace = ''.join(traceback.format_exception(*exception))
+ expected = ('[ RUN ] http://www.foo.com/\n'
+ '[ OK ] http://www.foo.com/ (7 ms)\n'
+ '[ RUN ] http://www.bar.com/\n'
+ '%s\n'
+ '[ FAILED ] http://www.bar.com/ (2 ms)\n'
+ '[ RUN ] http://www.baz.com/\n'
+ '%s\n'
+ '[ FAILED ] http://www.baz.com/ (6 ms)\n'
+ '[ RUN ] http://www.roz.com/\n'
+ '[ OK ] http://www.roz.com/ (5 ms)\n'
+ '[ PASSED ] 2 tests.\n'
+ '[ FAILED ] 2 tests, listed below:\n'
+ '[ FAILED ] http://www.bar.com/\n'
+ '[ FAILED ] http://www.baz.com/\n\n'
+ '2 FAILED TESTS\n\n' % (exception_trace, exception_trace))
+ self.assertEquals(expected, ''.join(results.output_data))
+
+ def tearDown(self):
+ gtest_test_results.time.time = self._real_gtest_time_time

Powered by Google App Engine
This is Rietveld 408576698