OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 | 4 |
5 import os | 5 import os |
6 import re | 6 import re |
7 import shutil | 7 import shutil |
8 import sys | |
8 import unittest | 9 import unittest |
9 | 10 |
11 SRC = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir) | |
12 sys.path.append(os.path.join(SRC, 'third_party', 'pymock')) | |
13 | |
10 import bisect_perf_regression | 14 import bisect_perf_regression |
11 import bisect_results | 15 import bisect_results |
16 import mock | |
12 import source_control as source_control_module | 17 import source_control as source_control_module |
13 | 18 |
19 | |
14 def _GetBisectPerformanceMetricsInstance(): | 20 def _GetBisectPerformanceMetricsInstance(): |
15 """Returns an instance of the BisectPerformanceMetrics class.""" | 21 """Returns an instance of the BisectPerformanceMetrics class.""" |
16 options_dict = { | 22 options_dict = { |
17 'debug_ignore_build': True, | 23 'debug_ignore_build': True, |
18 'debug_ignore_sync': True, | 24 'debug_ignore_sync': True, |
19 'debug_ignore_perf_test': True, | 25 'debug_ignore_perf_test': True, |
20 'command': 'fake_command', | 26 'command': 'fake_command', |
21 'metric': 'fake/metric', | 27 'metric': 'fake/metric', |
22 'good_revision': 280000, | 28 'good_revision': 280000, |
23 'bad_revision': 280005, | 29 'bad_revision': 280005, |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 | 345 |
340 def testReturnsCorrectResultForChromeOS(self): | 346 def testReturnsCorrectResultForChromeOS(self): |
341 self.assertEqual(self.registry.GetDepotDir('cros'), '/mock/src/tools/cros') | 347 self.assertEqual(self.registry.GetDepotDir('cros'), '/mock/src/tools/cros') |
342 | 348 |
343 def testUsesDepotSpecToInitializeRegistry(self): | 349 def testUsesDepotSpecToInitializeRegistry(self): |
344 self.assertEqual(self.registry.GetDepotDir('mock_depot'), '/mock/src/foo') | 350 self.assertEqual(self.registry.GetDepotDir('mock_depot'), '/mock/src/foo') |
345 | 351 |
346 def testChangedTheDirectory(self): | 352 def testChangedTheDirectory(self): |
347 self.registry.ChangeToDepotDir('mock_depot') | 353 self.registry.ChangeToDepotDir('mock_depot') |
348 self.assertEqual(self.cur_dir, '/mock/src/foo') | 354 self.assertEqual(self.cur_dir, '/mock/src/foo') |
349 | 355 |
qyearsley
2014/10/02 01:07:53
Two newlines between top-level classes.
prasadv
2014/10/02 17:27:27
Done.
| |
356 # The tests below test private functions (W0212). | |
357 # pylint: disable=W0212 | |
358 class GitTryJobTestCases(unittest.TestCase): | |
359 """Test case for bisect try job.""" | |
360 def setUp(self): | |
361 bisect_utils_patcher = mock.patch('bisect_perf_regression.bisect_utils') | |
362 self.mock_bisect_utils = bisect_utils_patcher.start() | |
363 self.addCleanup(bisect_utils_patcher.stop) | |
364 | |
365 def _AssertRunGitExceptions(self, git_cmds, func, *args): | |
qyearsley
2014/10/02 01:07:53
I think it would be helpful to explain the paramet
prasadv
2014/10/02 17:27:27
Done.
| |
366 def side_effect(values): | |
qyearsley
2014/10/02 01:07:53
A name like git_cmd_args or something might be bet
prasadv
2014/10/02 17:27:27
Done.
| |
367 for val in git_cmds: | |
qyearsley
2014/10/02 01:07:53
If the items you're iterating over are pairs, you
prasadv
2014/10/02 17:27:27
"git_cmds" is a list of tuples with git commands a
| |
368 if set(val[0]) == set(values): | |
369 return val[1] | |
370 self.mock_bisect_utils.RunGit = mock.Mock(side_effect=side_effect) | |
371 self.assertRaises(bisect_perf_regression.RunGitError, | |
qyearsley
2014/10/02 01:07:53
If you wanted to add another test method below tha
prasadv
2014/10/02 17:27:27
Done.
| |
372 func, | |
373 *args) | |
374 | |
375 def testNotGitRepo(self): | |
376 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | |
377 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | |
378 cmds = ( | |
qyearsley
2014/10/02 01:07:53
This could also be a list (with square brackets) r
prasadv
2014/10/02 17:27:27
Done.
| |
379 (['rev-parse', '--abbrev-ref', 'HEAD'], (None, 128)),) | |
qyearsley
2014/10/02 01:07:53
I think indentation here should be 4 spaces.
prasadv
2014/10/02 17:27:27
Done.
| |
380 self._AssertRunGitExceptions(cmds, | |
381 bisect_perf_regression._PrepareBisectBranch, | |
382 parent_branch, new_branch) | |
383 | |
384 def testFailedCheckoutMaster(self): | |
385 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | |
386 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | |
387 cmds = ( | |
388 (['rev-parse', '--abbrev-ref', 'HEAD'], (new_branch, 0)), | |
389 (['checkout', '-f', parent_branch], ('Checkout Failed', 1)),) | |
qyearsley
2014/10/02 01:07:53
Nit: inconsistent indentation.
prasadv
2014/10/02 17:27:27
Done.
| |
390 self._AssertRunGitExceptions(cmds, | |
391 bisect_perf_regression._PrepareBisectBranch, | |
392 parent_branch, new_branch) | |
393 | |
394 def testDeleteBisectBranchIfExists(self): | |
395 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | |
396 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | |
397 cmds = ( | |
398 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), | |
399 (['branch', '--list' ], ('bisect-tryjob\n*master\nsomebranch', 0)), | |
400 (['branch', '-D', new_branch], ('Failed to delete branch', 128)),) | |
401 self._AssertRunGitExceptions(cmds, | |
402 bisect_perf_regression._PrepareBisectBranch, | |
403 parent_branch, new_branch) | |
404 | |
405 def testCreatNewBranchFails(self): | |
406 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | |
407 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | |
408 cmds = ( | |
409 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), | |
410 (['branch', '--list' ], ('bisect-tryjob\n*master\nsomebranch', 0)), | |
411 (['branch', '-D', new_branch], ('None', 0)), | |
412 (['update-index', '--refresh', '-q'], (None, 0)), | |
413 (['diff-index', 'HEAD'], (None, 0)), | |
414 (['checkout', '-b', new_branch], ('Failed to create branch', 128)),) | |
415 | |
416 self._AssertRunGitExceptions(cmds, | |
417 bisect_perf_regression._PrepareBisectBranch, | |
418 parent_branch, new_branch) | |
419 | |
420 def testSetUpstreamToFails(self): | |
421 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | |
422 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | |
423 cmds = ( | |
424 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), | |
425 (['branch', '--list' ], ('bisect-tryjob\n*master\nsomebranch', 0)), | |
426 (['branch', '-D', new_branch], ('None', 0)), | |
427 (['update-index', '--refresh', '-q'], (None, 0)), | |
428 (['diff-index', 'HEAD'], (None, 0)), | |
429 (['checkout', '-b', new_branch], ('None', 0)), | |
430 (['branch', '--set-upstream-to', parent_branch], ('Setuptream fails', 1)), | |
431 ) | |
432 self._AssertRunGitExceptions(cmds, | |
433 bisect_perf_regression._PrepareBisectBranch, | |
434 parent_branch, new_branch) | |
435 def testBuilderTryJob(self): | |
436 git_revision = 'ac4a9f31fe2610bd146857bbd55d7a260003a888' | |
437 bot_name = 'linux_perf_bisect_builder' | |
438 bisect_job_name = 'testBisectJobname' | |
439 patch = None | |
440 patch_content = '/dev/null' | |
441 new_branch = bisect_perf_regression.BISECT_TRYJOB_BRANCH | |
442 parent_branch = bisect_perf_regression.BISECT_MASTER_BRANCH | |
443 try_cmd = ( | |
444 (['rev-parse', '--abbrev-ref', 'HEAD'], (parent_branch, 0)), | |
445 (['branch', '--list' ], ('bisect-tryjob\n*master\nsomebranch', 0)), | |
446 (['branch', '-D', new_branch], ('None', 0)), | |
447 (['update-index', '--refresh', '-q'], (None, 0)), | |
448 (['diff-index', 'HEAD'], (None, 0)), | |
449 (['checkout', '-b', new_branch], ('None', 0)), | |
450 (['branch', '--set-upstream-to', parent_branch], | |
451 ('Setuptream fails', 0)), | |
452 (['try', | |
453 '-b', bot_name, | |
454 '-r', git_revision, | |
455 '-n', bisect_job_name, | |
456 '--svn_repo=%s' % bisect_perf_regression.SVN_REPO_URL, | |
457 '--diff=%s' % patch_content | |
458 ], (None, 1)), | |
459 ) | |
460 self._AssertRunGitExceptions(try_cmd, | |
461 bisect_perf_regression._BuilderTryjob, | |
462 git_revision, bot_name, bisect_job_name, patch) | |
463 | |
350 | 464 |
351 if __name__ == '__main__': | 465 if __name__ == '__main__': |
352 unittest.main() | 466 unittest.main() |
OLD | NEW |