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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 description = 'Foo Bar\nR=reviewer@example.com' | 448 description = 'Foo Bar\nR=reviewer@example.com' |
449 self._run_reviewer_test( | 449 self._run_reviewer_test( |
450 ['--send-mail'], | 450 ['--send-mail'], |
451 'desc\n\nBUG=', | 451 'desc\n\nBUG=', |
452 description.strip('\n'), | 452 description.strip('\n'), |
453 description, | 453 description, |
454 ['--reviewers=reviewer@example.com', '--send_mail']) | 454 ['--reviewers=reviewer@example.com', '--send_mail']) |
455 | 455 |
456 def test_reviewer_send_mail_no_rev(self): | 456 def test_reviewer_send_mail_no_rev(self): |
457 # Fails without a reviewer. | 457 # Fails without a reviewer. |
458 class FileMock(object): | 458 stdout = StringIO.StringIO() |
459 buf = StringIO.StringIO() | 459 stderr = StringIO.StringIO() |
460 def write(self, content): | |
461 self.buf.write(content) | |
462 | |
463 mock = FileMock() | |
464 try: | 460 try: |
465 self.calls = self._upload_no_rev_calls(None, None) | 461 self.calls = self._upload_no_rev_calls(None, None) |
466 def RunEditor(desc, _, **kwargs): | 462 def RunEditor(desc, _, **kwargs): |
467 return desc | 463 return desc |
468 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) | 464 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) |
469 self.mock(sys, 'stderr', mock) | 465 self.mock(sys, 'stdout', stdout) |
| 466 self.mock(sys, 'stderr', stderr) |
470 git_cl.main(['upload', '--send-mail']) | 467 git_cl.main(['upload', '--send-mail']) |
471 self.fail() | 468 self.fail() |
472 except SystemExit: | 469 except SystemExit: |
473 self.assertEquals( | 470 self.assertEqual( |
474 'Must specify reviewers to send email.\n', mock.buf.getvalue()) | 471 'Using 50% similarity for rename/copy detection. Override with ' |
| 472 '--similarity.\n', |
| 473 stdout.getvalue()) |
| 474 self.assertEqual( |
| 475 'Must specify reviewers to send email.\n', stderr.getvalue()) |
475 | 476 |
476 def test_dcommit(self): | 477 def test_dcommit(self): |
477 self.calls = ( | 478 self.calls = ( |
478 self._dcommit_calls_1() + | 479 self._dcommit_calls_1() + |
479 self._git_sanity_checks('fake_ancestor_sha', 'working') + | 480 self._git_sanity_checks('fake_ancestor_sha', 'working') + |
480 self._dcommit_calls_normal() + | 481 self._dcommit_calls_normal() + |
481 self._dcommit_calls_3()) | 482 self._dcommit_calls_3()) |
482 git_cl.main(['dcommit']) | 483 git_cl.main(['dcommit']) |
483 | 484 |
484 def test_dcommit_bypass_hooks(self): | 485 def test_dcommit_bypass_hooks(self): |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 obj = git_cl.ChangeDescription(orig) | 686 obj = git_cl.ChangeDescription(orig) |
686 obj.update_reviewers(reviewers) | 687 obj.update_reviewers(reviewers) |
687 actual.append(obj.description) | 688 actual.append(obj.description) |
688 self.assertEqual(expected, actual) | 689 self.assertEqual(expected, actual) |
689 | 690 |
690 | 691 |
691 if __name__ == '__main__': | 692 if __name__ == '__main__': |
692 git_cl.logging.basicConfig( | 693 git_cl.logging.basicConfig( |
693 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 694 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
694 unittest.main() | 695 unittest.main() |
OLD | NEW |