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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 test('ssh://chrome-review.source.com/#/c/123/4/', fail=True) | 201 test('ssh://chrome-review.source.com/#/c/123/4/', fail=True) |
202 # Rietveld. | 202 # Rietveld. |
203 test('https://codereview.source.com/123', | 203 test('https://codereview.source.com/123', |
204 123, None, 'codereview.source.com') | 204 123, None, 'codereview.source.com') |
205 test('https://codereview.source.com/www123', fail=True) | 205 test('https://codereview.source.com/www123', fail=True) |
206 # Gerrrit. | 206 # Gerrrit. |
207 test('https://chrome-review.source.com/c/123/4', | 207 test('https://chrome-review.source.com/c/123/4', |
208 123, 4, 'chrome-review.source.com') | 208 123, 4, 'chrome-review.source.com') |
209 test('https://chrome-review.source.com/bad/123/4', fail=True) | 209 test('https://chrome-review.source.com/bad/123/4', fail=True) |
210 | 210 |
| 211 def test_get_bug_line_value(self): |
| 212 self.assertEqual(git_cl._get_bug_line_value('', ''), '') |
| 213 self.assertEqual(git_cl._get_bug_line_value('', '123,v8:456'), '123,v8:456') |
| 214 self.assertEqual(git_cl._get_bug_line_value('v8', '456'), 'v8:456') |
| 215 self.assertEqual(git_cl._get_bug_line_value('v8', 'chromium:123,456'), |
| 216 'chromium:123,v8:456') |
| 217 |
211 | 218 |
212 class TestGitCl(TestCase): | 219 class TestGitCl(TestCase): |
213 def setUp(self): | 220 def setUp(self): |
214 super(TestGitCl, self).setUp() | 221 super(TestGitCl, self).setUp() |
215 self.calls = [] | 222 self.calls = [] |
216 self._calls_done = [] | 223 self._calls_done = [] |
217 self.mock(subprocess2, 'call', self._mocked_call) | 224 self.mock(subprocess2, 'call', self._mocked_call) |
218 self.mock(subprocess2, 'check_call', self._mocked_call) | 225 self.mock(subprocess2, 'check_call', self._mocked_call) |
219 self.mock(subprocess2, 'check_output', self._mocked_call) | 226 self.mock(subprocess2, 'check_output', self._mocked_call) |
220 self.mock(subprocess2, 'communicate', self._mocked_call) | 227 self.mock(subprocess2, 'communicate', self._mocked_call) |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 git_cl.main(['upload', '--send-mail']) | 688 git_cl.main(['upload', '--send-mail']) |
682 self.fail() | 689 self.fail() |
683 except SystemExit: | 690 except SystemExit: |
684 self.assertEqual( | 691 self.assertEqual( |
685 'Using 50% similarity for rename/copy detection. Override with ' | 692 'Using 50% similarity for rename/copy detection. Override with ' |
686 '--similarity.\n', | 693 '--similarity.\n', |
687 stdout.getvalue()) | 694 stdout.getvalue()) |
688 self.assertEqual( | 695 self.assertEqual( |
689 'Must specify reviewers to send email.\n', stderr.getvalue()) | 696 'Must specify reviewers to send email.\n', stderr.getvalue()) |
690 | 697 |
| 698 def test_bug_on_cmd(self): |
| 699 self._run_reviewer_test( |
| 700 ['--bug=500658,proj:123'], |
| 701 'desc\n\nBUG=500658,proj:123', |
| 702 '# Blah blah comment.\ndesc\n\nBUG=500658,proj:1234', |
| 703 'desc\n\nBUG=500658,proj:1234', |
| 704 []) |
| 705 |
691 def test_dcommit(self): | 706 def test_dcommit(self): |
692 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | 707 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
693 self.calls = ( | 708 self.calls = ( |
694 self._dcommit_calls_1() + | 709 self._dcommit_calls_1() + |
695 self._git_sanity_checks('fake_ancestor_sha', 'working') + | 710 self._git_sanity_checks('fake_ancestor_sha', 'working') + |
696 self._dcommit_calls_normal() + | 711 self._dcommit_calls_normal() + |
697 self._dcommit_calls_3()) | 712 self._dcommit_calls_3()) |
698 git_cl.main(['dcommit']) | 713 git_cl.main(['dcommit']) |
699 | 714 |
700 def test_dcommit_bypass_hooks(self): | 715 def test_dcommit_bypass_hooks(self): |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), | 1710 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), |
1696 ''), | 1711 ''), |
1697 ] | 1712 ] |
1698 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) | 1713 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) |
1699 | 1714 |
1700 | 1715 |
1701 if __name__ == '__main__': | 1716 if __name__ == '__main__': |
1702 git_cl.logging.basicConfig( | 1717 git_cl.logging.basicConfig( |
1703 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1718 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
1704 unittest.main() | 1719 unittest.main() |
OLD | NEW |