| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 if find_copies: | 157 if find_copies: |
| 158 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', | 158 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
| 159 '--find-copies-harder', '-l100000', '-C'+similarity, | 159 '--find-copies-harder', '-l100000', '-C'+similarity, |
| 160 'fake_ancestor_sha', 'HEAD'],), '+dat') | 160 'fake_ancestor_sha', 'HEAD'],), '+dat') |
| 161 else: | 161 else: |
| 162 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', | 162 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
| 163 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') | 163 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') |
| 164 | 164 |
| 165 return [ | 165 return [ |
| 166 ((['git', 'config', 'rietveld.autoupdate'],), ''), | 166 #((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 167 ((['git', 'config', 'rietveld.server'],), | 167 #((['git', 'config', 'rietveld.server'],), |
| 168 'codereview.example.com'), | 168 # 'codereview.example.com'), |
| 169 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 169 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 170 similarity_call, | 170 similarity_call, |
| 171 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 171 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 172 find_copies_call, | 172 find_copies_call, |
| 173 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 174 ((['git', 'config', 'gerrit.host'],), ''), |
| 175 ((['git', 'config', 'rietveld.server'],), |
| 176 'codereview.example.com'), |
| 173 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 177 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 174 ((['git', 'config', 'branch.master.merge'],), 'master'), | 178 ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 175 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 179 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 176 ((['get_or_create_merge_base', 'master', 'master'],), | 180 ((['get_or_create_merge_base', 'master', 'master'],), |
| 177 'fake_ancestor_sha'), | 181 'fake_ancestor_sha'), |
| 178 ((['git', 'config', 'gerrit.host'],), ''), | |
| 179 ((['git', 'config', 'branch.master.rietveldissue'],), ''), | 182 ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
| 180 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 183 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
| 181 ((['git', 'rev-parse', '--show-cdup'],), ''), | 184 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 182 ((['git', 'rev-parse', 'HEAD'],), '12345'), | 185 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
| 183 ((['git', 'diff', '--name-status', '--no-renames', '-r', | 186 ((['git', 'diff', '--name-status', '--no-renames', '-r', |
| 184 'fake_ancestor_sha...', '.'],), | 187 'fake_ancestor_sha...', '.'],), |
| 185 'M\t.gitignore\n'), | 188 'M\t.gitignore\n'), |
| 186 ((['git', 'config', 'branch.master.rietveldpatchset'],), | 189 ((['git', 'config', 'branch.master.rietveldpatchset'],), |
| 187 ''), | 190 ''), |
| 188 ((['git', 'log', '--pretty=format:%s%n%n%b', | 191 ((['git', 'log', '--pretty=format:%s%n%n%b', |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 ((['git', 'config', 'rietveld.autoupdate'],), | 275 ((['git', 'config', 'rietveld.autoupdate'],), |
| 273 ''), | 276 ''), |
| 274 ((['git', 'config', 'rietveld.pending-ref-prefix'],), | 277 ((['git', 'config', 'rietveld.pending-ref-prefix'],), |
| 275 ''), | 278 ''), |
| 276 ((['git', | 279 ((['git', |
| 277 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | 280 'config', '--local', '--get-regexp', '^svn-remote\\.'],), |
| 278 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' | 281 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' |
| 279 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), | 282 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), |
| 280 None), | 283 None), |
| 281 0)), | 284 0)), |
| 282 ((['git', | |
| 283 'config', 'rietveld.server'],), 'codereview.example.com'), | |
| 284 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 285 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 285 ((['git', 'config', '--int', '--get', | 286 ((['git', 'config', '--int', '--get', |
| 286 'branch.working.git-cl-similarity'],), ''), | 287 'branch.working.git-cl-similarity'],), ''), |
| 287 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 288 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 288 ((['git', 'config', '--int', '--get', | 289 ((['git', 'config', '--int', '--get', |
| 289 'branch.working.git-find-copies'],), ''), | 290 'branch.working.git-find-copies'],), ''), |
| 291 ((['git', |
| 292 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 290 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 293 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 291 ((['git', | 294 ((['git', |
| 295 'config', 'branch.working.rietveldissue'],), '12345'), |
| 296 ((['git', |
| 292 'config', 'branch.working.merge'],), 'refs/heads/master'), | 297 'config', 'branch.working.merge'],), 'refs/heads/master'), |
| 293 ((['git', 'config', 'branch.working.remote'],), 'origin'), | 298 ((['git', 'config', 'branch.working.remote'],), 'origin'), |
| 294 ((['git', 'config', 'branch.working.merge'],), | 299 ((['git', 'config', 'branch.working.merge'],), |
| 295 'refs/heads/master'), | 300 'refs/heads/master'), |
| 296 ((['git', 'config', 'branch.working.remote'],), 'origin'), | 301 ((['git', 'config', 'branch.working.remote'],), 'origin'), |
| 297 ((['git', 'rev-list', '--merges', | 302 ((['git', 'rev-list', '--merges', |
| 298 '--grep=^SVN changes up to revision [0-9]*$', | 303 '--grep=^SVN changes up to revision [0-9]*$', |
| 299 'refs/remotes/origin/master^!'],), ''), | 304 'refs/remotes/origin/master^!'],), ''), |
| 300 ((['git', 'rev-list', '^refs/heads/working', | 305 ((['git', 'rev-list', '^refs/heads/working', |
| 301 'refs/remotes/origin/master'],), | 306 'refs/remotes/origin/master'],), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 314 @classmethod | 319 @classmethod |
| 315 def _dcommit_calls_normal(cls): | 320 def _dcommit_calls_normal(cls): |
| 316 return [ | 321 return [ |
| 317 ((['git', 'rev-parse', '--show-cdup'],), ''), | 322 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 318 ((['git', 'rev-parse', 'HEAD'],), | 323 ((['git', 'rev-parse', 'HEAD'],), |
| 319 '00ff397798ea57439712ed7e04ab96e13969ef40'), | 324 '00ff397798ea57439712ed7e04ab96e13969ef40'), |
| 320 ((['git', | 325 ((['git', |
| 321 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', | 326 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', |
| 322 '.'],), | 327 '.'],), |
| 323 'M\tPRESUBMIT.py'), | 328 'M\tPRESUBMIT.py'), |
| 324 ((['git', 'config', 'gerrit.host'],), ''), | |
| 325 ((['git', | |
| 326 'config', 'branch.working.rietveldissue'],), '12345'), | |
| 327 ((['git', | 329 ((['git', |
| 328 'config', 'branch.working.rietveldpatchset'],), '31137'), | 330 'config', 'branch.working.rietveldpatchset'],), '31137'), |
| 329 ((['git', 'config', 'branch.working.rietveldserver'],), | 331 ((['git', 'config', 'branch.working.rietveldserver'],), |
| 330 'codereview.example.com'), | 332 'codereview.example.com'), |
| 331 ((['git', 'config', 'user.email'],), 'author@example.com'), | 333 ((['git', 'config', 'user.email'],), 'author@example.com'), |
| 332 ((['git', 'config', 'rietveld.tree-status-url'],), ''), | 334 ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
| 333 ] | 335 ] |
| 334 | 336 |
| 335 @classmethod | 337 @classmethod |
| 336 def _dcommit_calls_bypassed(cls): | 338 def _dcommit_calls_bypassed(cls): |
| 337 return [ | 339 return [ |
| 338 ((['git', 'config', 'gerrit.host'],), ''), | |
| 339 ((['git', | |
| 340 'config', 'branch.working.rietveldissue'],), '12345'), | |
| 341 ((['git', 'config', 'branch.working.rietveldserver'],), | 340 ((['git', 'config', 'branch.working.rietveldserver'],), |
| 342 'codereview.example.com'), | 341 'codereview.example.com'), |
| 343 ] | 342 ] |
| 344 | 343 |
| 345 @classmethod | 344 @classmethod |
| 346 def _dcommit_calls_3(cls): | 345 def _dcommit_calls_3(cls): |
| 347 return [ | 346 return [ |
| 348 ((['git', | 347 ((['git', |
| 349 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 348 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
| 350 '-l100000', '-C50', 'fake_ancestor_sha', | 349 '-l100000', '-C50', 'fake_ancestor_sha', |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 self.calls = ( | 539 self.calls = ( |
| 541 self._dcommit_calls_1() + | 540 self._dcommit_calls_1() + |
| 542 self._dcommit_calls_bypassed() + | 541 self._dcommit_calls_bypassed() + |
| 543 self._dcommit_calls_3()) | 542 self._dcommit_calls_3()) |
| 544 git_cl.main(['dcommit', '--bypass-hooks']) | 543 git_cl.main(['dcommit', '--bypass-hooks']) |
| 545 | 544 |
| 546 | 545 |
| 547 @classmethod | 546 @classmethod |
| 548 def _gerrit_base_calls(cls): | 547 def _gerrit_base_calls(cls): |
| 549 return [ | 548 return [ |
| 550 ((['git', 'config', 'rietveld.autoupdate'],), | |
| 551 ''), | |
| 552 ((['git', | |
| 553 'config', 'rietveld.server'],), 'codereview.example.com'), | |
| 554 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 549 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 555 ((['git', 'config', '--int', '--get', | 550 ((['git', 'config', '--int', '--get', |
| 556 'branch.master.git-cl-similarity'],), ''), | 551 'branch.master.git-cl-similarity'],), ''), |
| 557 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 552 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 558 ((['git', 'config', '--int', '--get', | 553 ((['git', 'config', '--int', '--get', |
| 559 'branch.master.git-find-copies'],), ''), | 554 'branch.master.git-find-copies'],), ''), |
| 555 ((['git', 'config', 'rietveld.autoupdate'],), |
| 556 ''), |
| 557 ((['git', 'config', 'gerrit.host'],), 'True'), |
| 558 #((['git', |
| 559 # 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 560 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 560 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 561 #((['git', |
| 562 # 'config', 'branch.master.rietveldissue'],), ''), |
| 561 ((['git', 'config', 'branch.master.merge'],), 'master'), | 563 ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 562 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 564 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 563 ((['get_or_create_merge_base', 'master', 'master'],), | 565 ((['get_or_create_merge_base', 'master', 'master'],), |
| 564 'fake_ancestor_sha'), | 566 'fake_ancestor_sha'), |
| 565 ((['git', 'config', 'gerrit.host'],), 'True'), | 567 # ((['git', 'config', 'gerrit.host'],), 'True'), |
| 566 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 568 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
| 567 ((['git', 'rev-parse', '--show-cdup'],), ''), | 569 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 568 ((['git', 'rev-parse', 'HEAD'],), '12345'), | 570 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
| 569 ((['git', | 571 ((['git', |
| 570 'diff', '--name-status', '--no-renames', '-r', | 572 'diff', '--name-status', '--no-renames', '-r', |
| 571 'fake_ancestor_sha...', '.'],), | 573 'fake_ancestor_sha...', '.'],), |
| 572 'M\t.gitignore\n'), | 574 'M\t.gitignore\n'), |
| 573 ((['git', 'config', 'branch.master.gerritissue'],), ''), | 575 ((['git', 'config', 'branch.master.gerritissue'],), ''), |
| 574 ((['git', | 576 ((['git', |
| 575 'config', 'branch.master.rietveldpatchset'],), ''), | 577 'config', 'branch.master.gerritpatchset'],), ''), |
| 576 ((['git', | 578 ((['git', |
| 577 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), | 579 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), |
| 578 'foo'), | 580 'foo'), |
| 579 ((['git', 'config', 'user.email'],), 'me@example.com'), | 581 ((['git', 'config', 'user.email'],), 'me@example.com'), |
| 580 ((['git', | 582 ((['git', |
| 581 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 583 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
| 582 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), | 584 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
| 583 '+dat'), | 585 '+dat'), |
| 584 ] | 586 ] |
| 585 | 587 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 # Patch when local tree is dirty | 882 # Patch when local tree is dirty |
| 881 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) | 883 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) |
| 882 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 884 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
| 883 | 885 |
| 884 def test_diff_when_dirty(self): | 886 def test_diff_when_dirty(self): |
| 885 # Do 'git cl diff' when local tree is dirty | 887 # Do 'git cl diff' when local tree is dirty |
| 886 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) | 888 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) |
| 887 self.assertNotEqual(git_cl.main(['diff']), 0) | 889 self.assertNotEqual(git_cl.main(['diff']), 0) |
| 888 | 890 |
| 889 def _patch_common(self): | 891 def _patch_common(self): |
| 890 self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda x: '60001') | 892 self.mock(git_cl.RietveldChangelist, 'GetMostRecentPatchset', lambda x: '600
01') |
| 891 self.mock(git_cl.Changelist, 'GetPatchSetDiff', lambda *args: None) | 893 self.mock(git_cl.RietveldChangelist, 'GetPatchSetDiff', lambda *args: None) |
| 892 self.mock(git_cl.Changelist, 'GetDescription', lambda *args: 'Description') | 894 self.mock(git_cl.ChangelistBase, 'GetDescription', lambda *args: 'Descriptio
n') |
| 893 self.mock(git_cl.Changelist, 'SetIssue', lambda *args: None) | 895 self.mock(git_cl.ChangelistBase, 'SetIssue', lambda *args: None) |
| 894 self.mock(git_cl.Changelist, 'SetPatchset', lambda *args: None) | 896 self.mock(git_cl.ChangelistBase, 'SetPatchset', lambda *args: None) |
| 895 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) | 897 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) |
| 896 | 898 |
| 897 self.calls = [ | 899 self.calls = [ |
| 898 ((['git', 'config', 'rietveld.autoupdate'],), ''), | 900 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 899 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), | 901 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 900 ((['git', 'rev-parse', '--show-cdup'],), ''), | 902 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 901 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''), | 903 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''), |
| 902 ] | 904 ] |
| 903 | 905 |
| 904 def test_patch_successful(self): | 906 def test_patch_successful(self): |
| (...skipping 12 matching lines...) Expand all Loading... |
| 917 self.calls += [ | 919 self.calls += [ |
| 918 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 920 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
| 919 subprocess2.CalledProcessError(1, '', '', '', '')), | 921 subprocess2.CalledProcessError(1, '', '', '', '')), |
| 920 ] | 922 ] |
| 921 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 923 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
| 922 | 924 |
| 923 if __name__ == '__main__': | 925 if __name__ == '__main__': |
| 924 git_cl.logging.basicConfig( | 926 git_cl.logging.basicConfig( |
| 925 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 927 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 926 unittest.main() | 928 unittest.main() |
| OLD | NEW |