| 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 | |
| 68 def test_MakeListOfPoints_MinimalCase(self): | 42 def test_MakeListOfPoints_MinimalCase(self): |
| 69 """A very simple test of a call to MakeListOfPoints.""" | 43 """A very simple test of a call to MakeListOfPoints.""" |
| 70 | 44 |
| 71 # The master name is gotten when making the list of points, | 45 # The master name is gotten when making the list of points, |
| 72 # so it must be stubbed out here. | 46 # so it must be stubbed out here. |
| 73 self.mox.StubOutWithMock(slave_utils, 'GetActiveMaster') | 47 self.mox.StubOutWithMock(slave_utils, 'GetActiveMaster') |
| 74 slave_utils.GetActiveMaster().AndReturn('MyMaster') | 48 slave_utils.GetActiveMaster().AndReturn('MyMaster') |
| 75 self.mox.ReplayAll() | 49 self.mox.ReplayAll() |
| 76 | 50 |
| 77 actual_points = results_dashboard.MakeListOfPoints( | 51 actual_points = results_dashboard.MakeListOfPoints( |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 else: | 298 else: |
| 325 urllib2.urlopen(IsEncodedJson(json_line)) | 299 urllib2.urlopen(IsEncodedJson(json_line)) |
| 326 self.mox.ReplayAll() | 300 self.mox.ReplayAll() |
| 327 results_dashboard.SendResults(new_data, 'https:/x.com', self.build_dir) | 301 results_dashboard.SendResults(new_data, 'https:/x.com', self.build_dir) |
| 328 self.mox.VerifyAll() | 302 self.mox.VerifyAll() |
| 329 | 303 |
| 330 def test_FailureRetried(self): | 304 def test_FailureRetried(self): |
| 331 """After failing once, the same JSON is sent the next time.""" | 305 """After failing once, the same JSON is sent the next time.""" |
| 332 # First, some data is sent but it fails for some reason. | 306 # First, some data is sent but it fails for some reason. |
| 333 self._TestSendResults( | 307 self._TestSendResults( |
| 334 {'sample': 1, 'master': 'm', 'bot': 'b', | 308 {'sample': 1}, |
| 335 'chart_data': {'benchmark_name': 'b'}, 'point_id': 1234}, | 309 ['{"sample": 1}'], |
| 336 [('{"sample": 1, "master": "m", "bot": "b", ' | |
| 337 '"chart_data": {"benchmark_name": "b"}, "point_id": 1234}')], | |
| 338 [urllib2.URLError('some reason')]) | 310 [urllib2.URLError('some reason')]) |
| 339 | 311 |
| 340 # The next time, the old data is sent with the new data. | 312 # The next time, the old data is sent with the new data. |
| 341 self._TestSendResults( | 313 self._TestSendResults( |
| 342 {'sample': 2, 'master': 'm2', 'bot': 'b2', | 314 {'sample': 2}, |
| 343 'chart_data': {'benchmark_name': 'b'}, 'point_id': 1234}, | 315 ['{"sample": 1}', '{"sample": 2}'], |
| 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}')], | |
| 348 [None, None]) | 316 [None, None]) |
| 349 | 317 |
| 350 def test_SuccessNotRetried(self): | 318 def test_SuccessNotRetried(self): |
| 351 """After being successfully sent, data is not re-sent.""" | 319 """After being successfully sent, data is not re-sent.""" |
| 352 # First, some data is sent. | 320 # First, some data is sent. |
| 353 self._TestSendResults( | 321 self._TestSendResults( |
| 354 {'sample': 1, 'master': 'm', 'bot': 'b', | 322 {'sample': 1}, |
| 355 'chart_data': {'benchmark_name': 'b'}, 'point_id': 1234}, | 323 ['{"sample": 1}'], |
| 356 [('{"sample": 1, "master": "m", "bot": "b", ' | |
| 357 '"chart_data": {"benchmark_name": "b"}, "point_id": 1234}')], | |
| 358 [None]) | 324 [None]) |
| 359 | 325 |
| 360 # The next time, the old data is not sent with the new data. | 326 # The next time, the old data is not sent with the new data. |
| 361 self._TestSendResults( | 327 self._TestSendResults( |
| 362 {'sample': 2, 'master': 'm2', 'bot': 'b2', | 328 {'sample': 2}, |
| 363 'chart_data': {'benchmark_name': 'b'}, 'point_id': 1234}, | 329 ['{"sample": 2}'], |
| 364 [('{"sample": 2, "master": "m2", "bot": "b2", ' | |
| 365 '"chart_data": {"benchmark_name": "b"}, "point_id": 1234}')], | |
| 366 [None]) | 330 [None]) |
| 367 | 331 |
| 368 | 332 |
| 369 class ResultsDashboardTest(unittest.TestCase): | 333 class ResultsDashboardTest(unittest.TestCase): |
| 370 """Tests for other functions in results_dashboard.""" | 334 """Tests for other functions in results_dashboard.""" |
| 371 | 335 |
| 372 # Testing private method. | 336 # Testing private method. |
| 373 # pylint: disable=W0212 | 337 # pylint: disable=W0212 |
| 374 def test_LinkAnnotation_WithData(self): | 338 def test_LinkAnnotation_WithData(self): |
| 375 self.assertEqual( | 339 self.assertEqual( |
| 376 ('@@@STEP_LINK@Results Dashboard@' | 340 ('@@@STEP_LINK@Results Dashboard@' |
| 377 'https://chromeperf.appspot.com/report' | 341 'https://chromeperf.appspot.com/report' |
| 378 '?masters=MyMaster&bots=b&tests=sunspider&rev=1234@@@'), | 342 '?masters=MyMaster&bots=b&tests=sunspider&rev=1234@@@'), |
| 379 results_dashboard._LinkAnnotation( | 343 results_dashboard._LinkAnnotation( |
| 380 'https://chromeperf.appspot.com', | 344 'https://chromeperf.appspot.com', |
| 381 [{ | 345 [{ |
| 382 'master': 'MyMaster', | 346 'master': 'MyMaster', |
| 383 'bot': 'b', | 347 'bot': 'b', |
| 384 'test': 'sunspider/Total', | 348 'test': 'sunspider/Total', |
| 385 'revision': 1234, | 349 'revision': 1234, |
| 386 'value': 10, | 350 'value': 10, |
| 387 }])) | 351 }])) |
| 388 | 352 |
| 389 def test_LinkAnnotation_UnexpectedData(self): | 353 def test_LinkAnnotation_UnexpectedData(self): |
| 390 self.assertIsNone(results_dashboard._LinkAnnotation('', {})) | 354 self.assertIsNone(results_dashboard._LinkAnnotation('', {})) |
| 391 | 355 |
| 392 | 356 |
| 393 if __name__ == '__main__': | 357 if __name__ == '__main__': |
| 394 unittest.main() | 358 unittest.main() |
| OLD | NEW |