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 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 'refs/changes/56/123456/1'],), ''), | 1144 'refs/changes/56/123456/1'],), ''), |
1145 ((['git', 'cherry-pick', 'FETCH_HEAD'],), | 1145 ((['git', 'cherry-pick', 'FETCH_HEAD'],), |
1146 '', subprocess2.CalledProcessError(1, '', '', '', '')), | 1146 '', subprocess2.CalledProcessError(1, '', '', '', '')), |
1147 ((['DieWithError', 'git cherry-pick FETCH_HEAD" failed.\n'],), | 1147 ((['DieWithError', 'git cherry-pick FETCH_HEAD" failed.\n'],), |
1148 '', SystemExitMock()), | 1148 '', SystemExitMock()), |
1149 ] | 1149 ] |
1150 with self.assertRaises(SystemExitMock): | 1150 with self.assertRaises(SystemExitMock): |
1151 git_cl.main(['patch', | 1151 git_cl.main(['patch', |
1152 'https://chromium-review.googlesource.com/#/c/123456/1']) | 1152 'https://chromium-review.googlesource.com/#/c/123456/1']) |
1153 | 1153 |
| 1154 def _checkout_calls(self): |
| 1155 return [ |
| 1156 ((['git', 'config', '--local', '--get-regexp', |
| 1157 'branch\\..*\\.rietveldissue'], ), |
| 1158 ('branch.retrying.rietveldissue 1111111111\n' |
| 1159 'branch.some-fix.rietveldissue 2222222222\n')), |
| 1160 ((['git', 'config', '--local', '--get-regexp', |
| 1161 'branch\\..*\\.gerritissue'], ), |
| 1162 ('branch.ger-branch.gerritissue 123456\n' |
| 1163 'branch.gbranch654.gerritissue 654321\n')), |
| 1164 ] |
| 1165 |
| 1166 def test_checkout_gerrit(self): |
| 1167 """Tests git cl checkout <issue>.""" |
| 1168 self.calls = self._checkout_calls() |
| 1169 self.calls += [((['git', 'checkout', 'ger-branch'], ), '')] |
| 1170 self.assertEqual(0, git_cl.main(['checkout', '123456'])) |
| 1171 |
| 1172 def test_checkout_rietveld(self): |
| 1173 """Tests git cl checkout <issue>.""" |
| 1174 self.calls = self._checkout_calls() |
| 1175 self.calls += [((['git', 'checkout', 'some-fix'], ), '')] |
| 1176 self.assertEqual(0, git_cl.main(['checkout', '2222222222'])) |
| 1177 |
| 1178 def test_checkout_not_found(self): |
| 1179 """Tests git cl checkout <issue>.""" |
| 1180 self.calls = self._checkout_calls() |
| 1181 self.assertEqual(1, git_cl.main(['checkout', '99999'])) |
| 1182 |
1154 | 1183 |
1155 if __name__ == '__main__': | 1184 if __name__ == '__main__': |
1156 git_cl.logging.basicConfig( | 1185 git_cl.logging.basicConfig( |
1157 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1186 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
1158 unittest.main() | 1187 unittest.main() |
OLD | NEW |