Chromium Code Reviews| 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 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1086 ((['git', 'config', 'gerrit.host'],), ''), | 1086 ((['git', 'config', 'gerrit.host'],), ''), |
| 1087 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), | 1087 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 1088 ] | 1088 ] |
| 1089 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 1089 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
| 1090 | 1090 |
| 1091 def test_diff_when_dirty(self): | 1091 def test_diff_when_dirty(self): |
| 1092 # Do 'git cl diff' when local tree is dirty | 1092 # Do 'git cl diff' when local tree is dirty |
| 1093 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) | 1093 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) |
| 1094 self.assertNotEqual(git_cl.main(['diff']), 0) | 1094 self.assertNotEqual(git_cl.main(['diff']), 0) |
| 1095 | 1095 |
| 1096 def _patch_common(self, is_gerrit=False): | 1096 def _patch_common(self, is_gerrit=False, force_codereview=False): |
| 1097 self.mock(git_cl._RietveldChangelistImpl, 'GetMostRecentPatchset', | 1097 self.mock(git_cl._RietveldChangelistImpl, 'GetMostRecentPatchset', |
| 1098 lambda x: '60001') | 1098 lambda x: '60001') |
| 1099 self.mock(git_cl._RietveldChangelistImpl, 'GetPatchSetDiff', | 1099 self.mock(git_cl._RietveldChangelistImpl, 'GetPatchSetDiff', |
| 1100 lambda *args: None) | 1100 lambda *args: None) |
| 1101 self.mock(git_cl._GerritChangelistImpl, '_GetChangeDetail', | 1101 self.mock(git_cl._GerritChangelistImpl, '_GetChangeDetail', |
| 1102 lambda *args: { | 1102 lambda *args: { |
| 1103 'current_revision': '7777777777', | 1103 'current_revision': '7777777777', |
| 1104 'revisions': { | 1104 'revisions': { |
| 1105 '1111111111': { | 1105 '1111111111': { |
| 1106 '_number': 1, | 1106 '_number': 1, |
| 1107 'fetch': {'http': { | 1107 'fetch': {'http': { |
| 1108 'url': 'https://chromium.googlesource.com/my/repo', | 1108 'url': 'https://chromium.googlesource.com/my/repo', |
| 1109 'ref': 'refs/changes/56/123456/1', | 1109 'ref': 'refs/changes/56/123456/1', |
| 1110 }}, | 1110 }}, |
| 1111 }, | 1111 }, |
| 1112 '7777777777': { | 1112 '7777777777': { |
| 1113 '_number': 7, | 1113 '_number': 7, |
| 1114 'fetch': {'http': { | 1114 'fetch': {'http': { |
| 1115 'url': 'https://chromium.googlesource.com/my/repo', | 1115 'url': 'https://chromium.googlesource.com/my/repo', |
| 1116 'ref': 'refs/changes/56/123456/7', | 1116 'ref': 'refs/changes/56/123456/7', |
| 1117 }}, | 1117 }}, |
| 1118 }, | 1118 }, |
| 1119 }, | 1119 }, |
| 1120 }) | 1120 }) |
| 1121 self.mock(git_cl.Changelist, 'GetDescription', | 1121 self.mock(git_cl.Changelist, 'GetDescription', |
| 1122 lambda *args: 'Description') | 1122 lambda *args: 'Description') |
| 1123 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) | 1123 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) |
| 1124 | 1124 |
| 1125 self.calls = [ | 1125 if not force_codereview: |
| 1126 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 1126 # These calls detect codereview to use. |
| 1127 ((['git', 'config', 'branch.master.rietveldissue'],), ''), | 1127 self.calls = [ |
| 1128 ((['git', 'config', 'branch.master.gerritissue'],), ''), | 1128 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 1129 ((['git', 'config', 'rietveld.autoupdate'],), ''), | 1129 ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
|
tandrii(chromium)
2016/04/13 18:13:46
if this line had '12345' at the end, it'd tell git
| |
| 1130 ] | 1130 ((['git', 'config', 'branch.master.gerritissue'],), ''), |
| 1131 ((['git', 'config', 'rietveld.autoupdate'],), ''), | |
| 1132 ] | |
| 1133 else: | |
| 1134 self.calls = [] | |
| 1135 | |
| 1131 if is_gerrit: | 1136 if is_gerrit: |
| 1132 self.calls += [ | 1137 if not force_codereview: |
| 1133 ((['git', 'config', 'gerrit.host'],), 'true'), | 1138 self.calls += [ |
| 1134 ] | 1139 ((['git', 'config', 'gerrit.host'],), 'true'), |
| 1140 ] | |
| 1135 else: | 1141 else: |
| 1136 self.calls += [ | 1142 self.calls += [ |
| 1137 ((['git', 'config', 'gerrit.host'],), ''), | 1143 ((['git', 'config', 'gerrit.host'],), ''), |
| 1138 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), | 1144 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 1139 ((['git', 'rev-parse', '--show-cdup'],), ''), | 1145 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 1140 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''), | 1146 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''), |
| 1141 ] | 1147 ] |
| 1142 | 1148 |
| 1143 def test_patch_successful(self): | 1149 def test_patch_successful(self): |
| 1144 self._patch_common() | 1150 self._patch_common() |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1175 ((['git', 'config', 'branch.master.merge'],), 'master'), | 1181 ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 1176 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 1182 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 1177 ((['git', 'config', 'remote.origin.url'],), | 1183 ((['git', 'config', 'remote.origin.url'],), |
| 1178 'https://chromium.googlesource.com/my/repo'), | 1184 'https://chromium.googlesource.com/my/repo'), |
| 1179 ((['git', 'config', 'branch.master.gerritserver', | 1185 ((['git', 'config', 'branch.master.gerritserver', |
| 1180 'https://chromium-review.googlesource.com'],), ''), | 1186 'https://chromium-review.googlesource.com'],), ''), |
| 1181 ((['git', 'config', 'branch.master.gerritpatchset', '7'],), ''), | 1187 ((['git', 'config', 'branch.master.gerritpatchset', '7'],), ''), |
| 1182 ] | 1188 ] |
| 1183 self.assertEqual(git_cl.main(['patch', '123456']), 0) | 1189 self.assertEqual(git_cl.main(['patch', '123456']), 0) |
| 1184 | 1190 |
| 1191 def test_patch_force_codereview(self): | |
| 1192 self._patch_common(is_gerrit=True, force_codereview=True) | |
|
Sergiy Byelozyorov
2016/04/13 17:18:59
can you please try to create mock rietveld CL here
tandrii(chromium)
2016/04/13 18:13:46
Ha, good comment/idea! However, the calls below is
Sergiy Byelozyorov
2016/04/13 18:21:55
Acknowledged.
| |
| 1193 self.calls += [ | |
| 1194 ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', | |
| 1195 'refs/changes/56/123456/7'],), ''), | |
| 1196 ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), | |
| 1197 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | |
| 1198 ((['git', 'config', 'branch.master.gerritissue', '123456'],), ''), | |
| 1199 ((['git', 'config', 'branch.master.gerritserver'],), ''), | |
| 1200 ((['git', 'config', 'branch.master.merge'],), 'master'), | |
| 1201 ((['git', 'config', 'branch.master.remote'],), 'origin'), | |
| 1202 ((['git', 'config', 'remote.origin.url'],), | |
| 1203 'https://chromium.googlesource.com/my/repo'), | |
| 1204 ((['git', 'config', 'branch.master.gerritserver', | |
| 1205 'https://chromium-review.googlesource.com'],), ''), | |
| 1206 ((['git', 'config', 'branch.master.gerritpatchset', '7'],), ''), | |
| 1207 ] | |
| 1208 self.assertEqual(git_cl.main(['patch', '--gerrit', '123456']), 0) | |
| 1209 | |
| 1185 def test_gerrit_patch_url_successful(self): | 1210 def test_gerrit_patch_url_successful(self): |
| 1186 self._patch_common(is_gerrit=True) | 1211 self._patch_common(is_gerrit=True) |
| 1187 self.calls += [ | 1212 self.calls += [ |
| 1188 ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', | 1213 ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', |
| 1189 'refs/changes/56/123456/1'],), ''), | 1214 'refs/changes/56/123456/1'],), ''), |
| 1190 ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), | 1215 ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), |
| 1191 ((['git', 'config', 'branch.master.gerritissue', '123456'],), ''), | 1216 ((['git', 'config', 'branch.master.gerritissue', '123456'],), ''), |
| 1192 ((['git', 'config', 'branch.master.gerritserver', | 1217 ((['git', 'config', 'branch.master.gerritserver', |
| 1193 'https://chromium-review.googlesource.com'],), ''), | 1218 'https://chromium-review.googlesource.com'],), ''), |
| 1194 ((['git', 'config', 'branch.master.gerritpatchset', '1'],), ''), | 1219 ((['git', 'config', 'branch.master.gerritpatchset', '1'],), ''), |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1328 ((['SetReview', 'chromium-review.googlesource.com', 123, | 1353 ((['SetReview', 'chromium-review.googlesource.com', 123, |
| 1329 {'Commit-Queue': 1}],), ''), | 1354 {'Commit-Queue': 1}],), ''), |
| 1330 ] | 1355 ] |
| 1331 self.assertEqual(0, git_cl.main(['set-commit', '-d'])) | 1356 self.assertEqual(0, git_cl.main(['set-commit', '-d'])) |
| 1332 | 1357 |
| 1333 | 1358 |
| 1334 if __name__ == '__main__': | 1359 if __name__ == '__main__': |
| 1335 git_cl.logging.basicConfig( | 1360 git_cl.logging.basicConfig( |
| 1336 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1361 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 1337 unittest.main() | 1362 unittest.main() |
| OLD | NEW |