Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: tests/scm_unittest.py

Issue 8382030: depot_tools: Add git svn find-rev for safesync_url parsing (commonly LKGR link). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: changing more occurrences of SVN to Svn Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/gclient_scm_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 from __future__ import with_statement 8 from __future__ import with_statement
9 import logging 9 import logging
10 import os 10 import os
(...skipping 30 matching lines...) Expand all
41 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilter') 41 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilter')
42 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilterAndHeader') 42 self.mox.StubOutWithMock(scm.gclient_utils, 'CheckCallAndFilterAndHeader')
43 self.mox.StubOutWithMock(subprocess2, 'Popen') 43 self.mox.StubOutWithMock(subprocess2, 'Popen')
44 self.mox.StubOutWithMock(subprocess2, 'communicate') 44 self.mox.StubOutWithMock(subprocess2, 'communicate')
45 45
46 46
47 class RootTestCase(BaseSCMTestCase): 47 class RootTestCase(BaseSCMTestCase):
48 def testMembersChanged(self): 48 def testMembersChanged(self):
49 self.mox.ReplayAll() 49 self.mox.ReplayAll()
50 members = [ 50 members = [
51 'ElementTree', 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 51 'cStringIO',
52 'determine_scm',
53 'ElementTree',
54 'gclient_utils',
55 'GenFakeDiff',
56 'GetCasedPath',
57 'GIT',
58 'glob',
59 'logging',
60 'only_int',
61 'os',
62 're',
63 'subprocess2',
64 'SVN',
65 'sys',
66 'tempfile',
67 'time',
52 'ValidateEmail', 68 'ValidateEmail',
53 'cStringIO', 'determine_scm', 'gclient_utils', 'glob', 'logging',
54 'only_int', 'os', 're', 'subprocess2', 'sys', 'tempfile', 'time',
55 ] 69 ]
56 # If this test fails, you should add the relevant test. 70 # If this test fails, you should add the relevant test.
57 self.compareMembers(scm, members) 71 self.compareMembers(scm, members)
58 72
59 73
60 class GitWrapperTestCase(BaseSCMTestCase): 74 class GitWrapperTestCase(BaseSCMTestCase):
61 def testMembersChanged(self): 75 def testMembersChanged(self):
62 members = [ 76 members = [
63 'AssertVersion', 'Capture', 'CaptureStatus', 77 'AssertVersion',
78 'Capture',
79 'CaptureStatus',
80 'current_version',
64 'FetchUpstreamTuple', 81 'FetchUpstreamTuple',
65 'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot', 82 'GenerateDiff',
66 'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch', 83 'GetBranch',
67 'GetUpstreamBranch', 'IsGitSvn', 'MatchSvnGlob', 'ShortBranchName', 84 'GetBranchRef',
68 'current_version', 85 'GetCheckoutRoot',
86 'GetDifferentFiles',
87 'GetEmail',
88 'GetGitSvnHeadRev',
89 'GetPatchName',
90 'GetSha1ForSvnRev',
91 'GetSVNBranch',
92 'GetUpstreamBranch',
93 'IsGitSvn',
94 'IsValidRevision',
95 'MatchSvnGlob',
96 'ShortBranchName',
69 ] 97 ]
70 # If this test fails, you should add the relevant test. 98 # If this test fails, you should add the relevant test.
71 self.compareMembers(scm.GIT, members) 99 self.compareMembers(scm.GIT, members)
72 100
73 def testGetEmail(self): 101 def testGetEmail(self):
74 self.mox.StubOutWithMock(scm.GIT, 'Capture') 102 self.mox.StubOutWithMock(scm.GIT, 'Capture')
75 scm.GIT.Capture(['config', 'user.email'], cwd=self.root_dir 103 scm.GIT.Capture(['config', 'user.email'], cwd=self.root_dir
76 ).AndReturn('mini@me.com') 104 ).AndReturn('mini@me.com')
77 self.mox.ReplayAll() 105 self.mox.ReplayAll()
78 self.assertEqual(scm.GIT.GetEmail(self.root_dir), 'mini@me.com') 106 self.assertEqual(scm.GIT.GetEmail(self.root_dir), 'mini@me.com')
79 107
80 def testMatchSvnGlob(self): 108 def testMatchSvnGlob(self):
81 self.assertEquals(scm.GIT.MatchSvnGlob( 109 self.assertEquals(scm.GIT.MatchSvnGlob(
82 'svn://svn.chromium.org/chrome/trunk/src', 110 'svn://svn.chromium.org/chrome/trunk/src',
83 'svn://svn.chromium.org/chrome', 111 'svn://svn.chromium.org/chrome',
84 'trunk/src:refs/remotes/origin/trunk', 112 'trunk/src:refs/remotes/origin/trunk',
85 False), 'refs/remotes/origin/trunk') 113 False), 'refs/remotes/origin/trunk')
86 self.assertEquals(scm.GIT.MatchSvnGlob( 114 self.assertEquals(scm.GIT.MatchSvnGlob(
87 'https://v8.googlecode.com/svn/branches/bleeding_edge', 115 'https://v8.googlecode.com/svn/branches/bleeding_edge',
88 'https://v8.googlecode.com/svn', 116 'https://v8.googlecode.com/svn',
89 'branches/*:refs/remotes/*', 117 'branches/*:refs/remotes/*',
90 True), 'refs/remotes/bleeding_edge') 118 True), 'refs/remotes/bleeding_edge')
91 119
120
121 class RealGitTest(fake_repos.FakeReposTestBase):
122 def setUp(self):
123 super(RealGitTest, self).setUp()
124 self.enabled = self.FAKE_REPOS.set_up_git()
125 if self.enabled:
126 self.clone_dir = scm.os.path.join(self.FAKE_REPOS.git_root, 'repo_1')
127
128 def testIsValidRevision(self):
129 if not self.enabled:
130 return
131 # Sha1's are [0-9a-z]{32}, so starting with a 'z' or 'r' should always fail.
132 self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='zebra'))
133 self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='r123456'))
134 # Valid cases
135 first_rev = self.githash('repo_1', 1)
136 self.assertTrue(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev=first_rev))
137 self.assertTrue(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='HEAD'))
138
139
140 class RealGitSvnTest(fake_repos.FakeReposTestBase):
141 def setUp(self):
142 super(RealGitSvnTest, self).setUp()
143 self.enabled = self.FAKE_REPOS.set_up_git() and self.FAKE_REPOS.set_up_svn()
144 if self.enabled:
145 self.tree_name = 'git-svn'
146 self.svn_url = scm.os.path.join(self.FAKE_REPOS.svn_base, 'trunk')
147 self.clone_dir = scm.os.path.join(self.FAKE_REPOS.git_root,
148 self.tree_name)
149 scm.os.makedirs(self.clone_dir)
150 self._capture(['svn', 'clone', '-q', '-q', self.svn_url, self.clone_dir])
151 # git rev-list gives revisions in reverse chronological order.
152 hashes = reversed(self._capture(['rev-list', 'HEAD']).splitlines())
153 # We insert a null value at 0 to do 1-based indexing, not 0-based, as SVN
154 # revisions are 1-based (i.e. they start at r1, not r0).
155 self.git_hashes = ([None] + list(hashes))
156
157 def tearDown(self):
158 scm.gclient_utils.rmtree(self.clone_dir)
159
160 def _capture(self, cmd, **kwargs):
161 kwargs.setdefault('cwd', self.clone_dir)
162 return scm.GIT.Capture(cmd, **kwargs)
163
164 def testGetGitSvnHeadRev(self):
165 if not self.enabled:
166 return
167 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 2)
168 self._capture(['reset', '--hard', 'HEAD^'])
169 self.assertEquals(scm.GIT.GetGitSvnHeadRev(cwd=self.clone_dir), 1)
170
171 def testGetGetSha1ForSvnRev(self):
172 if not self.enabled:
173 return
174 self.assertEquals(scm.GIT.GetSha1ForSvnRev(cwd=self.clone_dir, rev=1),
175 self.git_hashes[1])
176 self.assertEquals(scm.GIT.GetSha1ForSvnRev(cwd=self.clone_dir, rev=2),
177 self.git_hashes[2])
178
179
92 class SVNTestCase(BaseSCMTestCase): 180 class SVNTestCase(BaseSCMTestCase):
93 def setUp(self): 181 def setUp(self):
94 BaseSCMTestCase.setUp(self) 182 BaseSCMTestCase.setUp(self)
95 self.mox.StubOutWithMock(scm.SVN, 'Capture') 183 self.mox.StubOutWithMock(scm.SVN, 'Capture')
96 self.url = self.SvnUrl() 184 self.url = self.SvnUrl()
97 185
98 def testMembersChanged(self): 186 def testMembersChanged(self):
99 self.mox.ReplayAll() 187 self.mox.ReplayAll()
100 members = [ 188 members = [
101 'AssertVersion', 'Capture', 'CaptureRevision', 'CaptureLocalInfo', 189 'AssertVersion',
190 'Capture',
191 'CaptureLocalInfo',
102 'CaptureRemoteInfo', 192 'CaptureRemoteInfo',
103 'CaptureStatus', 'current_version', 'DiffItem', 'GenerateDiff', 193 'CaptureRevision',
104 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved', 194 'CaptureStatus',
105 'IsMovedInfo', 'ReadSimpleAuth', 'Revert', 'RunAndGetFileList', 195 'current_version',
196 'DiffItem',
197 'GenerateDiff',
198 'GetCheckoutRoot',
199 'GetEmail',
200 'GetFileProperty',
201 'IsMoved',
202 'IsMovedInfo',
203 'IsValidRevision',
204 'ReadSimpleAuth',
205 'Revert',
206 'RunAndGetFileList',
106 ] 207 ]
107 # If this test fails, you should add the relevant test. 208 # If this test fails, you should add the relevant test.
108 self.compareMembers(scm.SVN, members) 209 self.compareMembers(scm.SVN, members)
109 210
110 def testGetCheckoutRoot(self): 211 def testGetCheckoutRoot(self):
111 # pylint: disable=E1103 212 # pylint: disable=E1103
112 self.mox.StubOutWithMock(scm.SVN, '_CaptureInfo') 213 self.mox.StubOutWithMock(scm.SVN, '_CaptureInfo')
113 self.mox.StubOutWithMock(scm, 'GetCasedPath') 214 self.mox.StubOutWithMock(scm, 'GetCasedPath')
114 scm.os.path.abspath = lambda x: x 215 scm.os.path.abspath = lambda x: x
115 scm.GetCasedPath = lambda x: x 216 scm.GetCasedPath = lambda x: x
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 def _capture(self, cmd, **kwargs): 382 def _capture(self, cmd, **kwargs):
282 kwargs.setdefault('cwd', self.svn_root) 383 kwargs.setdefault('cwd', self.svn_root)
283 return scm.SVN.Capture(cmd, **kwargs) 384 return scm.SVN.Capture(cmd, **kwargs)
284 385
285 def testCheckout(self): 386 def testCheckout(self):
286 if not self.enabled: 387 if not self.enabled:
287 return 388 return
288 # Checkout and verify the tree. 389 # Checkout and verify the tree.
289 self.assertTree(self.tree, self.svn_root) 390 self.assertTree(self.tree, self.svn_root)
290 391
392 def testIsValidRevision(self):
393 if not self.enabled:
394 return
395 url_at_rev = self.svn_base + 'trunk/third_party@%s'
396 # Invalid or non-existent.
397 self.assertFalse(scm.SVN.IsValidRevision('url://totally_invalid/trunk/foo'))
398 self.assertFalse(scm.SVN.IsValidRevision(url_at_rev % 0))
399 self.assertFalse(scm.SVN.IsValidRevision(url_at_rev % 123))
400 # Valid.
401 self.assertTrue(scm.SVN.IsValidRevision(url_at_rev % 1))
402 self.assertTrue(scm.SVN.IsValidRevision(url_at_rev % 2))
403 self.assertTrue(scm.SVN.IsValidRevision(url_at_rev % 'HEAD'))
404
291 def testRevert(self): 405 def testRevert(self):
292 if not self.enabled: 406 if not self.enabled:
293 return 407 return
294 # Mess around and make sure revert works for all corner cases. 408 # Mess around and make sure revert works for all corner cases.
295 # - svn add a file 409 # - svn add a file
296 # - svn add a file and delete it 410 # - svn add a file and delete it
297 # - Delete a file 411 # - Delete a file
298 # - svn delete a file 412 # - svn delete a file
299 # - svn move a directory and svn rename files in it 413 # - svn move a directory and svn rename files in it
300 # - add a directory tree. 414 # - add a directory tree.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 # Asserting the tree is not sufficient, svn status must come out clear too. 456 # Asserting the tree is not sufficient, svn status must come out clear too.
343 self.assertEquals('', self._capture(['status'])) 457 self.assertEquals('', self._capture(['status']))
344 458
345 459
346 if __name__ == '__main__': 460 if __name__ == '__main__':
347 if '-v' in sys.argv: 461 if '-v' in sys.argv:
348 logging.basicConfig(level=logging.DEBUG) 462 logging.basicConfig(level=logging.DEBUG)
349 unittest.main() 463 unittest.main()
350 464
351 # vim: ts=2:sw=2:tw=80:et: 465 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « tests/gclient_scm_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698