Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: tests/git_cl_test.py

Issue 104043008: Added --(de)activate-update options (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Changed noautoupdate to autoupdate Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« git_cl.py ('K') | « git_cl.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 git_cl.py.""" 6 """Unit tests for git_cl.py."""
7 7
8 import os 8 import os
9 import StringIO 9 import StringIO
10 import stat 10 import stat
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 if find_copies: 140 if find_copies:
141 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', 141 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat',
142 '--find-copies-harder', '-l100000', '-C'+similarity, 142 '--find-copies-harder', '-l100000', '-C'+similarity,
143 'fake_ancestor_sha', 'HEAD'],), '+dat') 143 'fake_ancestor_sha', 'HEAD'],), '+dat')
144 else: 144 else:
145 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', 145 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat',
146 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') 146 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat')
147 147
148 return [ 148 return [
149 ((['git', 'config', 'rietveld.autoupdate'],),
ghost stip (do not use) 2014/01/03 20:40:21 nit: make this one line?
150 ''),
149 ((['git', 'config', 'rietveld.server'],), 151 ((['git', 'config', 'rietveld.server'],),
150 'codereview.example.com'), 152 'codereview.example.com'),
151 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 153 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
152 similarity_call, 154 similarity_call,
153 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 155 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
154 find_copies_call, 156 find_copies_call,
155 ((['git', 'update-index', '--refresh', '-q'],), ''), 157 ((['git', 'update-index', '--refresh', '-q'],), ''),
156 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), 158 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''),
157 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 159 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
158 ((['git', 'config', 'branch.master.merge'],), 'master'), 160 ((['git', 'config', 'branch.master.merge'],), 'master'),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 245
244 @classmethod 246 @classmethod
245 def _dcommit_calls_1(cls): 247 def _dcommit_calls_1(cls):
246 return [ 248 return [
247 ((['git', 249 ((['git',
248 'config', '--local', '--get-regexp', '^svn-remote\\.'],), 250 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
249 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' 251 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n'
250 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), 252 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'),
251 None), 253 None),
252 0)), 254 0)),
255 ((['git', 'config', 'rietveld.autoupdate'],),
256 ''),
253 ((['git', 257 ((['git',
254 'config', 'rietveld.server'],), 'codereview.example.com'), 258 'config', 'rietveld.server'],), 'codereview.example.com'),
255 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 259 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
256 ((['git', 'config', '--int', '--get', 260 ((['git', 'config', '--int', '--get',
257 'branch.working.git-cl-similarity'],), ''), 261 'branch.working.git-cl-similarity'],), ''),
258 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 262 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
259 ((['git', 'config', '--int', '--get', 263 ((['git', 'config', '--int', '--get',
260 'branch.working.git-find-copies'],), ''), 264 'branch.working.git-find-copies'],), ''),
261 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 265 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
262 ((['git', 266 ((['git',
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 if '--find-copies' in upload_args: 379 if '--find-copies' in upload_args:
376 find_copies = True 380 find_copies = True
377 elif '--no-find-copies' in upload_args: 381 elif '--no-find-copies' in upload_args:
378 find_copies = False 382 find_copies = False
379 else: 383 else:
380 find_copies = None 384 find_copies = None
381 385
382 private = '--private' in upload_args 386 private = '--private' in upload_args
383 387
384 self.calls = self._upload_calls(similarity, find_copies, private) 388 self.calls = self._upload_calls(similarity, find_copies, private)
389
385 def RunEditor(desc, _, **kwargs): 390 def RunEditor(desc, _, **kwargs):
386 self.assertEquals( 391 self.assertEquals(
387 '# Enter a description of the change.\n' 392 '# Enter a description of the change.\n'
388 '# This will be displayed on the codereview site.\n' 393 '# This will be displayed on the codereview site.\n'
389 '# The first line will also be used as the subject of the review.\n' 394 '# The first line will also be used as the subject of the review.\n'
390 '#--------------------This line is 72 characters long' 395 '#--------------------This line is 72 characters long'
391 '--------------------\n' + 396 '--------------------\n' +
392 expected_description, 397 expected_description,
393 desc) 398 desc)
394 return returned_description 399 return returned_description
395 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) 400 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
401
396 def check_upload(args): 402 def check_upload(args):
397 cmd_line = self._cmd_line(final_description, reviewers, similarity, 403 cmd_line = self._cmd_line(final_description, reviewers, similarity,
398 find_copies, private) 404 find_copies, private)
399 self.assertEquals(cmd_line, args) 405 self.assertEquals(cmd_line, args)
400 return 1, 2 406 return 1, 2
401 self.mock(git_cl.upload, 'RealMain', check_upload) 407 self.mock(git_cl.upload, 'RealMain', check_upload)
408
402 git_cl.main(['upload'] + upload_args) 409 git_cl.main(['upload'] + upload_args)
403 410
404 def test_no_reviewer(self): 411 def test_no_reviewer(self):
405 self._run_reviewer_test( 412 self._run_reviewer_test(
406 [], 413 [],
407 'desc\n\nBUG=', 414 'desc\n\nBUG=',
408 '# Blah blah comment.\ndesc\n\nBUG=', 415 '# Blah blah comment.\ndesc\n\nBUG=',
409 'desc\n\nBUG=', 416 'desc\n\nBUG=',
410 []) 417 [])
411 418
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 self.calls = ( 515 self.calls = (
509 self._dcommit_calls_1() + 516 self._dcommit_calls_1() +
510 self._dcommit_calls_bypassed() + 517 self._dcommit_calls_bypassed() +
511 self._dcommit_calls_3()) 518 self._dcommit_calls_3())
512 git_cl.main(['dcommit', '--bypass-hooks']) 519 git_cl.main(['dcommit', '--bypass-hooks'])
513 520
514 521
515 @classmethod 522 @classmethod
516 def _gerrit_base_calls(cls): 523 def _gerrit_base_calls(cls):
517 return [ 524 return [
525 ((['git', 'config', 'rietveld.autoupdate'],),
526 ''),
518 ((['git', 527 ((['git',
519 'config', 'rietveld.server'],), 'codereview.example.com'), 528 'config', 'rietveld.server'],), 'codereview.example.com'),
520 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 529 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
521 ((['git', 'config', '--int', '--get', 530 ((['git', 'config', '--int', '--get',
522 'branch.master.git-cl-similarity'],), ''), 531 'branch.master.git-cl-similarity'],), ''),
523 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 532 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
524 ((['git', 'config', '--int', '--get', 533 ((['git', 'config', '--int', '--get',
525 'branch.master.git-find-copies'],), ''), 534 'branch.master.git-find-copies'],), ''),
526 ((['git', 'update-index', '--refresh', '-q'],), ''), 535 ((['git', 'update-index', '--refresh', '-q'],), ''),
527 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), 536 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''),
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') 653 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg')
645 def Exists(path): 654 def Exists(path):
646 if path == commit_msg_path: 655 if path == commit_msg_path:
647 return False 656 return False
648 # others paths, such as /usr/share/locale/.... 657 # others paths, such as /usr/share/locale/....
649 return True 658 return True
650 self.mock(git_cl.os.path, 'exists', Exists) 659 self.mock(git_cl.os.path, 'exists', Exists)
651 self.mock(git_cl, 'urlretrieve', self._mocked_call) 660 self.mock(git_cl, 'urlretrieve', self._mocked_call)
652 self.mock(git_cl, 'hasSheBang', self._mocked_call) 661 self.mock(git_cl, 'hasSheBang', self._mocked_call)
653 self.calls = [ 662 self.calls = [
663 ((['git', 'config', 'rietveld.autoupdate'],),
664 ''),
654 ((['git', 'config', 'rietveld.server', 665 ((['git', 'config', 'rietveld.server',
655 'gerrit.chromium.org'],), ''), 666 'gerrit.chromium.org'],), ''),
656 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), 667 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''),
657 ((['git', 'config', '--unset-all', 668 ((['git', 'config', '--unset-all',
658 'rietveld.private'],), ''), 669 'rietveld.private'],), ''),
659 ((['git', 'config', '--unset-all', 670 ((['git', 'config', '--unset-all',
660 'rietveld.tree-status-url'],), ''), 671 'rietveld.tree-status-url'],), ''),
661 ((['git', 'config', '--unset-all', 672 ((['git', 'config', '--unset-all',
662 'rietveld.viewvc-url'],), ''), 673 'rietveld.viewvc-url'],), ''),
663 ((['git', 'config', 'gerrit.host', 674 ((['git', 'config', 'gerrit.host',
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 obj = git_cl.ChangeDescription(orig) 728 obj = git_cl.ChangeDescription(orig)
718 obj.update_reviewers(reviewers) 729 obj.update_reviewers(reviewers)
719 actual.append(obj.description) 730 actual.append(obj.description)
720 self.assertEqual(expected, actual) 731 self.assertEqual(expected, actual)
721 732
722 733
723 if __name__ == '__main__': 734 if __name__ == '__main__':
724 git_cl.logging.basicConfig( 735 git_cl.logging.basicConfig(
725 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 736 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
726 unittest.main() 737 unittest.main()
OLDNEW
« git_cl.py ('K') | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698