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

Side by Side Diff: tests/scm_unittest.py

Issue 549733002: Fix gclient branch ref mangling and allow --force branch switches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: lint Created 6 years, 3 months 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) 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 'GetPatchName', 91 'GetPatchName',
92 'GetSha1ForSvnRev', 92 'GetSha1ForSvnRev',
93 'GetSVNBranch', 93 'GetSVNBranch',
94 'GetUpstreamBranch', 94 'GetUpstreamBranch',
95 'IsGitSvn', 95 'IsGitSvn',
96 'IsInsideWorkTree', 96 'IsInsideWorkTree',
97 'IsValidRevision', 97 'IsValidRevision',
98 'IsWorkTreeDirty', 98 'IsWorkTreeDirty',
99 'MatchSvnGlob', 99 'MatchSvnGlob',
100 'ParseGitSvnSha1', 100 'ParseGitSvnSha1',
101 'RefToRemoteRef',
101 'ShortBranchName', 102 'ShortBranchName',
102 ] 103 ]
103 # If this test fails, you should add the relevant test. 104 # If this test fails, you should add the relevant test.
104 self.compareMembers(scm.GIT, members) 105 self.compareMembers(scm.GIT, members)
105 106
106 def testGetEmail(self): 107 def testGetEmail(self):
107 self.mox.StubOutWithMock(scm.GIT, 'Capture') 108 self.mox.StubOutWithMock(scm.GIT, 'Capture')
108 scm.GIT.Capture(['config', 'user.email'], cwd=self.root_dir 109 scm.GIT.Capture(['config', 'user.email'], cwd=self.root_dir
109 ).AndReturn('mini@me.com') 110 ).AndReturn('mini@me.com')
110 self.mox.ReplayAll() 111 self.mox.ReplayAll()
111 self.assertEqual(scm.GIT.GetEmail(self.root_dir), 'mini@me.com') 112 self.assertEqual(scm.GIT.GetEmail(self.root_dir), 'mini@me.com')
112 113
113 def testMatchSvnGlob(self): 114 def testMatchSvnGlob(self):
114 self.assertEquals(scm.GIT.MatchSvnGlob( 115 self.assertEquals(scm.GIT.MatchSvnGlob(
115 'svn://svn.chromium.org/chrome/trunk/src', 116 'svn://svn.chromium.org/chrome/trunk/src',
116 'svn://svn.chromium.org/chrome', 117 'svn://svn.chromium.org/chrome',
117 'trunk/src:refs/remotes/origin/trunk', 118 'trunk/src:refs/remotes/origin/trunk',
118 False), 'refs/remotes/origin/trunk') 119 False), 'refs/remotes/origin/trunk')
119 self.assertEquals(scm.GIT.MatchSvnGlob( 120 self.assertEquals(scm.GIT.MatchSvnGlob(
120 'https://v8.googlecode.com/svn/branches/bleeding_edge', 121 'https://v8.googlecode.com/svn/branches/bleeding_edge',
121 'https://v8.googlecode.com/svn', 122 'https://v8.googlecode.com/svn',
122 'branches/*:refs/remotes/*', 123 'branches/*:refs/remotes/*',
123 True), 'refs/remotes/bleeding_edge') 124 True), 'refs/remotes/bleeding_edge')
124 125
126 def testRefToRemoteRefNoRemote(self):
127 refs = {
128 # local ref for upstream branch-head
129 'refs/remotes/branch-heads/1234': ('refs/remotes/branch-heads/',
130 '1234'),
131 # upstream ref for branch-head
132 'refs/branch-heads/1234': ('refs/remotes/branch-heads/', '1234'),
133 # could be either local or upstream ref, assumed to refer to
134 # upstream, but probably don't want to encourage refs like this.
135 'branch-heads/1234': ('refs/remotes/branch-heads/', '1234'),
136 # actively discouraging refs like this, should prepend with 'refs/'
137 'remotes/branch-heads/1234': None,
138 # might be non-"branch-heads" upstream branches, but can't resolve
139 # without knowing the remote.
140 'refs/heads/1234': None,
141 'heads/1234': None,
142 # underspecified, probably intended to refer to a local branch
143 '1234': None,
144 }
145 for k, v in refs.items():
146 r = scm.GIT.RefToRemoteRef(k)
147 self.assertEqual(r, v, msg='%s -> %s, expected %s' % (k, r, v))
148
149 def testRefToRemoteRefWithRemote(self):
150 remote = 'origin'
151 refs = {
152 # This shouldn't be any different from the NoRemote() version.
153 'refs/branch-heads/1234': ('refs/remotes/branch-heads/', '1234'),
154 # local refs for upstream branch
155 'refs/remotes/%s/foobar' % remote: ('refs/remotes/%s/' % remote,
156 'foobar'),
157 '%s/foobar' % remote: ('refs/remotes/%s/' % remote, 'foobar'),
158 # upstream ref for branch
159 'refs/heads/foobar': ('refs/remotes/%s/' % remote, 'foobar'),
160 # could be either local or upstream ref, assumed to refer to
161 # upstream, but probably don't want to encourage refs like this.
162 'heads/foobar': ('refs/remotes/%s/' % remote, 'foobar'),
163 # underspecified, probably intended to refer to a local branch
164 'foobar': None,
165 }
166 for k, v in refs.items():
167 r = scm.GIT.RefToRemoteRef(k, remote)
168 self.assertEqual(r, v, msg='%s -> %s, expected %s' % (k, r, v))
169
125 170
126 class RealGitTest(fake_repos.FakeReposTestBase): 171 class RealGitTest(fake_repos.FakeReposTestBase):
127 def setUp(self): 172 def setUp(self):
128 super(RealGitTest, self).setUp() 173 super(RealGitTest, self).setUp()
129 self.enabled = self.FAKE_REPOS.set_up_git() 174 self.enabled = self.FAKE_REPOS.set_up_git()
130 if self.enabled: 175 if self.enabled:
131 self.clone_dir = scm.os.path.join(self.FAKE_REPOS.git_root, 'repo_1') 176 self.clone_dir = scm.os.path.join(self.FAKE_REPOS.git_root, 'repo_1')
132 177
133 def testIsValidRevision(self): 178 def testIsValidRevision(self):
134 if not self.enabled: 179 if not self.enabled:
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 # Asserting the tree is not sufficient, svn status must come out clear too. 527 # Asserting the tree is not sufficient, svn status must come out clear too.
483 self.assertEquals('', self._capture(['status'])) 528 self.assertEquals('', self._capture(['status']))
484 529
485 530
486 if __name__ == '__main__': 531 if __name__ == '__main__':
487 if '-v' in sys.argv: 532 if '-v' in sys.argv:
488 logging.basicConfig(level=logging.DEBUG) 533 logging.basicConfig(level=logging.DEBUG)
489 unittest.main() 534 unittest.main()
490 535
491 # vim: ts=2:sw=2:tw=80:et: 536 # 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