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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 'GetDifferentFiles', | 85 'GetDifferentFiles', |
86 'GetEmail', | 86 'GetEmail', |
87 'GetGitSvnHeadRev', | 87 'GetGitSvnHeadRev', |
88 'GetPatchName', | 88 'GetPatchName', |
89 'GetSha1ForSvnRev', | 89 'GetSha1ForSvnRev', |
90 'GetSVNBranch', | 90 'GetSVNBranch', |
91 'GetUpstreamBranch', | 91 'GetUpstreamBranch', |
92 'IsGitSvn', | 92 'IsGitSvn', |
93 'IsValidRevision', | 93 'IsValidRevision', |
94 'MatchSvnGlob', | 94 'MatchSvnGlob', |
95 'ParseGitSvnSha1', | |
95 'ShortBranchName', | 96 'ShortBranchName', |
96 ] | 97 ] |
97 # If this test fails, you should add the relevant test. | 98 # If this test fails, you should add the relevant test. |
98 self.compareMembers(scm.GIT, members) | 99 self.compareMembers(scm.GIT, members) |
99 | 100 |
100 def testGetEmail(self): | 101 def testGetEmail(self): |
101 self.mox.StubOutWithMock(scm.GIT, 'Capture') | 102 self.mox.StubOutWithMock(scm.GIT, 'Capture') |
102 scm.GIT.Capture(['config', 'user.email'], cwd=self.root_dir | 103 scm.GIT.Capture(['config', 'user.email'], cwd=self.root_dir |
103 ).AndReturn('mini@me.com') | 104 ).AndReturn('mini@me.com') |
104 self.mox.ReplayAll() | 105 self.mox.ReplayAll() |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 kwargs.setdefault('cwd', self.clone_dir) | 161 kwargs.setdefault('cwd', self.clone_dir) |
161 return scm.GIT.Capture(cmd, **kwargs) | 162 return scm.GIT.Capture(cmd, **kwargs) |
162 | 163 |
163 def testGetGitSvnHeadRev(self): | 164 def testGetGitSvnHeadRev(self): |
164 if not self.enabled: | 165 if not self.enabled: |
165 return | 166 return |
166 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 2) | 167 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 2) |
167 self._capture(['reset', '--hard', 'HEAD^']) | 168 self._capture(['reset', '--hard', 'HEAD^']) |
168 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 1) | 169 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 1) |
169 | 170 |
171 def testParseGitSvnSha1(self): | |
172 test_sha1 = 'a5c63ce8671922e5c59c0dea49ef4f9d4a3020c9' | |
173 expected_output = test_sha1 + '\n' | |
174 # Cygwin git-svn 1.7.9 prints extra escape sequences when run under | |
175 # TERM=xterm | |
176 cygwin_output = test_sha1 + '\n\033[?1034h' | |
Dirk Pranke
2012/08/09 18:52:23
Great, this is what I was looking for ...
| |
177 | |
178 self.assertEquals(scm.GIT.ParseGitSvnSha1(expected_output), test_sha1) | |
179 self.assertEquals(scm.GIT.ParseGitSvnSha1(cygwin_output), test_sha1) | |
180 | |
170 def testGetGetSha1ForSvnRev(self): | 181 def testGetGetSha1ForSvnRev(self): |
171 if not self.enabled: | 182 if not self.enabled: |
172 return | 183 return |
173 self.assertEquals(scm.GIT.GetSha1ForSvnRev(cwd=self.clone_dir, rev=1), | 184 self.assertEquals(scm.GIT.GetSha1ForSvnRev(cwd=self.clone_dir, rev=1), |
174 self.git_hashes[1]) | 185 self.git_hashes[1]) |
175 self.assertEquals(scm.GIT.GetSha1ForSvnRev(cwd=self.clone_dir, rev=2), | 186 self.assertEquals(scm.GIT.GetSha1ForSvnRev(cwd=self.clone_dir, rev=2), |
176 self.git_hashes[2]) | 187 self.git_hashes[2]) |
177 | 188 |
178 | 189 |
179 class SVNTestCase(BaseSCMTestCase): | 190 class SVNTestCase(BaseSCMTestCase): |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 # Asserting the tree is not sufficient, svn status must come out clear too. | 466 # Asserting the tree is not sufficient, svn status must come out clear too. |
456 self.assertEquals('', self._capture(['status'])) | 467 self.assertEquals('', self._capture(['status'])) |
457 | 468 |
458 | 469 |
459 if __name__ == '__main__': | 470 if __name__ == '__main__': |
460 if '-v' in sys.argv: | 471 if '-v' in sys.argv: |
461 logging.basicConfig(level=logging.DEBUG) | 472 logging.basicConfig(level=logging.DEBUG) |
462 unittest.main() | 473 unittest.main() |
463 | 474 |
464 # vim: ts=2:sw=2:tw=80:et: | 475 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |