| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 """Test cases for results_dashboard.""" | 6 """Test cases for results_dashboard.""" |
| 7 | 7 |
| 8 import datetime | 8 import datetime |
| 9 import json | 9 import json |
| 10 import os | 10 import os |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 """Tests related to functions which convert data format.""" | 32 """Tests related to functions which convert data format.""" |
| 33 | 33 |
| 34 def setUp(self): | 34 def setUp(self): |
| 35 super(ResultsDashboardFormatTest, self).setUp() | 35 super(ResultsDashboardFormatTest, self).setUp() |
| 36 self.mox = mox.Mox() | 36 self.mox = mox.Mox() |
| 37 self.maxDiff = None | 37 self.maxDiff = None |
| 38 | 38 |
| 39 def tearDown(self): | 39 def tearDown(self): |
| 40 self.mox.UnsetStubs() | 40 self.mox.UnsetStubs() |
| 41 | 41 |
| 42 def test_MakeDashboardJsonV1(self): |
| 43 self.mox.StubOutWithMock(slave_utils, 'GetActiveMaster') |
| 44 slave_utils.GetActiveMaster().AndReturn('ChromiumPerf') |
| 45 self.mox.StubOutWithMock(results_dashboard, '_GetTimestamp') |
| 46 # pylint: disable=W0212 |
| 47 results_dashboard._GetTimestamp().AndReturn(12345) |
| 48 results_dashboard._GetTimestamp().AndReturn(12345) |
| 49 self.mox.ReplayAll() |
| 50 v1json = results_dashboard.MakeDashboardJsonV1( |
| 51 {'some_json': 'from_telemetry'}, |
| 52 {'rev': 'f46bf3c', 'git_revision': 'f46bf3c', 'v8_rev': '73a34f'}, |
| 53 'win7', 'chromium.perf', 'Windows Builder (1)', '432', {'x': 'y'}, |
| 54 True) |
| 55 self.assertEqual({ |
| 56 'master': 'ChromiumPerf', |
| 57 'masterid': 'chromium.perf', |
| 58 'bot': 'win7', |
| 59 'buildername': 'Windows Builder (1)', |
| 60 'buildnumber': '432', |
| 61 'chart_data': {'some_json': 'from_telemetry'}, |
| 62 'is_ref': True, |
| 63 'point_id': 12345, |
| 64 'supplemental': {'default_rev': 'r_chromium', 'x': 'y'}, |
| 65 'versions': {'v8_rev': '73a34f', 'chromium': 'f46bf3c'}}, |
| 66 v1json) |
| 67 |
| 42 def test_MakeListOfPoints_MinimalCase(self): | 68 def test_MakeListOfPoints_MinimalCase(self): |
| 43 """A very simple test of a call to MakeListOfPoints.""" | 69 """A very simple test of a call to MakeListOfPoints.""" |
| 44 | 70 |
| 45 # The master name is gotten when making the list of points, | 71 # The master name is gotten when making the list of points, |
| 46 # so it must be stubbed out here. | 72 # so it must be stubbed out here. |
| 47 self.mox.StubOutWithMock(slave_utils, 'GetActiveMaster') | 73 self.mox.StubOutWithMock(slave_utils, 'GetActiveMaster') |
| 48 slave_utils.GetActiveMaster().AndReturn('MyMaster') | 74 slave_utils.GetActiveMaster().AndReturn('MyMaster') |
| 49 self.mox.ReplayAll() | 75 self.mox.ReplayAll() |
| 50 | 76 |
| 51 actual_points = results_dashboard.MakeListOfPoints( | 77 actual_points = results_dashboard.MakeListOfPoints( |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 else: | 324 else: |
| 299 urllib2.urlopen(IsEncodedJson(json_line)) | 325 urllib2.urlopen(IsEncodedJson(json_line)) |
| 300 self.mox.ReplayAll() | 326 self.mox.ReplayAll() |
| 301 results_dashboard.SendResults(new_data, 'https:/x.com', self.build_dir) | 327 results_dashboard.SendResults(new_data, 'https:/x.com', self.build_dir) |
| 302 self.mox.VerifyAll() | 328 self.mox.VerifyAll() |
| 303 | 329 |
| 304 def test_FailureRetried(self): | 330 def test_FailureRetried(self): |
| 305 """After failing once, the same JSON is sent the next time.""" | 331 """After failing once, the same JSON is sent the next time.""" |
| 306 # First, some data is sent but it fails for some reason. | 332 # First, some data is sent but it fails for some reason. |
| 307 self._TestSendResults( | 333 self._TestSendResults( |
| 308 {'sample': 1}, | 334 {'sample': 1, 'master': 'm', 'bot': 'b', |
| 309 ['{"sample": 1}'], | 335 'chart_data': {'benchmark_name': 'b'}, 'point_id': 1234}, |
| 336 [('{"sample": 1, "master": "m", "bot": "b", ' |
| 337 '"chart_data": {"benchmark_name": "b"}, "point_id": 1234}')], |
| 310 [urllib2.URLError('some reason')]) | 338 [urllib2.URLError('some reason')]) |
| 311 | 339 |
| 312 # The next time, the old data is sent with the new data. | 340 # The next time, the old data is sent with the new data. |
| 313 self._TestSendResults( | 341 self._TestSendResults( |
| 314 {'sample': 2}, | 342 {'sample': 2, 'master': 'm2', 'bot': 'b2', |
| 315 ['{"sample": 1}', '{"sample": 2}'], | 343 'chart_data': {'benchmark_name': 'b'}, 'point_id': 1234}, |
| 344 [('{"sample": 1, "master": "m", "bot": "b", ' |
| 345 '"chart_data": {"benchmark_name": "b"}, "point_id": 1234}'), |
| 346 ('{"sample": 2, "master": "m2", "bot": "b2", ' |
| 347 '"chart_data": {"benchmark_name": "b"}, "point_id": 1234}')], |
| 316 [None, None]) | 348 [None, None]) |
| 317 | 349 |
| 318 def test_SuccessNotRetried(self): | 350 def test_SuccessNotRetried(self): |
| 319 """After being successfully sent, data is not re-sent.""" | 351 """After being successfully sent, data is not re-sent.""" |
| 320 # First, some data is sent. | 352 # First, some data is sent. |
| 321 self._TestSendResults( | 353 self._TestSendResults( |
| 322 {'sample': 1}, | 354 {'sample': 1, 'master': 'm', 'bot': 'b', |
| 323 ['{"sample": 1}'], | 355 'chart_data': {'benchmark_name': 'b'}, 'point_id': 1234}, |
| 356 [('{"sample": 1, "master": "m", "bot": "b", ' |
| 357 '"chart_data": {"benchmark_name": "b"}, "point_id": 1234}')], |
| 324 [None]) | 358 [None]) |
| 325 | 359 |
| 326 # The next time, the old data is not sent with the new data. | 360 # The next time, the old data is not sent with the new data. |
| 327 self._TestSendResults( | 361 self._TestSendResults( |
| 328 {'sample': 2}, | 362 {'sample': 2, 'master': 'm2', 'bot': 'b2', |
| 329 ['{"sample": 2}'], | 363 'chart_data': {'benchmark_name': 'b'}, 'point_id': 1234}, |
| 364 [('{"sample": 2, "master": "m2", "bot": "b2", ' |
| 365 '"chart_data": {"benchmark_name": "b"}, "point_id": 1234}')], |
| 330 [None]) | 366 [None]) |
| 331 | 367 |
| 332 | 368 |
| 333 class ResultsDashboardTest(unittest.TestCase): | 369 class ResultsDashboardTest(unittest.TestCase): |
| 334 """Tests for other functions in results_dashboard.""" | 370 """Tests for other functions in results_dashboard.""" |
| 335 | 371 |
| 336 # Testing private method. | 372 # Testing private method. |
| 337 # pylint: disable=W0212 | 373 # pylint: disable=W0212 |
| 338 def test_LinkAnnotation_WithData(self): | 374 def test_LinkAnnotation_WithData(self): |
| 339 self.assertEqual( | 375 self.assertEqual( |
| 340 ('@@@STEP_LINK@Results Dashboard@' | 376 ('@@@STEP_LINK@Results Dashboard@' |
| 341 'https://chromeperf.appspot.com/report' | 377 'https://chromeperf.appspot.com/report' |
| 342 '?masters=MyMaster&bots=b&tests=sunspider&rev=1234@@@'), | 378 '?masters=MyMaster&bots=b&tests=sunspider&rev=1234@@@'), |
| 343 results_dashboard._LinkAnnotation( | 379 results_dashboard._LinkAnnotation( |
| 344 'https://chromeperf.appspot.com', | 380 'https://chromeperf.appspot.com', |
| 345 [{ | 381 [{ |
| 346 'master': 'MyMaster', | 382 'master': 'MyMaster', |
| 347 'bot': 'b', | 383 'bot': 'b', |
| 348 'test': 'sunspider/Total', | 384 'test': 'sunspider/Total', |
| 349 'revision': 1234, | 385 'revision': 1234, |
| 350 'value': 10, | 386 'value': 10, |
| 351 }])) | 387 }])) |
| 352 | 388 |
| 353 def test_LinkAnnotation_UnexpectedData(self): | 389 def test_LinkAnnotation_UnexpectedData(self): |
| 354 self.assertIsNone(results_dashboard._LinkAnnotation('', {})) | 390 self.assertIsNone(results_dashboard._LinkAnnotation('', {})) |
| 355 | 391 |
| 356 | 392 |
| 357 if __name__ == '__main__': | 393 if __name__ == '__main__': |
| 358 unittest.main() | 394 unittest.main() |
| OLD | NEW |