| 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 scm.py.""" | 6 """Unit tests for scm.py.""" |
| 7 | 7 |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 'GetBranch', | 83 'GetBranch', |
| 84 'GetBranchRef', | 84 'GetBranchRef', |
| 85 'GetCheckoutRoot', | 85 'GetCheckoutRoot', |
| 86 'GetDifferentFiles', | 86 'GetDifferentFiles', |
| 87 'GetEmail', | 87 'GetEmail', |
| 88 'GetGitSvnHeadRev', | 88 'GetGitSvnHeadRev', |
| 89 'GetPatchName', | 89 'GetPatchName', |
| 90 'GetSha1ForSvnRev', | 90 'GetSha1ForSvnRev', |
| 91 'GetSVNBranch', | 91 'GetSVNBranch', |
| 92 'GetUpstreamBranch', | 92 'GetUpstreamBranch', |
| 93 'IsGit', |
| 93 'IsGitSvn', | 94 'IsGitSvn', |
| 94 'IsValidRevision', | 95 'IsValidRevision', |
| 95 'MatchSvnGlob', | 96 'MatchSvnGlob', |
| 96 'ParseGitSvnSha1', | 97 'ParseGitSvnSha1', |
| 97 'ShortBranchName', | 98 'ShortBranchName', |
| 98 ] | 99 ] |
| 99 # If this test fails, you should add the relevant test. | 100 # If this test fails, you should add the relevant test. |
| 100 self.compareMembers(scm.GIT, members) | 101 self.compareMembers(scm.GIT, members) |
| 101 | 102 |
| 102 def testGetEmail(self): | 103 def testGetEmail(self): |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 kwargs.setdefault('cwd', self.clone_dir) | 163 kwargs.setdefault('cwd', self.clone_dir) |
| 163 return scm.GIT.Capture(cmd, **kwargs) | 164 return scm.GIT.Capture(cmd, **kwargs) |
| 164 | 165 |
| 165 def testGetGitSvnHeadRev(self): | 166 def testGetGitSvnHeadRev(self): |
| 166 if not self.enabled: | 167 if not self.enabled: |
| 167 return | 168 return |
| 168 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 2) | 169 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 2) |
| 169 self._capture(['reset', '--hard', 'HEAD^']) | 170 self._capture(['reset', '--hard', 'HEAD^']) |
| 170 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 1) | 171 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 1) |
| 171 | 172 |
| 173 def testIsGit(self): |
| 174 if not self.enabled: |
| 175 return |
| 176 # Pure git |
| 177 git_dir = scm.os.path.join(self.FAKE_REPOS.git_root, 'repo_1') |
| 178 self.assertTrue(scm.GIT.IsGit(git_dir)) |
| 179 # Pure svn |
| 180 svn_dir = scm.os.path.join(self.FAKE_REPOS.svn_checkout, 'trunk') |
| 181 self.assertFalse(scm.GIT.IsGit(svn_dir)) |
| 182 |
| 183 def testIsGitSvn(self): |
| 184 if not self.enabled: |
| 185 return |
| 186 # Git-svn |
| 187 self.assertTrue(scm.GIT.IsGitSvn(self.clone_dir)) |
| 188 # Pure git |
| 189 git_dir = scm.os.path.join(self.FAKE_REPOS.git_root, 'repo_1') |
| 190 self.assertFalse(scm.GIT.IsGitSvn(git_dir)) |
| 191 # Pure svn |
| 192 svn_dir = scm.os.path.join(self.FAKE_REPOS.svn_checkout, 'trunk') |
| 193 self.assertFalse(scm.GIT.IsGitSvn(svn_dir)) |
| 194 |
| 172 def testParseGitSvnSha1(self): | 195 def testParseGitSvnSha1(self): |
| 173 test_sha1 = 'a5c63ce8671922e5c59c0dea49ef4f9d4a3020c9' | 196 test_sha1 = 'a5c63ce8671922e5c59c0dea49ef4f9d4a3020c9' |
| 174 expected_output = test_sha1 + '\n' | 197 expected_output = test_sha1 + '\n' |
| 175 # Cygwin git-svn 1.7.9 prints extra escape sequences when run under | 198 # Cygwin git-svn 1.7.9 prints extra escape sequences when run under |
| 176 # TERM=xterm | 199 # TERM=xterm |
| 177 cygwin_output = test_sha1 + '\n\033[?1034h' | 200 cygwin_output = test_sha1 + '\n\033[?1034h' |
| 178 | 201 |
| 179 self.assertEquals(scm.GIT.ParseGitSvnSha1(expected_output), test_sha1) | 202 self.assertEquals(scm.GIT.ParseGitSvnSha1(expected_output), test_sha1) |
| 180 self.assertEquals(scm.GIT.ParseGitSvnSha1(cygwin_output), test_sha1) | 203 self.assertEquals(scm.GIT.ParseGitSvnSha1(cygwin_output), test_sha1) |
| 181 | 204 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 # Asserting the tree is not sufficient, svn status must come out clear too. | 489 # Asserting the tree is not sufficient, svn status must come out clear too. |
| 467 self.assertEquals('', self._capture(['status'])) | 490 self.assertEquals('', self._capture(['status'])) |
| 468 | 491 |
| 469 | 492 |
| 470 if __name__ == '__main__': | 493 if __name__ == '__main__': |
| 471 if '-v' in sys.argv: | 494 if '-v' in sys.argv: |
| 472 logging.basicConfig(level=logging.DEBUG) | 495 logging.basicConfig(level=logging.DEBUG) |
| 473 unittest.main() | 496 unittest.main() |
| 474 | 497 |
| 475 # vim: ts=2:sw=2:tw=80:et: | 498 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |