OLD | NEW |
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 private_call = [ | 197 private_call = [ |
198 ((['git', 'config', 'rietveld.private'],), '')] | 198 ((['git', 'config', 'rietveld.private'],), '')] |
199 | 199 |
200 return [ | 200 return [ |
201 ((['git', 'config', 'core.editor'],), ''), | 201 ((['git', 'config', 'core.editor'],), ''), |
202 ] + cc_call + private_call + [ | 202 ] + cc_call + private_call + [ |
203 ((['git', 'config', 'branch.master.base-url'],), ''), | 203 ((['git', 'config', 'branch.master.base-url'],), ''), |
204 ((['git', | 204 ((['git', |
205 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | 205 'config', '--local', '--get-regexp', '^svn-remote\\.'],), |
206 (('', None), 0)), | 206 (('', None), 0)), |
| 207 ((['git', 'rev-parse', '--show-cdup'],), ''), |
207 ((['git', 'svn', 'info'],), ''), | 208 ((['git', 'svn', 'info'],), ''), |
208 ((['git', | 209 ((['git', |
209 'config', 'branch.master.rietveldissue', '1'],), ''), | 210 'config', 'branch.master.rietveldissue', '1'],), ''), |
210 ((['git', 'config', 'branch.master.rietveldserver', | 211 ((['git', 'config', 'branch.master.rietveldserver', |
211 'https://codereview.example.com'],), ''), | 212 'https://codereview.example.com'],), ''), |
212 ((['git', | 213 ((['git', |
213 'config', 'branch.master.rietveldpatchset', '2'],), ''), | 214 'config', 'branch.master.rietveldpatchset', '2'],), ''), |
214 ((['git', 'rev-parse', 'HEAD'],), 'hash'), | 215 ((['git', 'rev-parse', 'HEAD'],), 'hash'), |
215 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), | 216 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), |
216 ((['git', | 217 ((['git', |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 'config', 'branch.working.rietveldissue'],), '12345'), | 312 'config', 'branch.working.rietveldissue'],), '12345'), |
312 ((['git', 'config', 'branch.working.rietveldserver'],), | 313 ((['git', 'config', 'branch.working.rietveldserver'],), |
313 'codereview.example.com'), | 314 'codereview.example.com'), |
314 ((['git', 'config', 'rietveld.tree-status-url'],), ''), | 315 ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
315 (('GitClHooksBypassedCommit', | 316 (('GitClHooksBypassedCommit', |
316 'Issue https://codereview.example.com/12345 bypassed hook when ' | 317 'Issue https://codereview.example.com/12345 bypassed hook when ' |
317 'committing (tree status was "unset")'), None), | 318 'committing (tree status was "unset")'), None), |
318 ] | 319 ] |
319 | 320 |
320 @classmethod | 321 @classmethod |
321 def _dcommit_calls_3(cls, is_first_call): | 322 def _dcommit_calls_3(cls): |
322 calls = [ | 323 return [ |
323 ((['git', | 324 ((['git', |
324 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 325 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
325 '-l100000', '-C50', 'fake_ancestor_sha', | 326 '-l100000', '-C50', 'fake_ancestor_sha', |
326 'refs/heads/working'],), | 327 'refs/heads/working'],), |
327 (' PRESUBMIT.py | 2 +-\n' | 328 (' PRESUBMIT.py | 2 +-\n' |
328 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), | 329 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), |
329 (('About to commit; enter to confirm.',), None), | 330 (('About to commit; enter to confirm.',), None), |
330 ((['git', 'show-ref', '--quiet', '--verify', | 331 ((['git', 'show-ref', '--quiet', '--verify', |
331 'refs/heads/git-cl-commit'],), | 332 'refs/heads/git-cl-commit'],), |
332 (('', None), 0)), | 333 (('', None), 0)), |
333 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | 334 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
334 ((['git', 'show-ref', '--quiet', '--verify', | 335 ((['git', 'show-ref', '--quiet', '--verify', |
335 'refs/heads/git-cl-cherry-pick'],), ''), | 336 'refs/heads/git-cl-cherry-pick'],), ''), |
336 ] | 337 ((['git', 'rev-parse', '--show-cdup'],), '\n'), |
337 if is_first_call: | |
338 calls += [ | |
339 ((['git', 'rev-parse', '--show-cdup'],), '\n'), | |
340 ] | |
341 calls += [ | |
342 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), | 338 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), |
343 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), | 339 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), |
344 ((['git', 'commit', '-m', | 340 ((['git', 'commit', '-m', |
345 'Issue: 12345\n\nR=john@chromium.org\n\n' | 341 'Issue: 12345\n\nR=john@chromium.org\n\n' |
346 'Review URL: https://codereview.example.com/12345'],), | 342 'Review URL: https://codereview.example.com/12345'],), |
347 ''), | 343 ''), |
348 ((['git', | 344 ((['git', |
349 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), | 345 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), |
350 (('', None), 0)), | 346 (('', None), 0)), |
351 ((['git', 'checkout', '-q', 'working'],), ''), | 347 ((['git', 'checkout', '-q', 'working'],), ''), |
352 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | 348 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
353 ] | 349 ] |
354 return calls | |
355 | 350 |
356 @staticmethod | 351 @staticmethod |
357 def _cmd_line(description, args, similarity, find_copies, private): | 352 def _cmd_line(description, args, similarity, find_copies, private): |
358 """Returns the upload command line passed to upload.RealMain().""" | 353 """Returns the upload command line passed to upload.RealMain().""" |
359 return [ | 354 return [ |
360 'upload', '--assume_yes', '--server', | 355 'upload', '--assume_yes', '--server', |
361 'https://codereview.example.com', | 356 'https://codereview.example.com', |
362 '--message', description | 357 '--message', description |
363 ] + args + [ | 358 ] + args + [ |
364 '--cc', 'joe@example.com', | 359 '--cc', 'joe@example.com', |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 '--similarity.\n', | 502 '--similarity.\n', |
508 stdout.getvalue()) | 503 stdout.getvalue()) |
509 self.assertEqual( | 504 self.assertEqual( |
510 'Must specify reviewers to send email.\n', stderr.getvalue()) | 505 'Must specify reviewers to send email.\n', stderr.getvalue()) |
511 | 506 |
512 def test_dcommit(self): | 507 def test_dcommit(self): |
513 self.calls = ( | 508 self.calls = ( |
514 self._dcommit_calls_1() + | 509 self._dcommit_calls_1() + |
515 self._git_sanity_checks('fake_ancestor_sha', 'working') + | 510 self._git_sanity_checks('fake_ancestor_sha', 'working') + |
516 self._dcommit_calls_normal() + | 511 self._dcommit_calls_normal() + |
517 self._dcommit_calls_3(False)) | 512 self._dcommit_calls_3()) |
518 git_cl.main(['dcommit']) | 513 git_cl.main(['dcommit']) |
519 | 514 |
520 def test_dcommit_bypass_hooks(self): | 515 def test_dcommit_bypass_hooks(self): |
521 self.calls = ( | 516 self.calls = ( |
522 self._dcommit_calls_1() + | 517 self._dcommit_calls_1() + |
523 self._dcommit_calls_bypassed() + | 518 self._dcommit_calls_bypassed() + |
524 self._dcommit_calls_3(True)) | 519 self._dcommit_calls_3()) |
525 git_cl.main(['dcommit', '--bypass-hooks']) | 520 git_cl.main(['dcommit', '--bypass-hooks']) |
526 | 521 |
527 | 522 |
528 @classmethod | 523 @classmethod |
529 def _gerrit_base_calls(cls): | 524 def _gerrit_base_calls(cls): |
530 return [ | 525 return [ |
531 ((['git', 'config', 'rietveld.autoupdate'],), | 526 ((['git', 'config', 'rietveld.autoupdate'],), |
532 ''), | 527 ''), |
533 ((['git', | 528 ((['git', |
534 'config', 'rietveld.server'],), 'codereview.example.com'), | 529 'config', 'rietveld.server'],), 'codereview.example.com'), |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 obj = git_cl.ChangeDescription(orig) | 733 obj = git_cl.ChangeDescription(orig) |
739 obj.update_reviewers(reviewers) | 734 obj.update_reviewers(reviewers) |
740 actual.append(obj.description) | 735 actual.append(obj.description) |
741 self.assertEqual(expected, actual) | 736 self.assertEqual(expected, actual) |
742 | 737 |
743 | 738 |
744 if __name__ == '__main__': | 739 if __name__ == '__main__': |
745 git_cl.logging.basicConfig( | 740 git_cl.logging.basicConfig( |
746 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 741 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
747 unittest.main() | 742 unittest.main() |
OLD | NEW |