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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 class TestGitCl(TestCase): | 69 class TestGitCl(TestCase): |
70 def setUp(self): | 70 def setUp(self): |
71 super(TestGitCl, self).setUp() | 71 super(TestGitCl, self).setUp() |
72 self.calls = [] | 72 self.calls = [] |
73 self._calls_done = 0 | 73 self._calls_done = 0 |
74 self.mock(subprocess2, 'call', self._mocked_call) | 74 self.mock(subprocess2, 'call', self._mocked_call) |
75 self.mock(subprocess2, 'check_call', self._mocked_call) | 75 self.mock(subprocess2, 'check_call', self._mocked_call) |
76 self.mock(subprocess2, 'check_output', self._mocked_call) | 76 self.mock(subprocess2, 'check_output', self._mocked_call) |
77 self.mock(subprocess2, 'communicate', self._mocked_call) | 77 self.mock(subprocess2, 'communicate', self._mocked_call) |
78 self.mock(subprocess2, 'Popen', self._mocked_call) | 78 self.mock(git_common, 'is_dirty_git_tree', lambda x: False) |
79 self.mock(git_common, 'get_or_create_merge_base', | 79 self.mock(git_common, 'get_or_create_merge_base', |
80 lambda *a: ( | 80 lambda *a: ( |
81 self._mocked_call(['get_or_create_merge_base']+list(a)))) | 81 self._mocked_call(['get_or_create_merge_base']+list(a)))) |
82 self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: '') | 82 self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: '') |
83 self.mock(git_cl, 'ask_for_data', self._mocked_call) | 83 self.mock(git_cl, 'ask_for_data', self._mocked_call) |
84 self.mock(git_cl.breakpad, 'post', self._mocked_call) | 84 self.mock(git_cl.breakpad, 'post', self._mocked_call) |
85 self.mock(git_cl.breakpad, 'SendStack', self._mocked_call) | 85 self.mock(git_cl.breakpad, 'SendStack', self._mocked_call) |
86 self.mock(git_cl.presubmit_support, 'DoPresubmitChecks', PresubmitMock) | 86 self.mock(git_cl.presubmit_support, 'DoPresubmitChecks', PresubmitMock) |
87 self.mock(git_cl.rietveld, 'Rietveld', RietveldMock) | 87 self.mock(git_cl.rietveld, 'Rietveld', RietveldMock) |
88 self.mock(git_cl.rietveld, 'CachingRietveld', RietveldMock) | 88 self.mock(git_cl.rietveld, 'CachingRietveld', RietveldMock) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') | 149 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') |
150 | 150 |
151 return [ | 151 return [ |
152 ((['git', 'config', 'rietveld.autoupdate'],), ''), | 152 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
153 ((['git', 'config', 'rietveld.server'],), | 153 ((['git', 'config', 'rietveld.server'],), |
154 'codereview.example.com'), | 154 'codereview.example.com'), |
155 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 155 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
156 similarity_call, | 156 similarity_call, |
157 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 157 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
158 find_copies_call, | 158 find_copies_call, |
159 ((['git', 'update-index', '--refresh', '-q'],), ''), | |
160 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), | |
161 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 159 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
162 ((['git', 'config', 'branch.master.merge'],), 'master'), | 160 ((['git', 'config', 'branch.master.merge'],), 'master'), |
163 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 161 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
164 ((['get_or_create_merge_base', 'master', 'master'],), | 162 ((['get_or_create_merge_base', 'master', 'master'],), |
165 'fake_ancestor_sha'), | 163 'fake_ancestor_sha'), |
166 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 164 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
167 ((['git', 'rev-parse', '--show-cdup'],), ''), | 165 ((['git', 'rev-parse', '--show-cdup'],), ''), |
168 ((['git', 'rev-parse', 'HEAD'],), '12345'), | 166 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
169 ((['git', 'diff', '--name-status', '--no-renames', '-r', | 167 ((['git', 'diff', '--name-status', '--no-renames', '-r', |
170 'fake_ancestor_sha...', '.'],), | 168 'fake_ancestor_sha...', '.'],), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 271 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
274 ((['git', | 272 ((['git', |
275 'config', 'branch.working.merge'],), 'refs/heads/master'), | 273 'config', 'branch.working.merge'],), 'refs/heads/master'), |
276 ((['git', 'config', 'branch.working.remote'],), 'origin'), | 274 ((['git', 'config', 'branch.working.remote'],), 'origin'), |
277 ((['git', 'config', 'branch.working.merge'],), | 275 ((['git', 'config', 'branch.working.merge'],), |
278 'refs/heads/master'), | 276 'refs/heads/master'), |
279 ((['git', 'config', 'branch.working.remote'],), 'origin'), | 277 ((['git', 'config', 'branch.working.remote'],), 'origin'), |
280 ((['git', 'rev-list', '--merges', | 278 ((['git', 'rev-list', '--merges', |
281 '--grep=^SVN changes up to revision [0-9]*$', | 279 '--grep=^SVN changes up to revision [0-9]*$', |
282 'refs/remotes/origin/master^!'],), ''), | 280 'refs/remotes/origin/master^!'],), ''), |
283 ((['git', 'update-index', '--refresh', '-q'],), ''), | |
284 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), | |
285 ((['git', 'rev-list', '^refs/heads/working', | 281 ((['git', 'rev-list', '^refs/heads/working', |
286 'refs/remotes/origin/master'],), | 282 'refs/remotes/origin/master'],), |
287 ''), | 283 ''), |
288 ((['git', | 284 ((['git', |
289 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],), | 285 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],), |
290 '3fc18b62c4966193eb435baabe2d18a3810ec82e'), | 286 '3fc18b62c4966193eb435baabe2d18a3810ec82e'), |
291 ((['git', | 287 ((['git', |
292 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', | 288 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', |
293 'refs/remotes/origin/master'],), ''), | 289 'refs/remotes/origin/master'],), ''), |
294 ((['git', | 290 ((['git', |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 ((['git', 'config', 'rietveld.autoupdate'],), | 533 ((['git', 'config', 'rietveld.autoupdate'],), |
538 ''), | 534 ''), |
539 ((['git', | 535 ((['git', |
540 'config', 'rietveld.server'],), 'codereview.example.com'), | 536 'config', 'rietveld.server'],), 'codereview.example.com'), |
541 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 537 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
542 ((['git', 'config', '--int', '--get', | 538 ((['git', 'config', '--int', '--get', |
543 'branch.master.git-cl-similarity'],), ''), | 539 'branch.master.git-cl-similarity'],), ''), |
544 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 540 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
545 ((['git', 'config', '--int', '--get', | 541 ((['git', 'config', '--int', '--get', |
546 'branch.master.git-find-copies'],), ''), | 542 'branch.master.git-find-copies'],), ''), |
547 ((['git', 'update-index', '--refresh', '-q'],), ''), | |
548 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), | |
549 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 543 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
550 ((['git', 'config', 'branch.master.merge'],), 'master'), | 544 ((['git', 'config', 'branch.master.merge'],), 'master'), |
551 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 545 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
552 ((['get_or_create_merge_base', 'master', 'master'],), | 546 ((['get_or_create_merge_base', 'master', 'master'],), |
553 'fake_ancestor_sha'), | 547 'fake_ancestor_sha'), |
554 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 548 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
555 ((['git', 'rev-parse', '--show-cdup'],), ''), | 549 ((['git', 'rev-parse', '--show-cdup'],), ''), |
556 ((['git', 'rev-parse', 'HEAD'],), '12345'), | 550 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
557 ((['git', | 551 ((['git', |
558 'diff', '--name-status', '--no-renames', '-r', | 552 'diff', '--name-status', '--no-renames', '-r', |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 # Check target refs for pending prefix. | 843 # Check target refs for pending prefix. |
850 self.assertEqual('prefix/heads/master', | 844 self.assertEqual('prefix/heads/master', |
851 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', | 845 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', |
852 None, 'prefix/')) | 846 None, 'prefix/')) |
853 | 847 |
854 | 848 |
855 if __name__ == '__main__': | 849 if __name__ == '__main__': |
856 git_cl.logging.basicConfig( | 850 git_cl.logging.basicConfig( |
857 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 851 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
858 unittest.main() | 852 unittest.main() |
OLD | NEW |