| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 # No errors, should return True. | 163 # No errors, should return True. |
| 164 self.assertTrue(result) | 164 self.assertTrue(result) |
| 165 | 165 |
| 166 @mock.patch('slave.results_dashboard.MakeDashboardJsonV1') | 166 @mock.patch('slave.results_dashboard.MakeDashboardJsonV1') |
| 167 @mock.patch('slave.results_dashboard.SendResults') | 167 @mock.patch('slave.results_dashboard.SendResults') |
| 168 def test_SendResultsToDashboard_Telemetry( | 168 def test_SendResultsToDashboard_Telemetry( |
| 169 self, SendResults, MakeDashboardJsonV1): | 169 self, SendResults, MakeDashboardJsonV1): |
| 170 """Tests that the right methods get called in _SendResultsToDashboard.""" | 170 """Tests that the right methods get called in _SendResultsToDashboard.""" |
| 171 # Since this method just tests that certain methods get called when | 171 # Since this method just tests that certain methods get called when |
| 172 # a call to _SendResultsDashboard is made, the data used below is arbitrary. | 172 # a call to _SendResultsDashboard is made, the data used below is arbitrary. |
| 173 fake_json_data = {'chart': {'traces': {'x': [1, 0]}, 'rev': 1000}} | 173 fake_json_data = { |
| 174 'chart': {'traces': {'x': [1, 0]}, 'rev': 1000}, 'enabled': True} |
| 174 fake_results_tracker = mock.Mock() | 175 fake_results_tracker = mock.Mock() |
| 175 fake_results_tracker.IsChartJson = mock.MagicMock(return_value=True) | 176 fake_results_tracker.IsChartJson = mock.MagicMock(return_value=True) |
| 176 fake_results_tracker.ChartJson = mock.MagicMock(return_value=fake_json_data) | 177 fake_results_tracker.ChartJson = mock.MagicMock(return_value=fake_json_data) |
| 177 fake_results_tracker.IsReferenceBuild = mock.MagicMock(return_value=False) | 178 fake_results_tracker.IsReferenceBuild = mock.MagicMock(return_value=False) |
| 178 fake_results_tracker.Cleanup = mock.MagicMock() | 179 fake_results_tracker.Cleanup = mock.MagicMock() |
| 179 MakeDashboardJsonV1.return_value = {'doesnt': 'matter'} | 180 fake_results = {'doesnt': 'matter', 'chart_data': {'enabled': True}} |
| 181 MakeDashboardJsonV1.return_value = fake_results |
| 180 | 182 |
| 181 result = runtest._SendResultsToDashboard( | 183 result = runtest._SendResultsToDashboard( |
| 182 fake_results_tracker, { | 184 fake_results_tracker, { |
| 183 'system': 'linux', | 185 'system': 'linux', |
| 184 'test': 'sunspider', | 186 'test': 'sunspider', |
| 185 'url': 'http://x.com', | 187 'url': 'http://x.com', |
| 186 'build_dir': 'builddir', | 188 'build_dir': 'builddir', |
| 187 'mastername': 'my.master', | 189 'mastername': 'my.master', |
| 188 'buildername': 'Builder', | 190 'buildername': 'Builder', |
| 189 'buildnumber': 123, | 191 'buildnumber': 123, |
| 190 'revisions': {'rev': 343}, | 192 'revisions': {'rev': 343}, |
| 191 'supplemental_columns': {}}) | 193 'supplemental_columns': {}}) |
| 192 | 194 |
| 193 # Then the data is re-formatted to a format that the dashboard accepts. | 195 # Then the data is re-formatted to a format that the dashboard accepts. |
| 194 MakeDashboardJsonV1.assert_called_with( | 196 MakeDashboardJsonV1.assert_called_with( |
| 195 fake_json_data, {'rev': 343}, 'sunspider', 'linux', | 197 fake_json_data, {'rev': 343}, 'sunspider', 'linux', |
| 196 'Builder', 123, {}, False) | 198 'Builder', 123, {}, False) |
| 197 | 199 |
| 198 # Then a function is called to send the data (and any cached data). | 200 # Then a function is called to send the data (and any cached data). |
| 199 SendResults.assert_called_with( | 201 SendResults.assert_called_with( |
| 200 {'doesnt': 'matter'}, 'http://x.com', 'builddir') | 202 fake_results, 'http://x.com', 'builddir') |
| 201 fake_results_tracker.Cleanup.assert_called_with() | 203 fake_results_tracker.Cleanup.assert_called_with() |
| 202 | 204 |
| 203 # No errors, should return True. | 205 # No errors, should return True. |
| 204 self.assertTrue(result) | 206 self.assertTrue(result) |
| 205 | 207 |
| 206 @mock.patch('slave.results_dashboard.MakeDashboardJsonV1') | 208 @mock.patch('slave.results_dashboard.MakeDashboardJsonV1') |
| 207 @mock.patch('slave.results_dashboard.SendResults') | 209 @mock.patch('slave.results_dashboard.SendResults') |
| 210 def test_SendResultsToDashboard_DisabledBenchmark( |
| 211 self, SendResults, MakeDashboardJsonV1): |
| 212 """Tests that the right methods get called in _SendResultsToDashboard.""" |
| 213 # Since this method just tests that certain methods get called when |
| 214 # a call to _SendResultsDashboard is made, the data used below is arbitrary. |
| 215 fake_json_data = {'chart': {'traces': {'x': [1, 0]}, 'rev': 1000}, |
| 216 'enabled': True} |
| 217 fake_results_tracker = mock.Mock() |
| 218 fake_results_tracker.IsChartJson = mock.MagicMock(return_value=True) |
| 219 fake_results_tracker.ChartJson = mock.MagicMock(return_value=fake_json_data) |
| 220 fake_results_tracker.IsReferenceBuild = mock.MagicMock(return_value=False) |
| 221 fake_results_tracker.Cleanup = mock.MagicMock() |
| 222 fake_results = {'doesnt': 'matter', 'chart_data': {'enabled': False}} |
| 223 MakeDashboardJsonV1.return_value = fake_results |
| 224 |
| 225 result = runtest._SendResultsToDashboard( |
| 226 fake_results_tracker, { |
| 227 'system': 'linux', |
| 228 'test': 'sunspider', |
| 229 'url': 'http://x.com', |
| 230 'build_dir': 'builddir', |
| 231 'mastername': 'my.master', |
| 232 'buildername': 'Builder', |
| 233 'buildnumber': 123, |
| 234 'revisions': {'rev': 343}, |
| 235 'supplemental_columns': {}}) |
| 236 |
| 237 # Then the data is re-formatted to a format that the dashboard accepts. |
| 238 MakeDashboardJsonV1.assert_called_with( |
| 239 fake_json_data, {'rev': 343}, 'sunspider', 'linux', |
| 240 'Builder', 123, {}, False) |
| 241 |
| 242 # Make sure SendResults isn't called because the benchmarks is disabled |
| 243 self.assertFalse(SendResults.called) |
| 244 |
| 245 # No errors, should return True since disabled run is successful. |
| 246 self.assertTrue(result) |
| 247 |
| 248 @mock.patch('slave.results_dashboard.MakeDashboardJsonV1') |
| 249 @mock.patch('slave.results_dashboard.SendResults') |
| 208 def test_SendResultsToDashboard_NoTelemetryOutput( | 250 def test_SendResultsToDashboard_NoTelemetryOutput( |
| 209 self, SendResults, MakeDashboardJsonV1): | 251 self, SendResults, MakeDashboardJsonV1): |
| 210 """Tests that the right methods get called in _SendResultsToDashboard.""" | 252 """Tests that the right methods get called in _SendResultsToDashboard.""" |
| 211 fake_results_tracker = mock.Mock() | 253 fake_results_tracker = mock.Mock() |
| 212 fake_results_tracker.IsChartJson = mock.MagicMock(return_value=True) | 254 fake_results_tracker.IsChartJson = mock.MagicMock(return_value=True) |
| 213 fake_results_tracker.ChartJson = mock.MagicMock(return_value=None) | 255 fake_results_tracker.ChartJson = mock.MagicMock(return_value=None) |
| 214 fake_results_tracker.IsReferenceBuild = mock.MagicMock(return_value=False) | 256 fake_results_tracker.IsReferenceBuild = mock.MagicMock(return_value=False) |
| 215 fake_results_tracker.Cleanup = mock.MagicMock() | 257 fake_results_tracker.Cleanup = mock.MagicMock() |
| 216 | 258 |
| 217 runtest._SendResultsToDashboard( | 259 runtest._SendResultsToDashboard( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 243 'git_revision': '9a7b354', | 285 'git_revision': '9a7b354', |
| 244 } | 286 } |
| 245 versions = runtest._GetTelemetryRevisions(options) | 287 versions = runtest._GetTelemetryRevisions(options) |
| 246 self.assertEqual( | 288 self.assertEqual( |
| 247 {'rev': '294850', 'webkit_rev': '34f9d01', 'git_revision': '9a7b354', | 289 {'rev': '294850', 'webkit_rev': '34f9d01', 'git_revision': '9a7b354', |
| 248 'point_id': 1470050195}, | 290 'point_id': 1470050195}, |
| 249 versions) | 291 versions) |
| 250 | 292 |
| 251 if __name__ == '__main__': | 293 if __name__ == '__main__': |
| 252 unittest.main() | 294 unittest.main() |
| OLD | NEW |