| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for functions in runtest.py.""" | 6 """Unit tests for functions in runtest.py.""" |
| 7 | 7 |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 import test_env # pylint: disable=W0403,W0611 | 10 import test_env # pylint: disable=W0403,W0611 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 @mock.patch('slave.runtest._GetDataFromLogProcessor') | 126 @mock.patch('slave.runtest._GetDataFromLogProcessor') |
| 127 @mock.patch('slave.results_dashboard.MakeListOfPoints') | 127 @mock.patch('slave.results_dashboard.MakeListOfPoints') |
| 128 @mock.patch('slave.results_dashboard.SendResults') | 128 @mock.patch('slave.results_dashboard.SendResults') |
| 129 def test_SendResultsToDashboard_SimpleCase( | 129 def test_SendResultsToDashboard_SimpleCase( |
| 130 self, SendResults, MakeListOfPoints, GetDataFromLogProcessor): | 130 self, SendResults, MakeListOfPoints, GetDataFromLogProcessor): |
| 131 """Tests that the right methods get called in _SendResultsToDashboard.""" | 131 """Tests that the right methods get called in _SendResultsToDashboard.""" |
| 132 # Since this method just tests that certain methods get called when | 132 # Since this method just tests that certain methods get called when |
| 133 # a call to _SendResultsDashboard is made, the data used below is arbitrary. | 133 # a call to _SendResultsDashboard is made, the data used below is arbitrary. |
| 134 fake_charts_data = {'chart': {'traces': {'x': [1, 0]}, 'rev': 1000}} | 134 fake_charts_data = {'chart': {'traces': {'x': [1, 0]}, 'rev': 1000}} |
| 135 fake_points_data = [{'test': 'master/bot/chart/x', 'revision': 1000}] | 135 fake_points_data = [{'test': 'master/bot/chart/x', 'revision': 1000}] |
| 136 fake_results_tracker = mock.Mock() | 136 fake_results_tracker = object() |
| 137 fake_results_tracker.IsChartJson = mock.MagicMock(return_value=False) | |
| 138 GetDataFromLogProcessor.return_value = fake_charts_data | 137 GetDataFromLogProcessor.return_value = fake_charts_data |
| 139 MakeListOfPoints.return_value = fake_points_data | 138 MakeListOfPoints.return_value = fake_points_data |
| 140 | 139 |
| 141 runtest._SendResultsToDashboard( | 140 runtest._SendResultsToDashboard( |
| 142 fake_results_tracker, { | 141 fake_results_tracker, 'linux', 'sunspider', 'http://x.com', 'builddir', |
| 143 'system': 'linux', | 142 'my.master', 'Builder', 123, 'columns_file', extra_columns={}) |
| 144 'test': 'sunspider', | |
| 145 'url': 'http://x.com', | |
| 146 'build_dir': 'builddir', | |
| 147 'mastername': 'my.master', | |
| 148 'buildername': 'Builder', | |
| 149 'buildnumber': 123, | |
| 150 'supplemental_columns': {}}) | |
| 151 | 143 |
| 152 # First a function is called to get data from the log processor. | 144 # First a function is called to get data from the log processor. |
| 153 GetDataFromLogProcessor.assert_called_with(fake_results_tracker) | 145 GetDataFromLogProcessor.assert_called_with(fake_results_tracker) |
| 154 | 146 |
| 155 # Then the data is re-formatted to a format that the dashboard accepts. | 147 # Then the data is re-formatted to a format that the dashboard accepts. |
| 156 MakeListOfPoints.assert_called_with( | 148 MakeListOfPoints.assert_called_with( |
| 157 fake_charts_data, 'linux', 'sunspider', 'my.master', 'Builder', 123, {}) | 149 fake_charts_data, 'linux', 'sunspider', 'my.master', 'Builder', 123, {}) |
| 158 | 150 |
| 159 # Then a function is called to send the data (and any cached data). | 151 # Then a function is called to send the data (and any cached data). |
| 160 SendResults.assert_called_with( | 152 SendResults.assert_called_with( |
| 161 fake_points_data, 'http://x.com', 'builddir') | 153 fake_points_data, 'http://x.com', 'builddir') |
| 162 | 154 |
| 163 @mock.patch('slave.results_dashboard.MakeDashboardJsonV1') | |
| 164 @mock.patch('slave.results_dashboard.SendResults') | |
| 165 def test_SendResultsToDashboard_Telemetry( | |
| 166 self, SendResults, MakeDashboardJsonV1): | |
| 167 """Tests that the right methods get called in _SendResultsToDashboard.""" | |
| 168 # Since this method just tests that certain methods get called when | |
| 169 # a call to _SendResultsDashboard is made, the data used below is arbitrary. | |
| 170 fake_json_data = {'chart': {'traces': {'x': [1, 0]}, 'rev': 1000}} | |
| 171 fake_ref_data = {'test': 'master/bot/chart/x', 'revision': 1000} | |
| 172 fake_results_tracker = mock.Mock() | |
| 173 fake_results_tracker.IsChartJson = mock.MagicMock(return_value=True) | |
| 174 fake_results_tracker.ChartJson = mock.MagicMock(return_value=fake_json_data) | |
| 175 fake_results_tracker.RefJson = mock.MagicMock(return_value=fake_ref_data) | |
| 176 fake_results_tracker.Cleanup = mock.MagicMock() | |
| 177 MakeDashboardJsonV1.return_value = {'doesnt': 'matter'} | |
| 178 | |
| 179 runtest._SendResultsToDashboard( | |
| 180 fake_results_tracker, { | |
| 181 'system': 'linux', | |
| 182 'test': 'sunspider', | |
| 183 'url': 'http://x.com', | |
| 184 'build_dir': 'builddir', | |
| 185 'mastername': 'my.master', | |
| 186 'buildername': 'Builder', | |
| 187 'buildnumber': 123, | |
| 188 'revisions': {'rev': 343}, | |
| 189 'supplemental_columns': {}}) | |
| 190 | |
| 191 # Then the data is re-formatted to a format that the dashboard accepts. | |
| 192 MakeDashboardJsonV1.assert_has_calls([ | |
| 193 mock.call(fake_json_data, {'rev': 343}, 'linux', | |
| 194 'my.master', 'Builder', 123, {}, False), | |
| 195 mock.call(fake_ref_data, {'rev': 343}, 'linux', | |
| 196 'my.master', 'Builder', 123, {}, True)]) | |
| 197 | |
| 198 # Then a function is called to send the data (and any cached data). | |
| 199 SendResults.assert_has_calls([ | |
| 200 mock.call({'doesnt': 'matter'}, 'http://x.com', 'builddir'), | |
| 201 mock.call({'doesnt': 'matter'}, 'http://x.com', 'builddir')]) | |
| 202 | |
| 203 | 155 |
| 204 if __name__ == '__main__': | 156 if __name__ == '__main__': |
| 205 unittest.main() | 157 unittest.main() |
| OLD | NEW |