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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 ((['git', 'config', 'user.email'],), 'me@example.com'), | 386 ((['git', 'config', 'user.email'],), 'me@example.com'), |
387 ((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 387 ((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
388 '-C50', '-l100000', 'master...'],), | 388 '-C50', '-l100000', 'master...'],), |
389 '+dat'), | 389 '+dat'), |
390 ] | 390 ] |
391 | 391 |
392 @staticmethod | 392 @staticmethod |
393 def _gerrit_upload_calls(description, reviewers): | 393 def _gerrit_upload_calls(description, reviewers): |
394 calls = [ | 394 calls = [ |
395 ((['git', 'log', '--pretty=format:%s\n\n%b', 'master..'],), | 395 ((['git', 'log', '--pretty=format:%s\n\n%b', 'master..'],), |
396 description), | 396 description) |
397 ] | |
398 if git_cl.CHANGE_ID_STR not in description: | |
cmp
2012/10/20 22:42:31
CHANGE_ID_STR -> CHANGE_ID here, too
Siva Chandra
2012/10/22 07:13:56
Done.
| |
399 calls += [ | |
400 ((['git', 'log', '--pretty=format:%s\n\n%b', 'master..'],), | |
401 description), | |
402 ((['git', 'commit', '--amend', '-m', description],), | |
403 ''), | |
404 ((['git', 'log', '--pretty=format:%s\n\n%b', 'master..'],), | |
405 description) | |
406 ] | |
407 calls += [ | |
397 ((['git', 'config', 'rietveld.cc'],), '') | 408 ((['git', 'config', 'rietveld.cc'],), '') |
398 ] | 409 ] |
399 receive_pack = '--receive-pack=git receive-pack ' | 410 receive_pack = '--receive-pack=git receive-pack ' |
400 receive_pack += '--cc=joe@example.com' # from watch list | 411 receive_pack += '--cc=joe@example.com' # from watch list |
401 if reviewers: | 412 if reviewers: |
402 receive_pack += ' ' | 413 receive_pack += ' ' |
403 receive_pack += ' '.join(['--reviewer=' + email for email in reviewers]) | 414 receive_pack += ' '.join(['--reviewer=' + email for email in reviewers]) |
404 receive_pack += '' | 415 receive_pack += '' |
405 calls += [ | 416 calls += [ |
406 ((['git', 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],), | 417 ((['git', 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],), |
407 '') | 418 '') |
408 ] | 419 ] |
409 return calls | 420 return calls |
410 | 421 |
411 def _run_gerrit_reviewer_test( | 422 def _run_gerrit_upload_test( |
412 self, | 423 self, |
413 upload_args, | 424 upload_args, |
414 description, | 425 description, |
415 reviewers): | 426 reviewers): |
416 """Generic gerrit reviewer test framework.""" | 427 """Generic gerrit upload test framework.""" |
417 self.calls = self._gerrit_base_calls() | 428 self.calls = self._gerrit_base_calls() |
418 self.calls += self._gerrit_upload_calls(description, reviewers) | 429 self.calls += self._gerrit_upload_calls(description, reviewers) |
419 git_cl.main(['upload'] + upload_args) | 430 git_cl.main(['upload'] + upload_args) |
420 | 431 |
421 def test_gerrit_no_reviewer(self): | 432 def test_gerrit_upload_without_change_id(self): |
422 self._run_gerrit_reviewer_test( | 433 self._run_gerrit_upload_test( |
423 [], | 434 [], |
424 'desc\n\nBUG=\n', | 435 'desc\n\nBUG=\n', |
425 []) | 436 []) |
426 | 437 |
438 def test_gerrit_no_reviewer(self): | |
439 self._run_gerrit_upload_test( | |
440 [], | |
441 'desc\n\nBUG=\nChange-Id:123456789\n', | |
442 []) | |
443 | |
427 def test_gerrit_reviewers_cmd_line(self): | 444 def test_gerrit_reviewers_cmd_line(self): |
428 self._run_gerrit_reviewer_test( | 445 self._run_gerrit_upload_test( |
429 ['-r', 'foo@example.com'], | 446 ['-r', 'foo@example.com'], |
430 'desc\n\nBUG=\n', | 447 'desc\n\nBUG=\nChange-Id:123456789', |
431 ['foo@example.com']) | 448 ['foo@example.com']) |
432 | 449 |
433 def test_gerrit_reviewer_multiple(self): | 450 def test_gerrit_reviewer_multiple(self): |
434 self._run_gerrit_reviewer_test( | 451 self._run_gerrit_upload_test( |
435 [], | 452 [], |
436 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n', | 453 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n' |
454 'Change-Id:123456789\n', | |
437 ['reviewer@example.com', 'another@example.com']) | 455 ['reviewer@example.com', 'another@example.com']) |
438 | 456 |
439 | 457 |
440 def test_config_gerrit_download_hook(self): | 458 def test_config_gerrit_download_hook(self): |
441 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) | 459 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) |
442 def ParseCodereviewSettingsContent(content): | 460 def ParseCodereviewSettingsContent(content): |
443 keyvals = {} | 461 keyvals = {} |
444 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' | 462 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' |
445 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' | 463 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' |
446 keyvals['GERRIT_PORT'] = '29418' | 464 keyvals['GERRIT_PORT'] = '29418' |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 ((['git', 'config', 'rietveld.viewvc-url'],), ''), | 507 ((['git', 'config', 'rietveld.viewvc-url'],), ''), |
490 (('ViewVC URL:',), ''), | 508 (('ViewVC URL:',), ''), |
491 # DownloadHooks(True) | 509 # DownloadHooks(True) |
492 ((commit_msg_path, os.X_OK,), True), | 510 ((commit_msg_path, os.X_OK,), True), |
493 ] | 511 ] |
494 git_cl.main(['config']) | 512 git_cl.main(['config']) |
495 | 513 |
496 | 514 |
497 if __name__ == '__main__': | 515 if __name__ == '__main__': |
498 unittest.main() | 516 unittest.main() |
OLD | NEW |