| 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 json | 5 import json |
| 6 import os | 6 import os |
| 7 import StringIO | 7 import StringIO |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 from telemetry import benchmark | 10 from telemetry import benchmark |
| 11 from telemetry import page as page_module | 11 from telemetry import page as page_module |
| 12 from telemetry.results import chart_json_output_formatter | 12 from telemetry.results import chart_json_output_formatter |
| 13 from telemetry.results import page_test_results | 13 from telemetry.results import page_test_results |
| 14 from telemetry.page import page_set | 14 from telemetry.page import page_set |
| 15 from telemetry.value import improvement_direction |
| 16 from telemetry.value import list_of_scalar_values |
| 15 from telemetry.value import scalar | 17 from telemetry.value import scalar |
| 16 from telemetry.value import list_of_scalar_values | |
| 17 | 18 |
| 18 | 19 |
| 19 def _MakePageSet(): | 20 def _MakePageSet(): |
| 20 ps = page_set.PageSet(file_path=os.path.dirname(__file__)) | 21 ps = page_set.PageSet(file_path=os.path.dirname(__file__)) |
| 21 ps.AddUserStory(page_module.Page('http://www.foo.com/', ps, ps.base_dir)) | 22 ps.AddUserStory(page_module.Page('http://www.foo.com/', ps, ps.base_dir)) |
| 22 ps.AddUserStory(page_module.Page('http://www.bar.com/', ps, ps.base_dir)) | 23 ps.AddUserStory(page_module.Page('http://www.bar.com/', ps, ps.base_dir)) |
| 23 return ps | 24 return ps |
| 24 | 25 |
| 25 class ChartJsonTest(unittest.TestCase): | 26 class ChartJsonTest(unittest.TestCase): |
| 26 def setUp(self): | 27 def setUp(self): |
| 27 self._output = StringIO.StringIO() | 28 self._output = StringIO.StringIO() |
| 28 self._page_set = _MakePageSet() | 29 self._page_set = _MakePageSet() |
| 29 self._benchmark_metadata = benchmark.BenchmarkMetadata( | 30 self._benchmark_metadata = benchmark.BenchmarkMetadata( |
| 30 'benchmark_name', 'benchmark_description') | 31 'benchmark_name', 'benchmark_description') |
| 31 self._formatter = chart_json_output_formatter.ChartJsonOutputFormatter( | 32 self._formatter = chart_json_output_formatter.ChartJsonOutputFormatter( |
| 32 self._output, self._benchmark_metadata) | 33 self._output, self._benchmark_metadata) |
| 33 | 34 |
| 34 def testOutputAndParse(self): | 35 def testOutputAndParse(self): |
| 35 results = page_test_results.PageTestResults() | 36 results = page_test_results.PageTestResults() |
| 36 | 37 |
| 37 self._output.truncate(0) | 38 self._output.truncate(0) |
| 38 | 39 |
| 39 results.WillRunPage(self._page_set[0]) | 40 results.WillRunPage(self._page_set[0]) |
| 40 v0 = scalar.ScalarValue(results.current_page, 'foo', 'seconds', 3) | 41 v0 = scalar.ScalarValue(results.current_page, 'foo', 'seconds', 3, |
| 42 improvement_direction=improvement_direction.DOWN) |
| 41 results.AddValue(v0) | 43 results.AddValue(v0) |
| 42 results.DidRunPage(self._page_set[0]) | 44 results.DidRunPage(self._page_set[0]) |
| 43 | 45 |
| 44 self._formatter.Format(results) | 46 self._formatter.Format(results) |
| 45 d = json.loads(self._output.getvalue()) | 47 d = json.loads(self._output.getvalue()) |
| 46 self.assertIn('foo', d['charts']) | 48 self.assertIn('foo', d['charts']) |
| 47 | 49 |
| 48 def testAsChartDictSerializable(self): | 50 def testAsChartDictSerializable(self): |
| 49 v0 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 3) | 51 v0 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 3, |
| 52 improvement_direction=improvement_direction.DOWN) |
| 50 page_specific_values = [v0] | 53 page_specific_values = [v0] |
| 51 summary_values = [] | 54 summary_values = [] |
| 52 | 55 |
| 53 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 | 56 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 |
| 54 self._benchmark_metadata, | 57 self._benchmark_metadata, |
| 55 page_specific_values, | 58 page_specific_values, |
| 56 summary_values) | 59 summary_values) |
| 57 json.dumps(d) | 60 json.dumps(d) |
| 58 | 61 |
| 59 def testAsChartDictBaseKeys(self): | 62 def testAsChartDictBaseKeys(self): |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 summary_values = [] | 77 summary_values = [] |
| 75 | 78 |
| 76 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 | 79 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 |
| 77 benchmark.BenchmarkMetadata('benchmark_name', ''), | 80 benchmark.BenchmarkMetadata('benchmark_name', ''), |
| 78 page_specific_values, | 81 page_specific_values, |
| 79 summary_values) | 82 summary_values) |
| 80 | 83 |
| 81 self.assertEquals('', d['benchmark_description']) | 84 self.assertEquals('', d['benchmark_description']) |
| 82 | 85 |
| 83 def testAsChartDictPageSpecificValuesSamePage(self): | 86 def testAsChartDictPageSpecificValuesSamePage(self): |
| 84 v0 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 3) | 87 v0 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 3, |
| 85 v1 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 4) | 88 improvement_direction=improvement_direction.DOWN) |
| 89 v1 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 4, |
| 90 improvement_direction=improvement_direction.DOWN) |
| 86 page_specific_values = [v0, v1] | 91 page_specific_values = [v0, v1] |
| 87 summary_values = [] | 92 summary_values = [] |
| 88 | 93 |
| 89 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 | 94 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 |
| 90 self._benchmark_metadata, | 95 self._benchmark_metadata, |
| 91 page_specific_values, | 96 page_specific_values, |
| 92 summary_values) | 97 summary_values) |
| 93 | 98 |
| 94 self.assertTrue('foo' in d['charts']) | 99 self.assertTrue('foo' in d['charts']) |
| 95 self.assertTrue('http://www.foo.com/' in d['charts']['foo']) | 100 self.assertTrue('http://www.foo.com/' in d['charts']['foo']) |
| 96 | 101 |
| 97 def testAsChartDictPageSpecificValuesAndComputedSummaryWithTraceName(self): | 102 def testAsChartDictPageSpecificValuesAndComputedSummaryWithTraceName(self): |
| 98 v0 = scalar.ScalarValue(self._page_set[0], 'foo.bar', 'seconds', 3) | 103 v0 = scalar.ScalarValue(self._page_set[0], 'foo.bar', 'seconds', 3, |
| 99 v1 = scalar.ScalarValue(self._page_set[1], 'foo.bar', 'seconds', 4) | 104 improvement_direction=improvement_direction.DOWN) |
| 105 v1 = scalar.ScalarValue(self._page_set[1], 'foo.bar', 'seconds', 4, |
| 106 improvement_direction=improvement_direction.DOWN) |
| 100 page_specific_values = [v0, v1] | 107 page_specific_values = [v0, v1] |
| 101 summary_values = [] | 108 summary_values = [] |
| 102 | 109 |
| 103 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 | 110 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 |
| 104 self._benchmark_metadata, | 111 self._benchmark_metadata, |
| 105 page_specific_values, | 112 page_specific_values, |
| 106 summary_values) | 113 summary_values) |
| 107 | 114 |
| 108 self.assertTrue('foo' in d['charts']) | 115 self.assertTrue('foo' in d['charts']) |
| 109 self.assertTrue('http://www.foo.com/' in d['charts']['foo']) | 116 self.assertTrue('http://www.foo.com/' in d['charts']['foo']) |
| 110 self.assertTrue('http://www.bar.com/' in d['charts']['foo']) | 117 self.assertTrue('http://www.bar.com/' in d['charts']['foo']) |
| 111 self.assertTrue('bar' in d['charts']['foo']) | 118 self.assertTrue('bar' in d['charts']['foo']) |
| 112 | 119 |
| 113 def testAsChartDictPageSpecificValuesAndComputedSummaryWithoutTraceName(self): | 120 def testAsChartDictPageSpecificValuesAndComputedSummaryWithoutTraceName(self): |
| 114 v0 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 3) | 121 v0 = scalar.ScalarValue(self._page_set[0], 'foo', 'seconds', 3, |
| 115 v1 = scalar.ScalarValue(self._page_set[1], 'foo', 'seconds', 4) | 122 improvement_direction=improvement_direction.DOWN) |
| 123 v1 = scalar.ScalarValue(self._page_set[1], 'foo', 'seconds', 4, |
| 124 improvement_direction=improvement_direction.DOWN) |
| 116 page_specific_values = [v0, v1] | 125 page_specific_values = [v0, v1] |
| 117 summary_values = [] | 126 summary_values = [] |
| 118 | 127 |
| 119 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 | 128 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 |
| 120 self._benchmark_metadata, | 129 self._benchmark_metadata, |
| 121 page_specific_values, | 130 page_specific_values, |
| 122 summary_values) | 131 summary_values) |
| 123 | 132 |
| 124 self.assertTrue('foo' in d['charts']) | 133 self.assertTrue('foo' in d['charts']) |
| 125 self.assertTrue('http://www.foo.com/' in d['charts']['foo']) | 134 self.assertTrue('http://www.foo.com/' in d['charts']['foo']) |
| 126 self.assertTrue('http://www.bar.com/' in d['charts']['foo']) | 135 self.assertTrue('http://www.bar.com/' in d['charts']['foo']) |
| 127 self.assertTrue('summary' in d['charts']['foo']) | 136 self.assertTrue('summary' in d['charts']['foo']) |
| 128 | 137 |
| 129 def testAsChartDictSummaryValueWithTraceName(self): | 138 def testAsChartDictSummaryValueWithTraceName(self): |
| 130 v0 = list_of_scalar_values.ListOfScalarValues(None, 'foo.bar', 'seconds', | 139 v0 = list_of_scalar_values.ListOfScalarValues( |
| 131 [3, 4]) | 140 None, 'foo.bar', 'seconds', [3, 4], |
| 141 improvement_direction=improvement_direction.DOWN) |
| 132 page_specific_values = [] | 142 page_specific_values = [] |
| 133 summary_values = [v0] | 143 summary_values = [v0] |
| 134 | 144 |
| 135 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 | 145 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 |
| 136 self._benchmark_metadata, | 146 self._benchmark_metadata, |
| 137 page_specific_values, | 147 page_specific_values, |
| 138 summary_values) | 148 summary_values) |
| 139 | 149 |
| 140 self.assertTrue('bar' in d['charts']['foo']) | 150 self.assertTrue('bar' in d['charts']['foo']) |
| 141 | 151 |
| 142 def testAsChartDictSummaryValueWithoutTraceName(self): | 152 def testAsChartDictSummaryValueWithoutTraceName(self): |
| 143 v0 = list_of_scalar_values.ListOfScalarValues(None, 'foo', 'seconds', | 153 v0 = list_of_scalar_values.ListOfScalarValues( |
| 144 [3, 4]) | 154 None, 'foo', 'seconds', [3, 4], |
| 155 improvement_direction=improvement_direction.DOWN) |
| 145 page_specific_values = [] | 156 page_specific_values = [] |
| 146 summary_values = [v0] | 157 summary_values = [v0] |
| 147 | 158 |
| 148 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 | 159 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 |
| 149 self._benchmark_metadata, | 160 self._benchmark_metadata, |
| 150 page_specific_values, | 161 page_specific_values, |
| 151 summary_values) | 162 summary_values) |
| 152 | 163 |
| 153 self.assertTrue('summary' in d['charts']['foo']) | 164 self.assertTrue('summary' in d['charts']['foo']) |
| 154 | 165 |
| 155 def testAsChartDictValueSmokeTest(self): | 166 def testAsChartDictValueSmokeTest(self): |
| 156 v0 = list_of_scalar_values.ListOfScalarValues(None, 'foo.bar', 'seconds', | 167 v0 = list_of_scalar_values.ListOfScalarValues( |
| 157 [3, 4]) | 168 None, 'foo.bar', 'seconds', [3, 4], |
| 169 improvement_direction=improvement_direction.DOWN) |
| 158 page_specific_values = [] | 170 page_specific_values = [] |
| 159 summary_values = [v0] | 171 summary_values = [v0] |
| 160 | 172 |
| 161 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 | 173 d = chart_json_output_formatter._ResultsAsChartDict( # pylint: disable=W0212 |
| 162 self._benchmark_metadata, | 174 self._benchmark_metadata, |
| 163 page_specific_values, | 175 page_specific_values, |
| 164 summary_values) | 176 summary_values) |
| 165 | 177 |
| 166 self.assertEquals(d['charts']['foo']['bar']['values'], [3, 4]) | 178 self.assertEquals(d['charts']['foo']['bar']['values'], [3, 4]) |
| OLD | NEW |