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

Side by Side Diff: tests/git_cl_test.py

Issue 15650014: Add --private option to git_cl.py (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: Created 7 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 # diagnose. 102 # diagnose.
103 if expected_args != args: 103 if expected_args != args:
104 msg = '@%d Expected: %r Actual: %r' % ( 104 msg = '@%d Expected: %r Actual: %r' % (
105 self._calls_done, expected_args, args) 105 self._calls_done, expected_args, args)
106 git_cl.logging.error(msg) 106 git_cl.logging.error(msg)
107 self.fail(msg) 107 self.fail(msg)
108 self._calls_done += 1 108 self._calls_done += 1
109 return result 109 return result
110 110
111 @classmethod 111 @classmethod
112 def _upload_calls(cls, similarity, find_copies): 112 def _upload_calls(cls, similarity, find_copies, private):
113 return (cls._git_base_calls(similarity, find_copies) + 113 return (cls._git_base_calls(similarity, find_copies) +
114 cls._git_upload_calls()) 114 cls._git_upload_calls(private))
115 115
116 @classmethod 116 @classmethod
117 def _upload_no_rev_calls(cls, similarity, find_copies): 117 def _upload_no_rev_calls(cls, similarity, find_copies):
118 return (cls._git_base_calls(similarity, find_copies) + 118 return (cls._git_base_calls(similarity, find_copies) +
119 cls._git_upload_no_rev_calls()) 119 cls._git_upload_no_rev_calls())
120 120
121 @classmethod 121 @classmethod
122 def _git_base_calls(cls, similarity, find_copies): 122 def _git_base_calls(cls, similarity, find_copies):
123 if similarity is None: 123 if similarity is None:
124 similarity = '50' 124 similarity = '50'
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 'desc\n'), 179 'desc\n'),
180 ] 180 ]
181 181
182 @classmethod 182 @classmethod
183 def _git_upload_no_rev_calls(cls): 183 def _git_upload_no_rev_calls(cls):
184 return [ 184 return [
185 ((['git', '--no-pager', 'config', 'core.editor'],), ''), 185 ((['git', '--no-pager', 'config', 'core.editor'],), ''),
186 ] 186 ]
187 187
188 @classmethod 188 @classmethod
189 def _git_upload_calls(cls): 189 def _git_upload_calls(cls, private):
190 if private:
191 private_call = []
192 else:
193 private_call = [
194 ((['git', '--no-pager', 'config', 'rietveld.private'],), '')]
195
190 return [ 196 return [
191 ((['git', '--no-pager', 'config', 'core.editor'],), ''), 197 ((['git', '--no-pager', 'config', 'core.editor'],), ''),
192 ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''), 198 ((['git', '--no-pager', 'config', 'rietveld.cc'],), '')
193 ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''), 199 ] + private_call + [
194 ((['git', '--no-pager', 200 ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''),
195 'config', '--local', '--get-regexp', '^svn-remote\\.'],), 201 ((['git', '--no-pager',
196 (('', None), 0)), 202 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
197 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), 203 (('', None), 0)),
198 ((['git', '--no-pager', 'svn', 'info'],), ''), 204 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
199 ((['git', '--no-pager', 205 ((['git', '--no-pager', 'svn', 'info'],), ''),
200 'config', 'branch.master.rietveldissue', '1'],), ''), 206 ((['git', '--no-pager',
201 ((['git', '--no-pager', 'config', 'branch.master.rietveldserver', 207 'config', 'branch.master.rietveldissue', '1'],), ''),
202 'https://codereview.example.com'],), ''), 208 ((['git', '--no-pager', 'config', 'branch.master.rietveldserver',
203 ((['git', '--no-pager', 209 'https://codereview.example.com'],), ''),
204 'config', 'branch.master.rietveldpatchset', '2'],), ''), 210 ((['git', '--no-pager',
205 ((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'), 211 'config', 'branch.master.rietveldpatchset', '2'],), ''),
206 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'), 212 ((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'),
207 ((['git', '--no-pager', 213 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'),
208 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), 214 ((['git', '--no-pager',
215 'config', 'branch.hash.last-upload-hash', 'hash'],), ''),
209 ] 216 ]
210 217
211 @staticmethod 218 @staticmethod
212 def _git_sanity_checks(diff_base, working_branch): 219 def _git_sanity_checks(diff_base, working_branch):
213 fake_ancestor = 'fake_ancestor' 220 fake_ancestor = 'fake_ancestor'
214 fake_cl = 'fake_cl_for_patch' 221 fake_cl = 'fake_cl_for_patch'
215 return [ 222 return [
216 # Calls to verify branch point is ancestor 223 # Calls to verify branch point is ancestor
217 ((['git', '--no-pager', 224 ((['git', '--no-pager',
218 'rev-parse', '--verify', diff_base],), fake_ancestor), 225 'rev-parse', '--verify', diff_base],), fake_ancestor),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 'Review URL: https://codereview.example.com/12345'],), 336 'Review URL: https://codereview.example.com/12345'],),
330 ''), 337 ''),
331 ((['git', '--no-pager', 338 ((['git', '--no-pager',
332 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), 339 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],),
333 (('', None), 0)), 340 (('', None), 0)),
334 ((['git', '--no-pager', 'checkout', '-q', 'working'],), ''), 341 ((['git', '--no-pager', 'checkout', '-q', 'working'],), ''),
335 ((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''), 342 ((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''),
336 ] 343 ]
337 344
338 @staticmethod 345 @staticmethod
339 def _cmd_line(description, args, similarity, find_copies): 346 def _cmd_line(description, args, similarity, find_copies, private):
340 """Returns the upload command line passed to upload.RealMain().""" 347 """Returns the upload command line passed to upload.RealMain()."""
341 return [ 348 return [
342 'upload', '--assume_yes', '--server', 349 'upload', '--assume_yes', '--server',
343 'https://codereview.example.com', 350 'https://codereview.example.com',
344 '--message', description 351 '--message', description
345 ] + args + [ 352 ] + args + [
346 '--cc', 'joe@example.com', 353 '--cc', 'joe@example.com',
354 ] + (['--private'] if private else []) + [
347 '--git_similarity', similarity or '50' 355 '--git_similarity', similarity or '50'
348 ] + (['--git_no_find_copies'] if find_copies == False else []) + [ 356 ] + (['--git_no_find_copies'] if find_copies == False else []) + [
349 'fake_ancestor_sha', 'HEAD' 357 'fake_ancestor_sha', 'HEAD'
350 ] 358 ]
351 359
352 def _run_reviewer_test( 360 def _run_reviewer_test(
353 self, 361 self,
354 upload_args, 362 upload_args,
355 expected_description, 363 expected_description,
356 returned_description, 364 returned_description,
357 final_description, 365 final_description,
358 reviewers): 366 reviewers,
367 private=False):
359 """Generic reviewer test framework.""" 368 """Generic reviewer test framework."""
360 try: 369 try:
361 similarity = upload_args[upload_args.index('--similarity')+1] 370 similarity = upload_args[upload_args.index('--similarity')+1]
362 except ValueError: 371 except ValueError:
363 similarity = None 372 similarity = None
364 373
365 if '--find-copies' in upload_args: 374 if '--find-copies' in upload_args:
366 find_copies = True 375 find_copies = True
367 elif '--no-find-copies' in upload_args: 376 elif '--no-find-copies' in upload_args:
368 find_copies = False 377 find_copies = False
369 else: 378 else:
370 find_copies = None 379 find_copies = None
371 380
372 self.calls = self._upload_calls(similarity, find_copies) 381 private = '--private' in upload_args
382
383 self.calls = self._upload_calls(similarity, find_copies, private)
373 def RunEditor(desc, _, **kwargs): 384 def RunEditor(desc, _, **kwargs):
374 self.assertEquals( 385 self.assertEquals(
375 '# Enter a description of the change.\n' 386 '# Enter a description of the change.\n'
376 '# This will be displayed on the codereview site.\n' 387 '# This will be displayed on the codereview site.\n'
377 '# The first line will also be used as the subject of the review.\n' + 388 '# The first line will also be used as the subject of the review.\n' +
378 expected_description, 389 expected_description,
379 desc) 390 desc)
380 return returned_description 391 return returned_description
381 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) 392 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
382 def check_upload(args): 393 def check_upload(args):
383 cmd_line = self._cmd_line(final_description, reviewers, similarity, 394 cmd_line = self._cmd_line(final_description, reviewers, similarity,
384 find_copies) 395 find_copies, private)
385 self.assertEquals(cmd_line, args) 396 self.assertEquals(cmd_line, args)
386 return 1, 2 397 return 1, 2
387 self.mock(git_cl.upload, 'RealMain', check_upload) 398 self.mock(git_cl.upload, 'RealMain', check_upload)
388 git_cl.main(['upload'] + upload_args) 399 git_cl.main(['upload'] + upload_args)
389 400
390 def test_no_reviewer(self): 401 def test_no_reviewer(self):
391 self._run_reviewer_test( 402 self._run_reviewer_test(
392 [], 403 [],
393 'desc\n\nBUG=', 404 'desc\n\nBUG=',
394 '# Blah blah comment.\ndesc\n\nBUG=', 405 '# Blah blah comment.\ndesc\n\nBUG=',
395 'desc\n\nBUG=', 406 'desc\n\nBUG=',
396 []) 407 [])
397 408
398 def test_keep_similarity(self): 409 def test_keep_similarity(self):
399 self._run_reviewer_test( 410 self._run_reviewer_test(
400 ['--similarity', '70'], 411 ['--similarity', '70'],
401 'desc\n\nBUG=', 412 'desc\n\nBUG=',
402 '# Blah blah comment.\ndesc\n\nBUG=', 413 '# Blah blah comment.\ndesc\n\nBUG=',
403 'desc\n\nBUG=', 414 'desc\n\nBUG=',
404 []) 415 [])
405 416
406 def test_keep_find_copies(self): 417 def test_keep_find_copies(self):
407 self._run_reviewer_test( 418 self._run_reviewer_test(
408 ['--no-find-copies'], 419 ['--no-find-copies'],
409 'desc\n\nBUG=', 420 'desc\n\nBUG=',
410 '# Blah blah comment.\ndesc\n\nBUG=\n', 421 '# Blah blah comment.\ndesc\n\nBUG=\n',
411 'desc\n\nBUG=', 422 'desc\n\nBUG=',
412 []) 423 [])
413 424
425 def test_private(self):
426 self._run_reviewer_test(
427 ['--private'],
428 'desc\n\nBUG=',
429 '# Blah blah comment.\ndesc\n\nBUG=\n',
430 'desc\n\nBUG=',
431 [])
432
414 def test_reviewers_cmd_line(self): 433 def test_reviewers_cmd_line(self):
415 # Reviewer is passed as-is 434 # Reviewer is passed as-is
416 description = 'desc\n\nR=foo@example.com\nBUG=' 435 description = 'desc\n\nR=foo@example.com\nBUG='
417 self._run_reviewer_test( 436 self._run_reviewer_test(
418 ['-r' 'foo@example.com'], 437 ['-r' 'foo@example.com'],
419 description, 438 description,
420 '\n%s\n' % description, 439 '\n%s\n' % description,
421 description, 440 description,
422 ['--reviewers=foo@example.com']) 441 ['--reviewers=foo@example.com'])
423 442
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 return False 643 return False
625 # others paths, such as /usr/share/locale/.... 644 # others paths, such as /usr/share/locale/....
626 return True 645 return True
627 self.mock(git_cl.os.path, 'exists', Exists) 646 self.mock(git_cl.os.path, 'exists', Exists)
628 self.mock(git_cl, 'urlretrieve', self._mocked_call) 647 self.mock(git_cl, 'urlretrieve', self._mocked_call)
629 self.calls = [ 648 self.calls = [
630 ((['git', '--no-pager', 'config', 'rietveld.server', 649 ((['git', '--no-pager', 'config', 'rietveld.server',
631 'gerrit.chromium.org'],), ''), 650 'gerrit.chromium.org'],), ''),
632 ((['git', '--no-pager', 'config', '--unset-all', 'rietveld.cc'],), ''), 651 ((['git', '--no-pager', 'config', '--unset-all', 'rietveld.cc'],), ''),
633 ((['git', '--no-pager', 'config', '--unset-all', 652 ((['git', '--no-pager', 'config', '--unset-all',
653 'rietveld.private'],), ''),
654 ((['git', '--no-pager', 'config', '--unset-all',
634 'rietveld.tree-status-url'],), ''), 655 'rietveld.tree-status-url'],), ''),
635 ((['git', '--no-pager', 'config', '--unset-all', 656 ((['git', '--no-pager', 'config', '--unset-all',
636 'rietveld.viewvc-url'],), ''), 657 'rietveld.viewvc-url'],), ''),
637 ((['git', '--no-pager', 'config', 'gerrit.host', 658 ((['git', '--no-pager', 'config', 'gerrit.host',
638 'gerrit.chromium.org'],), ''), 659 'gerrit.chromium.org'],), ''),
639 ((['git', '--no-pager', 'config', 'gerrit.port', '29418'],), ''), 660 ((['git', '--no-pager', 'config', 'gerrit.port', '29418'],), ''),
640 # DownloadHooks(False) 661 # DownloadHooks(False)
641 ((['git', '--no-pager', 'config', 'gerrit.host'],), 662 ((['git', '--no-pager', 'config', 'gerrit.host'],),
642 'gerrit.chromium.org'), 663 'gerrit.chromium.org'),
643 ((['git', '--no-pager', 'config', 'rietveld.server'],), 664 ((['git', '--no-pager', 'config', 'rietveld.server'],),
644 'gerrit.chromium.org'), 665 'gerrit.chromium.org'),
645 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), 666 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
646 ((commit_msg_path, os.X_OK,), False), 667 ((commit_msg_path, os.X_OK,), False),
647 (('https://gerrit.chromium.org/tools/hooks/commit-msg', 668 (('https://gerrit.chromium.org/tools/hooks/commit-msg',
648 commit_msg_path,), ''), 669 commit_msg_path,), ''),
649 ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), 670 ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''),
650 # GetCodereviewSettingsInteractively 671 # GetCodereviewSettingsInteractively
651 ((['git', '--no-pager', 'config', 'rietveld.server'],), 672 ((['git', '--no-pager', 'config', 'rietveld.server'],),
652 'gerrit.chromium.org'), 673 'gerrit.chromium.org'),
653 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), 674 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',),
654 ''), 675 ''),
655 ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''), 676 ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''),
656 (('CC list:',), ''), 677 (('CC list:',), ''),
678 ((['git', '--no-pager', 'config', 'rietveld.private'],), ''),
679 (('Private flag (rietveld only):',), ''),
657 ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''), 680 ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''),
658 (('Tree status URL:',), ''), 681 (('Tree status URL:',), ''),
659 ((['git', '--no-pager', 'config', 'rietveld.viewvc-url'],), ''), 682 ((['git', '--no-pager', 'config', 'rietveld.viewvc-url'],), ''),
660 (('ViewVC URL:',), ''), 683 (('ViewVC URL:',), ''),
661 # DownloadHooks(True) 684 # DownloadHooks(True)
662 ((commit_msg_path, os.X_OK,), True), 685 ((commit_msg_path, os.X_OK,), True),
663 ] 686 ]
664 git_cl.main(['config']) 687 git_cl.main(['config'])
665 688
666 def test_update_reviewers(self): 689 def test_update_reviewers(self):
(...skipping 19 matching lines...) Expand all
686 obj = git_cl.ChangeDescription(orig) 709 obj = git_cl.ChangeDescription(orig)
687 obj.update_reviewers(reviewers) 710 obj.update_reviewers(reviewers)
688 actual.append(obj.description) 711 actual.append(obj.description)
689 self.assertEqual(expected, actual) 712 self.assertEqual(expected, actual)
690 713
691 714
692 if __name__ == '__main__': 715 if __name__ == '__main__':
693 git_cl.logging.basicConfig( 716 git_cl.logging.basicConfig(
694 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 717 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
695 unittest.main() 718 unittest.main()
OLDNEW
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698