| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import argparse | 4 import argparse |
| 5 import logging | 5 import logging |
| 6 import json | 6 import json |
| 7 import StringIO | 7 import StringIO |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 import mock | 10 import mock |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 self._stubs.Restore() | 48 self._stubs.Restore() |
| 49 self._subprocess_patcher.stop() | 49 self._subprocess_patcher.stop() |
| 50 self._urllib2_patcher.stop() | 50 self._urllib2_patcher.stop() |
| 51 # Reset the cached builders in trybot_command | 51 # Reset the cached builders in trybot_command |
| 52 trybot_command.Trybot._builders = None | 52 trybot_command.Trybot._builders = None |
| 53 | 53 |
| 54 def _ExpectProcesses(self, expected_args_list): | 54 def _ExpectProcesses(self, expected_args_list): |
| 55 counter = [-1] | 55 counter = [-1] |
| 56 | 56 |
| 57 def side_effect(args, **kwargs): | 57 def side_effect(args, **kwargs): |
| 58 if not expected_args_list: |
| 59 self.fail( |
| 60 'Not expect any Popen() call but got a Popen call with %s\n' % args) |
| 58 del kwargs # unused | 61 del kwargs # unused |
| 59 counter[0] += 1 | 62 counter[0] += 1 |
| 60 expected_args, expected_responses = expected_args_list[counter[0]] | 63 expected_args, expected_responses = expected_args_list[counter[0]] |
| 61 self.assertEquals( | 64 self.assertEquals( |
| 62 expected_args, args, | 65 expected_args, args, |
| 63 'Popen() is called with unexpected args.\n Actual: %s.\n' | 66 'Popen() is called with unexpected args.\n Actual: %s.\n' |
| 64 'Expecting (index %i): %s' % (args, counter[0], expected_args)) | 67 'Expecting (index %i): %s' % (args, counter[0], expected_args)) |
| 65 return FakeProcess(expected_responses) | 68 return FakeProcess(expected_responses) |
| 66 self._mock_subprocess.Popen.side_effect = side_effect | 69 self._mock_subprocess.Popen.side_effect = side_effect |
| 67 | 70 |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)), | 483 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)), |
| 481 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', | 484 (['git', 'cl', 'try', '-m', 'tryserver.chromium.perf', '-b', |
| 482 'android_nexus4_perf_bisect'], (128, None, None)))) | 485 'android_nexus4_perf_bisect'], (128, None, None)))) |
| 483 cfg_filename = 'tools/run-perf-test.cfg' | 486 cfg_filename = 'tools/run-perf-test.cfg' |
| 484 cfg = StringIO.StringIO() | 487 cfg = StringIO.StringIO() |
| 485 self._stubs.open.files = {cfg_filename: cfg} | 488 self._stubs.open.files = {cfg_filename: cfg} |
| 486 self.assertRaises( | 489 self.assertRaises( |
| 487 trybot_command.TrybotError, command._UpdateConfigAndRunTryjob, | 490 trybot_command.TrybotError, command._UpdateConfigAndRunTryjob, |
| 488 'android', cfg_filename, []) | 491 'android', cfg_filename, []) |
| 489 | 492 |
| 493 def testUpdateConfigSkipTryjob(self): |
| 494 self._MockTryserverJson({'win_perf_bisect': 'stuff'}) |
| 495 command = trybot_command.Trybot() |
| 496 command._InitializeBuilderNames('win-x64') |
| 497 self._ExpectProcesses(()) |
| 498 cfg_filename = 'tools/run-perf-test.cfg' |
| 499 cfg_data = '''config = { |
| 500 "command": "python tools\\\\perf\\\\run_benchmark --browser=release_x64", |
| 501 "max_time_minutes": "120", |
| 502 "repeat_count": "1", |
| 503 "target_arch": "x64", |
| 504 "truncate_percent": "0" |
| 505 }''' |
| 506 self._stubs.open.files = {cfg_filename: cfg_data} |
| 507 self.assertEquals((trybot_command.NO_CHANGES, ''), |
| 508 command._UpdateConfigAndRunTryjob( |
| 509 'win-x64', cfg_filename, [])) |
| 510 |
| 490 def testUpdateConfigGitTry(self): | 511 def testUpdateConfigGitTry(self): |
| 491 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) | 512 self._MockTryserverJson({'android_nexus4_perf_bisect': 'stuff'}) |
| 492 command = trybot_command.Trybot() | 513 command = trybot_command.Trybot() |
| 493 command._InitializeBuilderNames('android-nexus4') | 514 command._InitializeBuilderNames('android-nexus4') |
| 494 self._ExpectProcesses(( | 515 self._ExpectProcesses(( |
| 495 (['git', 'commit', '-a', '-m', 'bisect config: android'], | 516 (['git', 'commit', '-a', '-m', 'bisect config: android'], |
| 496 (0, 'None', None)), | 517 (0, 'None', None)), |
| 497 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m', | 518 (['git', 'cl', 'upload', '-f', '--bypass-hooks', '-m', |
| 498 'CL for perf tryjob on android'], | 519 'CL for perf tryjob on android'], |
| 499 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)), | 520 (0, 'stuff https://codereview.chromium.org/12345 stuff', None)), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 "target_arch": "ia32", | 591 "target_arch": "ia32", |
| 571 "truncate_percent": "0" | 592 "truncate_percent": "0" |
| 572 }''''''config = { | 593 }''''''config = { |
| 573 "command": "./tools/perf/run_benchmark --browser=android-chromium", | 594 "command": "./tools/perf/run_benchmark --browser=android-chromium", |
| 574 "max_time_minutes": "120", | 595 "max_time_minutes": "120", |
| 575 "repeat_count": "1", | 596 "repeat_count": "1", |
| 576 "target_arch": "ia32", | 597 "target_arch": "ia32", |
| 577 "truncate_percent": "0" | 598 "truncate_percent": "0" |
| 578 }''') | 599 }''') |
| 579 self.assertEquals(cfg.read(), config) | 600 self.assertEquals(cfg.read(), config) |
| OLD | NEW |