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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 def tearDown(self): | 91 def tearDown(self): |
92 if not self.has_failed(): | 92 if not self.has_failed(): |
93 self.assertEquals([], self.calls) | 93 self.assertEquals([], self.calls) |
94 super(TestGitCl, self).tearDown() | 94 super(TestGitCl, self).tearDown() |
95 | 95 |
96 def _mocked_call(self, *args, **kwargs): | 96 def _mocked_call(self, *args, **kwargs): |
97 self.assertTrue( | 97 self.assertTrue( |
98 self.calls, | 98 self.calls, |
99 '@%d Expected: <Missing> Actual: %r' % (self._calls_done, args)) | 99 '@%d Expected: <Missing> Actual: %r' % (self._calls_done, args)) |
100 expected_args, result = self.calls.pop(0) | 100 expected_args, result = self.calls.pop(0) |
101 self.assertEquals( | 101 # Also logs otherwise it could get caught in a try/finally and be hard to |
102 expected_args, | 102 # diagnose. |
103 args, | 103 if expected_args != args: |
104 '@%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) |
| 107 self.fail(msg) |
106 self._calls_done += 1 | 108 self._calls_done += 1 |
107 return result | 109 return result |
108 | 110 |
109 @classmethod | 111 @classmethod |
110 def _upload_calls(cls, similarity, find_copies): | 112 def _upload_calls(cls, similarity, find_copies): |
111 return (cls._git_base_calls(similarity, find_copies) + | 113 return (cls._git_base_calls(similarity, find_copies) + |
112 cls._git_upload_calls()) | 114 cls._git_upload_calls()) |
113 | 115 |
114 @classmethod | 116 @classmethod |
115 def _git_base_calls(cls, similarity, find_copies): | 117 def _git_base_calls(cls, similarity, find_copies): |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 ((['git', 'show-ref', '--quiet', '--verify', | 279 ((['git', 'show-ref', '--quiet', '--verify', |
278 'refs/heads/git-cl-commit'],), | 280 'refs/heads/git-cl-commit'],), |
279 (('', None), 0)), | 281 (('', None), 0)), |
280 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | 282 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
281 ((['git', 'show-ref', '--quiet', '--verify', | 283 ((['git', 'show-ref', '--quiet', '--verify', |
282 'refs/heads/git-cl-cherry-pick'],), ''), | 284 'refs/heads/git-cl-cherry-pick'],), ''), |
283 ((['git', 'rev-parse', '--show-cdup'],), '\n'), | 285 ((['git', 'rev-parse', '--show-cdup'],), '\n'), |
284 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), | 286 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), |
285 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), | 287 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), |
286 ((['git', 'commit', '-m', | 288 ((['git', 'commit', '-m', |
287 'Issue: 12345\n\n' | 289 'Issue: 12345\n\nR=john@chromium.org\n\n' |
288 'Review URL: https://codereview.example.com/12345'],), | 290 'Review URL: https://codereview.example.com/12345'],), |
289 ''), | 291 ''), |
290 ((['git', 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), | 292 ((['git', 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), |
291 (('', None), 0)), | 293 (('', None), 0)), |
292 ((['git', 'checkout', '-q', 'working'],), ''), | 294 ((['git', 'checkout', '-q', 'working'],), ''), |
293 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | 295 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
294 ] | 296 ] |
295 | 297 |
296 @staticmethod | 298 @staticmethod |
297 def _cmd_line(description, args, similarity, find_copies): | 299 def _cmd_line(description, args, similarity, find_copies): |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 obj = git_cl.ChangeDescription(orig) | 630 obj = git_cl.ChangeDescription(orig) |
629 obj.update_reviewers(reviewers) | 631 obj.update_reviewers(reviewers) |
630 actual.append(obj.description) | 632 actual.append(obj.description) |
631 self.assertEqual(expected, actual) | 633 self.assertEqual(expected, actual) |
632 | 634 |
633 | 635 |
634 if __name__ == '__main__': | 636 if __name__ == '__main__': |
635 git_cl.logging.basicConfig( | 637 git_cl.logging.basicConfig( |
636 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 638 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
637 unittest.main() | 639 unittest.main() |
OLD | NEW |