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

Side by Side Diff: tests/gclient_scm_test.py

Issue 391052: Group SCM-specific functions in classes to simplify generalization of the interface. (Closed)
Patch Set: One more fix Created 11 years, 1 month 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright 2008-2009 Google Inc. All Rights Reserved. 3 # Copyright 2008-2009 Google Inc. All Rights Reserved.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
(...skipping 15 matching lines...) Expand all
26 from super_mox import mox, SuperMoxBaseTestBase 26 from super_mox import mox, SuperMoxBaseTestBase
27 27
28 28
29 class BaseTestCase(GCBaseTestCase): 29 class BaseTestCase(GCBaseTestCase):
30 def setUp(self): 30 def setUp(self):
31 GCBaseTestCase.setUp(self) 31 GCBaseTestCase.setUp(self)
32 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') 32 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead')
33 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') 33 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
34 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'SubprocessCall') 34 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'SubprocessCall')
35 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') 35 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory')
36 self._CaptureSVNInfo = gclient_scm.CaptureSVNInfo 36 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo
37 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVN') 37 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture')
38 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNInfo') 38 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo')
39 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNStatus') 39 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus')
40 self.mox.StubOutWithMock(gclient_scm, 'RunSVN') 40 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Run')
41 self.mox.StubOutWithMock(gclient_scm, 'RunSVNAndGetFileList') 41 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList')
42 self._scm_wrapper = gclient_scm.CreateSCM 42 self._scm_wrapper = gclient_scm.CreateSCM
43 43
44 44
45 class SVNWrapperTestCase(BaseTestCase): 45 class SVNWrapperTestCase(BaseTestCase):
46 class OptionsObject(object): 46 class OptionsObject(object):
47 def __init__(self, test_case, verbose=False, revision=None): 47 def __init__(self, test_case, verbose=False, revision=None):
48 self.verbose = verbose 48 self.verbose = verbose
49 self.revision = revision 49 self.revision = revision
50 self.manually_grab_svn_rev = True 50 self.manually_grab_svn_rev = True
51 self.deps_os = None 51 self.deps_os = None
52 self.force = False 52 self.force = False
53 self.nohooks = False 53 self.nohooks = False
54 54
55 def Options(self, *args, **kwargs): 55 def Options(self, *args, **kwargs):
56 return self.OptionsObject(self, *args, **kwargs) 56 return self.OptionsObject(self, *args, **kwargs)
57 57
58 def setUp(self): 58 def setUp(self):
59 BaseTestCase.setUp(self) 59 BaseTestCase.setUp(self)
60 self.root_dir = self.Dir() 60 self.root_dir = self.Dir()
61 self.args = self.Args() 61 self.args = self.Args()
62 self.url = self.Url() 62 self.url = self.Url()
63 self.relpath = 'asf' 63 self.relpath = 'asf'
64 64
65 def testDir(self): 65 def testDir(self):
66 members = [ 66 members = [
67 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', 67 'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo',
68 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', 68 'CaptureStatus', 'DiffItem', 'FullUrlForRelativeUrl', 'GetFileProperty',
69 'update', 'url', 69 'IsMoved', 'Run', 'RunAndFilterOutput', 'RunAndGetFileList',
70 'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
71 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url',
70 ] 72 ]
71 73
72 # If you add a member, be sure to add the relevant test! 74 # If you add a member, be sure to add the relevant test!
73 self.compareMembers(self._scm_wrapper(), members) 75 self.compareMembers(self._scm_wrapper(), members)
74 76
75 def testUnsupportedSCM(self): 77 def testUnsupportedSCM(self):
76 args = [self.url, self.root_dir, self.relpath] 78 args = [self.url, self.root_dir, self.relpath]
77 kwargs = {'scm_name' : 'foo'} 79 kwargs = {'scm_name' : 'foo'}
78 exception_msg = 'Unsupported scm %(scm_name)s' % kwargs 80 exception_msg = 'Unsupported scm %(scm_name)s' % kwargs
79 self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs) 81 self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs)
(...skipping 26 matching lines...) Expand all
106 options = self.Options(verbose=True) 108 options = self.Options(verbose=True)
107 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 109 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
108 gclient_scm.os.path.isdir(base_path).AndReturn(False) 110 gclient_scm.os.path.isdir(base_path).AndReturn(False)
109 # It'll to a checkout instead. 111 # It'll to a checkout instead.
110 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 112 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
111 ).AndReturn(False) 113 ).AndReturn(False)
112 print("\n_____ %s is missing, synching instead" % self.relpath) 114 print("\n_____ %s is missing, synching instead" % self.relpath)
113 # Checkout. 115 # Checkout.
114 gclient_scm.os.path.exists(base_path).AndReturn(False) 116 gclient_scm.os.path.exists(base_path).AndReturn(False)
115 files_list = self.mox.CreateMockAnything() 117 files_list = self.mox.CreateMockAnything()
116 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, base_path], 118 gclient_scm.scm.SVN.RunAndGetFileList(options,
117 self.root_dir, files_list) 119 ['checkout', self.url, base_path],
120 self.root_dir, files_list)
118 121
119 self.mox.ReplayAll() 122 self.mox.ReplayAll()
120 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 123 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
121 relpath=self.relpath) 124 relpath=self.relpath)
122 scm.revert(options, self.args, files_list) 125 scm.revert(options, self.args, files_list)
123 126
124 def testRevertNone(self): 127 def testRevertNone(self):
125 options = self.Options(verbose=True) 128 options = self.Options(verbose=True)
126 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 129 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
127 gclient_scm.os.path.isdir(base_path).AndReturn(True) 130 gclient_scm.os.path.isdir(base_path).AndReturn(True)
128 gclient_scm.CaptureSVNStatus(base_path).AndReturn([]) 131 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn([])
129 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], 132 gclient_scm.scm.SVN.RunAndGetFileList(options,
130 base_path, mox.IgnoreArg()) 133 ['update', '--revision', 'BASE'],
134 base_path, mox.IgnoreArg())
131 135
132 self.mox.ReplayAll() 136 self.mox.ReplayAll()
133 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 137 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
134 relpath=self.relpath) 138 relpath=self.relpath)
135 file_list = [] 139 file_list = []
136 scm.revert(options, self.args, file_list) 140 scm.revert(options, self.args, file_list)
137 141
138 def testRevert2Files(self): 142 def testRevert2Files(self):
139 options = self.Options(verbose=True) 143 options = self.Options(verbose=True)
140 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 144 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
141 gclient_scm.os.path.isdir(base_path).AndReturn(True) 145 gclient_scm.os.path.isdir(base_path).AndReturn(True)
142 items = [ 146 items = [
143 ('M ', 'a'), 147 ('M ', 'a'),
144 ('A ', 'b'), 148 ('A ', 'b'),
145 ] 149 ]
146 file_path1 = gclient_scm.os.path.join(base_path, 'a') 150 file_path1 = gclient_scm.os.path.join(base_path, 'a')
147 file_path2 = gclient_scm.os.path.join(base_path, 'b') 151 file_path2 = gclient_scm.os.path.join(base_path, 'b')
148 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) 152 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items)
149 gclient_scm.os.path.exists(file_path1).AndReturn(True) 153 gclient_scm.os.path.exists(file_path1).AndReturn(True)
150 gclient_scm.os.path.isfile(file_path1).AndReturn(True) 154 gclient_scm.os.path.isfile(file_path1).AndReturn(True)
151 gclient_scm.os.remove(file_path1) 155 gclient_scm.os.remove(file_path1)
152 gclient_scm.os.path.exists(file_path2).AndReturn(True) 156 gclient_scm.os.path.exists(file_path2).AndReturn(True)
153 gclient_scm.os.path.isfile(file_path2).AndReturn(True) 157 gclient_scm.os.path.isfile(file_path2).AndReturn(True)
154 gclient_scm.os.remove(file_path2) 158 gclient_scm.os.remove(file_path2)
155 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], 159 gclient_scm.scm.SVN.RunAndGetFileList(options,
156 base_path, mox.IgnoreArg()) 160 ['update', '--revision', 'BASE'],
161 base_path, mox.IgnoreArg())
157 print(gclient_scm.os.path.join(base_path, 'a')) 162 print(gclient_scm.os.path.join(base_path, 'a'))
158 print(gclient_scm.os.path.join(base_path, 'b')) 163 print(gclient_scm.os.path.join(base_path, 'b'))
159 164
160 self.mox.ReplayAll() 165 self.mox.ReplayAll()
161 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 166 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
162 relpath=self.relpath) 167 relpath=self.relpath)
163 file_list = [] 168 file_list = []
164 scm.revert(options, self.args, file_list) 169 scm.revert(options, self.args, file_list)
165 170
166 def testRevertDirectory(self): 171 def testRevertDirectory(self):
167 options = self.Options(verbose=True) 172 options = self.Options(verbose=True)
168 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 173 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
169 gclient_scm.os.path.isdir(base_path).AndReturn(True) 174 gclient_scm.os.path.isdir(base_path).AndReturn(True)
170 items = [ 175 items = [
171 ('~ ', 'a'), 176 ('~ ', 'a'),
172 ] 177 ]
173 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) 178 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items)
174 file_path = gclient_scm.os.path.join(base_path, 'a') 179 file_path = gclient_scm.os.path.join(base_path, 'a')
175 print(file_path) 180 print(file_path)
176 gclient_scm.os.path.exists(file_path).AndReturn(True) 181 gclient_scm.os.path.exists(file_path).AndReturn(True)
177 gclient_scm.os.path.isfile(file_path).AndReturn(False) 182 gclient_scm.os.path.isfile(file_path).AndReturn(False)
178 gclient_scm.os.path.isdir(file_path).AndReturn(True) 183 gclient_scm.os.path.isdir(file_path).AndReturn(True)
179 gclient_scm.gclient_utils.RemoveDirectory(file_path) 184 gclient_scm.gclient_utils.RemoveDirectory(file_path)
180 file_list1 = [] 185 file_list1 = []
181 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], 186 gclient_scm.scm.SVN.RunAndGetFileList(options,
182 base_path, mox.IgnoreArg()) 187 ['update', '--revision', 'BASE'],
188 base_path, mox.IgnoreArg())
183 189
184 self.mox.ReplayAll() 190 self.mox.ReplayAll()
185 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 191 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
186 relpath=self.relpath) 192 relpath=self.relpath)
187 file_list2 = [] 193 file_list2 = []
188 scm.revert(options, self.args, file_list2) 194 scm.revert(options, self.args, file_list2)
189 195
190 def testStatus(self): 196 def testStatus(self):
191 options = self.Options(verbose=True) 197 options = self.Options(verbose=True)
192 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 198 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
193 gclient_scm.os.path.isdir(base_path).AndReturn(True) 199 gclient_scm.os.path.isdir(base_path).AndReturn(True)
194 gclient_scm.RunSVNAndGetFileList(options, ['status'] + self.args, 200 gclient_scm.scm.SVN.RunAndGetFileList(options,
195 base_path, []).AndReturn(None) 201 ['status'] + self.args,
202 base_path, []).AndReturn(None)
196 203
197 self.mox.ReplayAll() 204 self.mox.ReplayAll()
198 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 205 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
199 relpath=self.relpath) 206 relpath=self.relpath)
200 file_list = [] 207 file_list = []
201 self.assertEqual(scm.status(options, self.args, file_list), None) 208 self.assertEqual(scm.status(options, self.args, file_list), None)
202 209
203 210
204 # TODO(maruel): TEST REVISIONS!!! 211 # TODO(maruel): TEST REVISIONS!!!
205 # TODO(maruel): TEST RELOCATE!!! 212 # TODO(maruel): TEST RELOCATE!!!
206 def testUpdateCheckout(self): 213 def testUpdateCheckout(self):
207 options = self.Options(verbose=True) 214 options = self.Options(verbose=True)
208 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 215 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
209 file_info = gclient_scm.gclient_utils.PrintableObject() 216 file_info = gclient_scm.gclient_utils.PrintableObject()
210 file_info.root = 'blah' 217 file_info.root = 'blah'
211 file_info.url = self.url 218 file_info.url = self.url
212 file_info.uuid = 'ABC' 219 file_info.uuid = 'ABC'
213 file_info.revision = 42 220 file_info.revision = 42
214 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 221 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
215 ).AndReturn(False) 222 ).AndReturn(False)
216 # Checkout. 223 # Checkout.
217 gclient_scm.os.path.exists(base_path).AndReturn(False) 224 gclient_scm.os.path.exists(base_path).AndReturn(False)
218 files_list = self.mox.CreateMockAnything() 225 files_list = self.mox.CreateMockAnything()
219 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, 226 gclient_scm.scm.SVN.RunAndGetFileList(options,
220 base_path], self.root_dir, files_list) 227 ['checkout', self.url, base_path],
228 self.root_dir, files_list)
221 self.mox.ReplayAll() 229 self.mox.ReplayAll()
222 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 230 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
223 relpath=self.relpath) 231 relpath=self.relpath)
224 scm.update(options, (), files_list) 232 scm.update(options, (), files_list)
225 233
226 def testUpdateUpdate(self): 234 def testUpdateUpdate(self):
227 options = self.Options(verbose=True) 235 options = self.Options(verbose=True)
228 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 236 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
229 options.force = True 237 options.force = True
230 options.nohooks = False 238 options.nohooks = False
231 file_info = { 239 file_info = {
232 'Repository Root': 'blah', 240 'Repository Root': 'blah',
233 'URL': self.url, 241 'URL': self.url,
234 'UUID': 'ABC', 242 'UUID': 'ABC',
235 'Revision': 42, 243 'Revision': 42,
236 } 244 }
237 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') 245 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
238 ).AndReturn(False) 246 ).AndReturn(False)
239 # Checkout or update. 247 # Checkout or update.
240 gclient_scm.os.path.exists(base_path).AndReturn(True) 248 gclient_scm.os.path.exists(base_path).AndReturn(True)
241 gclient_scm.CaptureSVNInfo(gclient_scm.os.path.join(base_path, "."), '.' 249 gclient_scm.scm.SVN.CaptureInfo(
242 ).AndReturn(file_info) 250 gclient_scm.os.path.join(base_path, "."), '.'
251 ).AndReturn(file_info)
243 # Cheat a bit here. 252 # Cheat a bit here.
244 gclient_scm.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) 253 gclient_scm.scm.SVN.CaptureInfo(file_info['URL'], '.').AndReturn(file_info)
245 additional_args = [] 254 additional_args = []
246 if options.manually_grab_svn_rev: 255 if options.manually_grab_svn_rev:
247 additional_args = ['--revision', str(file_info['Revision'])] 256 additional_args = ['--revision', str(file_info['Revision'])]
248 files_list = [] 257 files_list = []
249 gclient_scm.RunSVNAndGetFileList(options, 258 gclient_scm.scm.SVN.RunAndGetFileList(
250 ['update', base_path] + additional_args, 259 options,
251 self.root_dir, files_list) 260 ['update', base_path] + additional_args,
261 self.root_dir, files_list)
252 262
253 self.mox.ReplayAll() 263 self.mox.ReplayAll()
254 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 264 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
255 relpath=self.relpath) 265 relpath=self.relpath)
256 scm.update(options, (), files_list) 266 scm.update(options, (), files_list)
257 267
258 def testUpdateGit(self): 268 def testUpdateGit(self):
259 options = self.Options(verbose=True) 269 options = self.Options(verbose=True)
260 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') 270 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
261 gclient_scm.os.path.exists(file_path).AndReturn(True) 271 gclient_scm.os.path.exists(file_path).AndReturn(True)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) 359 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
350 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) 360 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
351 SuperMoxBaseTestBase.setUp(self) 361 SuperMoxBaseTestBase.setUp(self)
352 362
353 def tearDown(self): 363 def tearDown(self):
354 SuperMoxBaseTestBase.tearDown(self) 364 SuperMoxBaseTestBase.tearDown(self)
355 shutil.rmtree(self.root_dir) 365 shutil.rmtree(self.root_dir)
356 366
357 def testDir(self): 367 def testDir(self):
358 members = [ 368 members = [
359 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export', 369 'COMMAND', 'Capture', 'CaptureStatus', 'FullUrlForRelativeUrl',
360 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', 370 'RunCommand', 'cleanup', 'diff', 'export', 'relpath', 'revert',
361 'update', 'url', 371 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url',
362 ] 372 ]
363 373
364 # If you add a member, be sure to add the relevant test! 374 # If you add a member, be sure to add the relevant test!
365 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) 375 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
366 376
367 def testRevertMissing(self): 377 def testRevertMissing(self):
368 if not self.enabled: 378 if not self.enabled:
369 return 379 return
370 options = self.Options() 380 options = self.Options()
371 file_path = gclient_scm.os.path.join(self.base_path, 'a') 381 file_path = gclient_scm.os.path.join(self.base_path, 'a')
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 relpath=self.relpath) 512 relpath=self.relpath)
503 rev_info = scm.revinfo(options, (), None) 513 rev_info = scm.revinfo(options, (), None)
504 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') 514 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
505 515
506 516
507 if __name__ == '__main__': 517 if __name__ == '__main__':
508 import unittest 518 import unittest
509 unittest.main() 519 unittest.main()
510 520
511 # vim: ts=2:sw=2:tw=80:et: 521 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« scm.py ('K') | « tests/gcl_unittest.py ('k') | tests/gclient_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698