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

Side by Side Diff: tests/gclient_test.py

Issue 115322: Remove two seams options.gclient and options.scm_wrapper in gclient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 11 years, 7 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 | « gclient.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/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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 self._RunSVN = gclient.RunSVN 114 self._RunSVN = gclient.RunSVN
115 gclient.RunSVN = self.mox.CreateMockAnything() 115 gclient.RunSVN = self.mox.CreateMockAnything()
116 self._RunSVNAndGetFileList = gclient.RunSVNAndGetFileList 116 self._RunSVNAndGetFileList = gclient.RunSVNAndGetFileList
117 gclient.RunSVNAndGetFileList = self.mox.CreateMockAnything() 117 gclient.RunSVNAndGetFileList = self.mox.CreateMockAnything()
118 self._sys_stdout = gclient.sys.stdout 118 self._sys_stdout = gclient.sys.stdout
119 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout) 119 gclient.sys.stdout = self.mox.CreateMock(self._sys_stdout)
120 self._subprocess = gclient.subprocess 120 self._subprocess = gclient.subprocess
121 gclient.subprocess = self.mox.CreateMock(self._subprocess) 121 gclient.subprocess = self.mox.CreateMock(self._subprocess)
122 self._os_path_exists = gclient.os.path.exists 122 self._os_path_exists = gclient.os.path.exists
123 gclient.os.path.exists = self.mox.CreateMockAnything() 123 gclient.os.path.exists = self.mox.CreateMockAnything()
124 self._gclient_gclient = gclient.GClient
125 gclient.GClient = self.mox.CreateMockAnything()
126 self._scm_wrapper = gclient.SCMWrapper
127 gclient.SCMWrapper = self.mox.CreateMockAnything()
124 128
125 def tearDown(self): 129 def tearDown(self):
126 gclient.CaptureSVN = self._CaptureSVN 130 gclient.CaptureSVN = self._CaptureSVN
127 gclient.CaptureSVNInfo = self._CaptureSVNInfo 131 gclient.CaptureSVNInfo = self._CaptureSVNInfo
128 gclient.CaptureSVNStatus = self._CaptureSVNStatus 132 gclient.CaptureSVNStatus = self._CaptureSVNStatus
129 gclient.FileRead = self._FileRead 133 gclient.FileRead = self._FileRead
130 gclient.FileWrite = self._FileWrite 134 gclient.FileWrite = self._FileWrite
131 gclient.RemoveDirectory = self._RemoveDirectory 135 gclient.RemoveDirectory = self._RemoveDirectory
132 gclient.RunSVN = self._RunSVN 136 gclient.RunSVN = self._RunSVN
133 gclient.RunSVNAndGetFileList = self._RunSVNAndGetFileList 137 gclient.RunSVNAndGetFileList = self._RunSVNAndGetFileList
134 gclient.sys.stdout = self._sys_stdout 138 gclient.sys.stdout = self._sys_stdout
135 gclient.subprocess = self._subprocess 139 gclient.subprocess = self._subprocess
136 gclient.os.path.exists = self._os_path_exists 140 gclient.os.path.exists = self._os_path_exists
141 gclient.GClient = self._gclient_gclient
142 gclient.SCMWrapper = self._scm_wrapper
137 143
138 144
139 class GclientTestCase(GClientBaseTestCase): 145 class GclientTestCase(GClientBaseTestCase):
140 class OptionsObject(object): 146 class OptionsObject(object):
141 def __init__(self, test_case, verbose=False, spec=None, 147 def __init__(self, test_case, verbose=False, spec=None,
142 config_filename='a_file_name', 148 config_filename='a_file_name',
143 entries_filename='a_entry_file_name', 149 entries_filename='a_entry_file_name',
144 deps_file='a_deps_file_name', force=False): 150 deps_file='a_deps_file_name', force=False):
145 self.verbose = verbose 151 self.verbose = verbose
146 self.spec = spec 152 self.spec = spec
147 self.config_filename = config_filename 153 self.config_filename = config_filename
148 self.entries_filename = entries_filename 154 self.entries_filename = entries_filename
149 self.deps_file = deps_file 155 self.deps_file = deps_file
150 self.force = force 156 self.force = force
151 self.revisions = [] 157 self.revisions = []
152 self.manually_grab_svn_rev = True 158 self.manually_grab_svn_rev = True
153 self.deps_os = None 159 self.deps_os = None
154 self.head = False 160 self.head = False
155 161
156 # Mox 162 # Mox
157 self.platform = test_case.platform 163 self.platform = test_case.platform
158 self.gclient = test_case.gclient
159 self.scm_wrapper = test_case.scm_wrapper
160 164
161 def setUp(self): 165 def setUp(self):
162 GClientBaseTestCase.setUp(self) 166 GClientBaseTestCase.setUp(self)
163 self.platform = 'darwin' 167 self.platform = 'darwin'
164 168
165 self.gclient = self.mox.CreateMock(gclient.GClient)
166 self.scm_wrapper = self.mox.CreateMock(gclient.SCMWrapper)
167
168 self.args = Args() 169 self.args = Args()
169 self.root_dir = Dir() 170 self.root_dir = Dir()
170 self.url = Url() 171 self.url = Url()
171 172
172 173
173 class GClientCommandsTestCase(GClientBaseTestCase): 174 class GClientCommandsTestCase(GClientBaseTestCase):
174 def testCommands(self): 175 def testCommands(self):
175 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff, 176 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff,
176 gclient.DoHelp, gclient.DoStatus, gclient.DoUpdate, 177 gclient.DoHelp, gclient.DoStatus, gclient.DoUpdate,
177 gclient.DoRevert, gclient.DoRunHooks, gclient.DoRevInfo] 178 gclient.DoRevert, gclient.DoRunHooks, gclient.DoRevInfo]
178 for (k,v) in gclient.gclient_command_map.iteritems(): 179 for (k,v) in gclient.gclient_command_map.iteritems():
179 # If it fails, you need to add a test case for the new command. 180 # If it fails, you need to add a test case for the new command.
180 self.assert_(v in known_commands) 181 self.assert_(v in known_commands)
181 self.mox.ReplayAll() 182 self.mox.ReplayAll()
182 self.mox.VerifyAll() 183 self.mox.VerifyAll()
183 184
184 class TestDoConfig(GclientTestCase): 185 class TestDoConfig(GclientTestCase):
185 def setUp(self): 186 def setUp(self):
186 GclientTestCase.setUp(self) 187 GclientTestCase.setUp(self)
187 # pymox has trouble to mock the class object and not a class instance.
188 self.gclient = self.mox.CreateMockAnything()
189 188
190 def testMissingArgument(self): 189 def testMissingArgument(self):
191 exception_msg = "required argument missing; see 'gclient help config'" 190 exception_msg = "required argument missing; see 'gclient help config'"
192 191
193 self.mox.ReplayAll() 192 self.mox.ReplayAll()
194 self.assertRaisesError(exception_msg, gclient.DoConfig, self.Options(), ()) 193 self.assertRaisesError(exception_msg, gclient.DoConfig, self.Options(), ())
195 self.mox.VerifyAll() 194 self.mox.VerifyAll()
196 195
197 def testExistingClientFile(self): 196 def testExistingClientFile(self):
198 options = self.Options() 197 options = self.Options()
199 exception_msg = ('%s file already exists in the current directory' % 198 exception_msg = ('%s file already exists in the current directory' %
200 options.config_filename) 199 options.config_filename)
201 gclient.os.path.exists(options.config_filename).AndReturn(True) 200 gclient.os.path.exists(options.config_filename).AndReturn(True)
202 201
203 self.mox.ReplayAll() 202 self.mox.ReplayAll()
204 self.assertRaisesError(exception_msg, gclient.DoConfig, options, (1,)) 203 self.assertRaisesError(exception_msg, gclient.DoConfig, options, (1,))
205 self.mox.VerifyAll() 204 self.mox.VerifyAll()
206 205
207 def testFromText(self): 206 def testFromText(self):
208 options = self.Options(spec='config_source_content') 207 options = self.Options(spec='config_source_content')
209 gclient.os.path.exists(options.config_filename).AndReturn(False) 208 gclient.os.path.exists(options.config_filename).AndReturn(False)
210 options.gclient('.', options).AndReturn(options.gclient) 209 gclient.GClient('.', options).AndReturn(gclient.GClient)
211 options.gclient.SetConfig(options.spec) 210 gclient.GClient.SetConfig(options.spec)
212 options.gclient.SaveConfig() 211 gclient.GClient.SaveConfig()
213 212
214 self.mox.ReplayAll() 213 self.mox.ReplayAll()
215 gclient.DoConfig(options, (1,),) 214 gclient.DoConfig(options, (1,),)
216 self.mox.VerifyAll() 215 self.mox.VerifyAll()
217 216
218 def testCreateClientFile(self): 217 def testCreateClientFile(self):
219 options = self.Options() 218 options = self.Options()
220 gclient.os.path.exists(options.config_filename).AndReturn(False) 219 gclient.os.path.exists(options.config_filename).AndReturn(False)
221 options.gclient('.', options).AndReturn(options.gclient) 220 gclient.GClient('.', options).AndReturn(gclient.GClient)
222 options.gclient.SetDefaultConfig('the_name', 'http://svn/url/the_name', 221 gclient.GClient.SetDefaultConfig('the_name', 'http://svn/url/the_name',
223 'other') 222 'other')
224 options.gclient.SaveConfig() 223 gclient.GClient.SaveConfig()
225 224
226 self.mox.ReplayAll() 225 self.mox.ReplayAll()
227 gclient.DoConfig(options, 226 gclient.DoConfig(options,
228 ('http://svn/url/the_name', 'other', 'args', 'ignored')) 227 ('http://svn/url/the_name', 'other', 'args', 'ignored'))
229 self.mox.VerifyAll() 228 self.mox.VerifyAll()
230 229
231 230
232 class TestDoHelp(GclientTestCase): 231 class TestDoHelp(GclientTestCase):
233 def testGetUsage(self): 232 def testGetUsage(self):
234 print(gclient.COMMAND_USAGE_TEXT['config']) 233 print(gclient.COMMAND_USAGE_TEXT['config'])
(...skipping 14 matching lines...) Expand all
249 self.mox.ReplayAll() 248 self.mox.ReplayAll()
250 options = self.Options() 249 options = self.Options()
251 self.assertRaisesError("unknown subcommand 'xyzzy'; see 'gclient help'", 250 self.assertRaisesError("unknown subcommand 'xyzzy'; see 'gclient help'",
252 gclient.DoHelp, options, ('xyzzy',)) 251 gclient.DoHelp, options, ('xyzzy',))
253 self.mox.VerifyAll() 252 self.mox.VerifyAll()
254 253
255 254
256 class GenericCommandTestCase(GclientTestCase): 255 class GenericCommandTestCase(GclientTestCase):
257 def ReturnValue(self, command, function, return_value): 256 def ReturnValue(self, command, function, return_value):
258 options = self.Options() 257 options = self.Options()
259 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) 258 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
260 self.gclient.RunOnDeps(command, self.args).AndReturn(return_value) 259 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
261 260
262 self.mox.ReplayAll() 261 self.mox.ReplayAll()
263 result = function(options, self.args) 262 result = function(options, self.args)
264 self.assertEquals(result, return_value) 263 self.assertEquals(result, return_value)
265 self.mox.VerifyAll() 264 self.mox.VerifyAll()
266 265
267 def BadClient(self, function): 266 def BadClient(self, function):
268 options = self.Options() 267 options = self.Options()
269 self.gclient.LoadCurrentConfig(options).AndReturn(None) 268 gclient.GClient.LoadCurrentConfig(options).AndReturn(None)
270 269
271 self.mox.ReplayAll() 270 self.mox.ReplayAll()
272 self.assertRaisesError( 271 self.assertRaisesError(
273 "client not configured; see 'gclient config'", 272 "client not configured; see 'gclient config'",
274 function, options, self.args) 273 function, options, self.args)
275 self.mox.VerifyAll() 274 self.mox.VerifyAll()
276 275
277 def Verbose(self, command, function): 276 def Verbose(self, command, function):
278 options = self.Options(verbose=True) 277 options = self.Options(verbose=True)
279 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) 278 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
280 text = "# Dummy content\nclient = 'my client'" 279 text = "# Dummy content\nclient = 'my client'"
281 self.gclient.ConfigContent().AndReturn(text) 280 gclient.GClient.ConfigContent().AndReturn(text)
282 print(text) 281 print(text)
283 self.gclient.RunOnDeps(command, self.args).AndReturn(0) 282 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
284 283
285 self.mox.ReplayAll() 284 self.mox.ReplayAll()
286 result = function(options, self.args) 285 result = function(options, self.args)
287 self.assertEquals(result, 0) 286 self.assertEquals(result, 0)
288 self.mox.VerifyAll() 287 self.mox.VerifyAll()
289 288
290 class TestDoCleanup(GenericCommandTestCase): 289 class TestDoCleanup(GenericCommandTestCase):
291 def testGoodClient(self): 290 def testGoodClient(self):
292 self.ReturnValue('cleanup', gclient.DoCleanup, 0) 291 self.ReturnValue('cleanup', gclient.DoCleanup, 0)
293 def testError(self): 292 def testError(self):
(...skipping 21 matching lines...) Expand all
315 def testBadClient(self): 314 def testBadClient(self):
316 self.BadClient(gclient.DoRunHooks) 315 self.BadClient(gclient.DoRunHooks)
317 316
318 317
319 class TestDoUpdate(GenericCommandTestCase): 318 class TestDoUpdate(GenericCommandTestCase):
320 def Options(self, verbose=False, *args, **kwargs): 319 def Options(self, verbose=False, *args, **kwargs):
321 return self.OptionsObject(self, verbose=verbose, *args, **kwargs) 320 return self.OptionsObject(self, verbose=verbose, *args, **kwargs)
322 321
323 def ReturnValue(self, command, function, return_value): 322 def ReturnValue(self, command, function, return_value):
324 options = self.Options() 323 options = self.Options()
325 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) 324 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
326 self.gclient.GetVar("solutions") 325 gclient.GClient.GetVar("solutions")
327 self.gclient.RunOnDeps(command, self.args).AndReturn(return_value) 326 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
328 327
329 self.mox.ReplayAll() 328 self.mox.ReplayAll()
330 result = function(options, self.args) 329 result = function(options, self.args)
331 self.assertEquals(result, return_value) 330 self.assertEquals(result, return_value)
332 self.mox.VerifyAll() 331 self.mox.VerifyAll()
333 332
334 def Verbose(self, command, function): 333 def Verbose(self, command, function):
335 options = self.Options(verbose=True) 334 options = self.Options(verbose=True)
336 self.gclient.LoadCurrentConfig(options).AndReturn(self.gclient) 335 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
337 self.gclient.GetVar("solutions") 336 gclient.GClient.GetVar("solutions")
338 text = "# Dummy content\nclient = 'my client'" 337 text = "# Dummy content\nclient = 'my client'"
339 self.gclient.ConfigContent().AndReturn(text) 338 gclient.GClient.ConfigContent().AndReturn(text)
340 print(text) 339 print(text)
341 self.gclient.RunOnDeps(command, self.args).AndReturn(0) 340 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
342 341
343 self.mox.ReplayAll() 342 self.mox.ReplayAll()
344 result = function(options, self.args) 343 result = function(options, self.args)
345 self.assertEquals(result, 0) 344 self.assertEquals(result, 0)
346 self.mox.VerifyAll() 345 self.mox.VerifyAll()
347 346
348 def Options(self, verbose=False, *args, **kwargs): 347 def Options(self, verbose=False, *args, **kwargs):
349 return self.OptionsObject(self, verbose=verbose, *args, **kwargs) 348 return self.OptionsObject(self, verbose=verbose, *args, **kwargs)
350 349
351 def testBasic(self): 350 def testBasic(self):
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 382
384 class GClientClassTestCase(GclientTestCase): 383 class GClientClassTestCase(GclientTestCase):
385 def testDir(self): 384 def testDir(self):
386 members = [ 385 members = [
387 'ConfigContent', 'FromImpl', 'GetVar', 'LoadCurrentConfig', 386 'ConfigContent', 'FromImpl', 'GetVar', 'LoadCurrentConfig',
388 'RunOnDeps', 'SaveConfig', 'SetConfig', 'SetDefaultConfig', 387 'RunOnDeps', 'SaveConfig', 'SetConfig', 'SetDefaultConfig',
389 'supported_commands', 'PrintRevInfo', 388 'supported_commands', 'PrintRevInfo',
390 ] 389 ]
391 390
392 # If you add a member, be sure to add the relevant test! 391 # If you add a member, be sure to add the relevant test!
393 self.compareMembers(gclient.GClient('root_dir', 'options'), members) 392 self.compareMembers(self._gclient_gclient('root_dir', 'options'), members)
394 393
395 def testSetConfig_ConfigContent_GetVar_SaveConfig_SetDefaultConfig(self): 394 def testSetConfig_ConfigContent_GetVar_SaveConfig_SetDefaultConfig(self):
396 options = self.Options() 395 options = self.Options()
397 text = "# Dummy content\nclient = 'my client'" 396 text = "# Dummy content\nclient = 'my client'"
398 gclient.FileWrite(os.path.join(self.root_dir, options.config_filename), 397 gclient.FileWrite(os.path.join(self.root_dir, options.config_filename),
399 text) 398 text)
400 399
401 self.mox.ReplayAll() 400 self.mox.ReplayAll()
402 client = gclient.GClient(self.root_dir, options) 401 client = self._gclient_gclient(self.root_dir, options)
403 client.SetConfig(text) 402 client.SetConfig(text)
404 self.assertEqual(client.ConfigContent(), text) 403 self.assertEqual(client.ConfigContent(), text)
405 self.assertEqual(client.GetVar('client'), 'my client') 404 self.assertEqual(client.GetVar('client'), 'my client')
406 self.assertEqual(client.GetVar('foo'), None) 405 self.assertEqual(client.GetVar('foo'), None)
407 client.SaveConfig() 406 client.SaveConfig()
408 407
409 solution_name = 'solution name' 408 solution_name = 'solution name'
410 solution_url = 'solution url' 409 solution_url = 'solution url'
411 safesync_url = 'safesync url' 410 safesync_url = 'safesync url'
412 default_text = gclient.DEFAULT_CLIENT_FILE_TEXT % (solution_name, 411 default_text = gclient.DEFAULT_CLIENT_FILE_TEXT % (solution_name,
413 solution_url, 412 solution_url,
414 safesync_url) 413 safesync_url)
415 client.SetDefaultConfig(solution_name, solution_url, safesync_url) 414 client.SetDefaultConfig(solution_name, solution_url, safesync_url)
416 self.assertEqual(client.ConfigContent(), default_text) 415 self.assertEqual(client.ConfigContent(), default_text)
417 solutions = [{ 416 solutions = [{
418 'name': solution_name, 417 'name': solution_name,
419 'url': solution_url, 418 'url': solution_url,
420 'custom_deps': {}, 419 'custom_deps': {},
421 'safesync_url': safesync_url 420 'safesync_url': safesync_url
422 }] 421 }]
423 self.assertEqual(client.GetVar('solutions'), solutions) 422 self.assertEqual(client.GetVar('solutions'), solutions)
424 self.assertEqual(client.GetVar('foo'), None) 423 self.assertEqual(client.GetVar('foo'), None)
425 self.mox.VerifyAll() 424 self.mox.VerifyAll()
426 425
427 def testLoadCurrentConfig(self): 426 def testLoadCurrentConfig(self):
428 # pymox has trouble to mock the class object and not a class instance.
429 self.gclient = self.mox.CreateMockAnything()
430 options = self.Options() 427 options = self.Options()
431 path = os.path.realpath(self.root_dir) 428 path = os.path.realpath(self.root_dir)
432 gclient.os.path.exists(os.path.join(path, options.config_filename) 429 gclient.os.path.exists(os.path.join(path, options.config_filename)
433 ).AndReturn(True) 430 ).AndReturn(True)
434 options.gclient(path, options).AndReturn(options.gclient) 431 gclient.GClient(path, options).AndReturn(gclient.GClient)
435 options.gclient._LoadConfig() 432 gclient.GClient._LoadConfig()
436 433
437 self.mox.ReplayAll() 434 self.mox.ReplayAll()
438 client = gclient.GClient.LoadCurrentConfig(options, self.root_dir) 435 client = self._gclient_gclient.LoadCurrentConfig(options, self.root_dir)
439 self.mox.VerifyAll() 436 self.mox.VerifyAll()
440 437
441 def testRunOnDepsNoDeps(self): 438 def testRunOnDepsNoDeps(self):
442 solution_name = 'testRunOnDepsNoDeps_solution_name' 439 solution_name = 'testRunOnDepsNoDeps_solution_name'
443 gclient_config = ( 440 gclient_config = (
444 "solutions = [ {\n" 441 "solutions = [ {\n"
445 " 'name': '%s',\n" 442 " 'name': '%s',\n"
446 " 'url': '%s',\n" 443 " 'url': '%s',\n"
447 " 'custom_deps': {},\n" 444 " 'custom_deps': {},\n"
448 "} ]\n" 445 "} ]\n"
449 ) % (solution_name, self.url) 446 ) % (solution_name, self.url)
450 447
451 entries_content = ( 448 entries_content = (
452 'entries = [\n' 449 'entries = [\n'
453 ' "%s",\n' 450 ' "%s",\n'
454 ']\n' 451 ']\n'
455 ) % solution_name 452 ) % solution_name
456 453
457 self.scm_wrapper = self.mox.CreateMockAnything()
458 scm_wrapper_sol = self.mox.CreateMock(gclient.SCMWrapper)
459
460 options = self.Options() 454 options = self.Options()
461 455
462 checkout_path = os.path.join(self.root_dir, solution_name) 456 checkout_path = os.path.join(self.root_dir, solution_name)
463 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False) 457 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False)
464 # Expect a check for the entries file and we say there is not one. 458 # Expect a check for the entries file and we say there is not one.
465 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 459 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
466 ).AndReturn(False) 460 ).AndReturn(False)
467 461
468 # An scm will be requested for the solution. 462 # An scm will be requested for the solution.
469 options.scm_wrapper(self.url, self.root_dir, solution_name 463 scm_wrapper_sol = self.mox.CreateMockAnything()
464 gclient.SCMWrapper(self.url, self.root_dir, solution_name
470 ).AndReturn(scm_wrapper_sol) 465 ).AndReturn(scm_wrapper_sol)
471 # Then an update will be performed. 466 # Then an update will be performed.
472 scm_wrapper_sol.RunCommand('update', options, self.args, []) 467 scm_wrapper_sol.RunCommand('update', options, self.args, [])
473 # Then an attempt will be made to read its DEPS file. 468 # Then an attempt will be made to read its DEPS file.
474 gclient.FileRead(os.path.join(self.root_dir, 469 gclient.FileRead(os.path.join(self.root_dir,
475 solution_name, 470 solution_name,
476 options.deps_file)).AndRaise(IOError(2, 'No DEPS file')) 471 options.deps_file)).AndRaise(IOError(2, 'No DEPS file'))
477 472
478 # After everything is done, an attempt is made to write an entries 473 # After everything is done, an attempt is made to write an entries
479 # file. 474 # file.
480 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 475 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
481 entries_content) 476 entries_content)
482 477
483 self.mox.ReplayAll() 478 self.mox.ReplayAll()
484 client = gclient.GClient(self.root_dir, options) 479 client = self._gclient_gclient(self.root_dir, options)
485 client.SetConfig(gclient_config) 480 client.SetConfig(gclient_config)
486 client.RunOnDeps('update', self.args) 481 client.RunOnDeps('update', self.args)
487 self.mox.VerifyAll() 482 self.mox.VerifyAll()
488 483
489 def testRunOnDepsRelativePaths(self): 484 def testRunOnDepsRelativePaths(self):
490 solution_name = 'testRunOnDepsRelativePaths_solution_name' 485 solution_name = 'testRunOnDepsRelativePaths_solution_name'
491 gclient_config = ( 486 gclient_config = (
492 "solutions = [ {\n" 487 "solutions = [ {\n"
493 " 'name': '%s',\n" 488 " 'name': '%s',\n"
494 " 'url': '%s',\n" 489 " 'url': '%s',\n"
495 " 'custom_deps': {},\n" 490 " 'custom_deps': {},\n"
496 "} ]\n" 491 "} ]\n"
497 ) % (solution_name, self.url) 492 ) % (solution_name, self.url)
498 493
499 deps = ( 494 deps = (
500 "use_relative_paths = True\n" 495 "use_relative_paths = True\n"
501 "deps = {\n" 496 "deps = {\n"
502 " 'src/t': 'svn://scm.t/trunk',\n" 497 " 'src/t': 'svn://scm.t/trunk',\n"
503 "}\n") 498 "}\n")
504 499
505 entries_content = ( 500 entries_content = (
506 'entries = [\n' 501 'entries = [\n'
507 ' "%s",\n' 502 ' "%s",\n'
508 ' "%s",\n' 503 ' "%s",\n'
509 ']\n' 504 ']\n'
510 ) % (os.path.join(solution_name, 'src', 't'), solution_name) 505 ) % (os.path.join(solution_name, 'src', 't'), solution_name)
511 506
512 self.scm_wrapper = self.mox.CreateMockAnything() 507 scm_wrapper_sol = self.mox.CreateMockAnything()
513 scm_wrapper_sol = self.mox.CreateMock(gclient.SCMWrapper) 508 scm_wrapper_t = self.mox.CreateMockAnything()
514 scm_wrapper_t = self.mox.CreateMock(gclient.SCMWrapper)
515 509
516 options = self.Options() 510 options = self.Options()
517 511
518 gclient.os.path.exists(os.path.join(self.root_dir, solution_name, 'src', 512 gclient.os.path.exists(os.path.join(self.root_dir, solution_name, 'src',
519 't', '.git') 513 't', '.git')
520 ).AndReturn(False) 514 ).AndReturn(False)
521 gclient.os.path.exists(os.path.join(self.root_dir, solution_name, '.git') 515 gclient.os.path.exists(os.path.join(self.root_dir, solution_name, '.git')
522 ).AndReturn(False) 516 ).AndReturn(False)
523 # Expect a check for the entries file and we say there is not one. 517 # Expect a check for the entries file and we say there is not one.
524 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 518 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
525 ).AndReturn(False) 519 ).AndReturn(False)
526 520
527 # An scm will be requested for the solution. 521 # An scm will be requested for the solution.
528 options.scm_wrapper(self.url, self.root_dir, solution_name 522 gclient.SCMWrapper(self.url, self.root_dir, solution_name
529 ).AndReturn(scm_wrapper_sol) 523 ).AndReturn(scm_wrapper_sol)
530 # Then an update will be performed. 524 # Then an update will be performed.
531 scm_wrapper_sol.RunCommand('update', options, self.args, []) 525 scm_wrapper_sol.RunCommand('update', options, self.args, [])
532 # Then an attempt will be made to read its DEPS file. 526 # Then an attempt will be made to read its DEPS file.
533 gclient.FileRead(os.path.join(self.root_dir, 527 gclient.FileRead(os.path.join(self.root_dir,
534 solution_name, 528 solution_name,
535 options.deps_file)).AndReturn(deps) 529 options.deps_file)).AndReturn(deps)
536 530
537 # Next we expect an scm to be request for dep src/t but it should 531 # Next we expect an scm to be request for dep src/t but it should
538 # use the url specified in deps and the relative path should now 532 # use the url specified in deps and the relative path should now
539 # be relative to the DEPS file. 533 # be relative to the DEPS file.
540 options.scm_wrapper( 534 gclient.SCMWrapper(
541 'svn://scm.t/trunk', 535 'svn://scm.t/trunk',
542 self.root_dir, 536 self.root_dir,
543 os.path.join(solution_name, "src", "t")).AndReturn(scm_wrapper_t) 537 os.path.join(solution_name, "src", "t")).AndReturn(scm_wrapper_t)
544 scm_wrapper_t.RunCommand('update', options, self.args, []) 538 scm_wrapper_t.RunCommand('update', options, self.args, [])
545 539
546 # After everything is done, an attempt is made to write an entries 540 # After everything is done, an attempt is made to write an entries
547 # file. 541 # file.
548 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 542 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
549 entries_content) 543 entries_content)
550 544
551 self.mox.ReplayAll() 545 self.mox.ReplayAll()
552 client = gclient.GClient(self.root_dir, options) 546 client = self._gclient_gclient(self.root_dir, options)
553 client.SetConfig(gclient_config) 547 client.SetConfig(gclient_config)
554 client.RunOnDeps('update', self.args) 548 client.RunOnDeps('update', self.args)
555 self.mox.VerifyAll() 549 self.mox.VerifyAll()
556 550
557 def testRunOnDepsCustomDeps(self): 551 def testRunOnDepsCustomDeps(self):
558 solution_name = 'testRunOnDepsCustomDeps_solution_name' 552 solution_name = 'testRunOnDepsCustomDeps_solution_name'
559 gclient_config = ( 553 gclient_config = (
560 "solutions = [ {\n" 554 "solutions = [ {\n"
561 " 'name': '%s',\n" 555 " 'name': '%s',\n"
562 " 'url': '%s',\n" 556 " 'url': '%s',\n"
(...skipping 12 matching lines...) Expand all
575 ) 569 )
576 570
577 entries_content = ( 571 entries_content = (
578 'entries = [\n' 572 'entries = [\n'
579 ' "%s",\n' 573 ' "%s",\n'
580 ' "src/n",\n' 574 ' "src/n",\n'
581 ' "src/t",\n' 575 ' "src/t",\n'
582 ']\n' 576 ']\n'
583 ) % solution_name 577 ) % solution_name
584 578
585 self.scm_wrapper = self.mox.CreateMockAnything() 579 scm_wrapper_sol = self.mox.CreateMockAnything()
586 scm_wrapper_sol = self.mox.CreateMock(gclient.SCMWrapper) 580 scm_wrapper_t = self.mox.CreateMockAnything()
587 scm_wrapper_t = self.mox.CreateMock(gclient.SCMWrapper) 581 scm_wrapper_n = self.mox.CreateMockAnything()
588 scm_wrapper_n = self.mox.CreateMock(gclient.SCMWrapper)
589 582
590 options = self.Options() 583 options = self.Options()
591 584
592 checkout_path = os.path.join(self.root_dir, solution_name) 585 checkout_path = os.path.join(self.root_dir, solution_name)
593 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False) 586 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False)
594 gclient.os.path.exists(os.path.join(self.root_dir, 'src/n', '.git') 587 gclient.os.path.exists(os.path.join(self.root_dir, 'src/n', '.git')
595 ).AndReturn(False) 588 ).AndReturn(False)
596 gclient.os.path.exists(os.path.join(self.root_dir, 'src/t', '.git') 589 gclient.os.path.exists(os.path.join(self.root_dir, 'src/t', '.git')
597 ).AndReturn(False) 590 ).AndReturn(False)
598 591
599 # Expect a check for the entries file and we say there is not one. 592 # Expect a check for the entries file and we say there is not one.
600 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 593 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
601 ).AndReturn(False) 594 ).AndReturn(False)
602 595
603 # An scm will be requested for the solution. 596 # An scm will be requested for the solution.
604 options.scm_wrapper(self.url, self.root_dir, solution_name 597 gclient.SCMWrapper(self.url, self.root_dir, solution_name
605 ).AndReturn(scm_wrapper_sol) 598 ).AndReturn(scm_wrapper_sol)
606 # Then an update will be performed. 599 # Then an update will be performed.
607 scm_wrapper_sol.RunCommand('update', options, self.args, []) 600 scm_wrapper_sol.RunCommand('update', options, self.args, [])
608 # Then an attempt will be made to read its DEPS file. 601 # Then an attempt will be made to read its DEPS file.
609 gclient.FileRead(os.path.join(checkout_path, options.deps_file) 602 gclient.FileRead(os.path.join(checkout_path, options.deps_file)
610 ).AndReturn(deps) 603 ).AndReturn(deps)
611 604
612 # Next we expect an scm to be request for dep src/n even though it does not 605 # Next we expect an scm to be request for dep src/n even though it does not
613 # exist in the DEPS file. 606 # exist in the DEPS file.
614 options.scm_wrapper('svn://custom.n/trunk', 607 gclient.SCMWrapper('svn://custom.n/trunk',
615 self.root_dir, 608 self.root_dir,
616 "src/n").AndReturn(scm_wrapper_n) 609 "src/n").AndReturn(scm_wrapper_n)
617 610
618 # Next we expect an scm to be request for dep src/t but it should 611 # Next we expect an scm to be request for dep src/t but it should
619 # use the url specified in custom_deps. 612 # use the url specified in custom_deps.
620 options.scm_wrapper('svn://custom.t/trunk', 613 gclient.SCMWrapper('svn://custom.t/trunk',
621 self.root_dir, 614 self.root_dir,
622 "src/t").AndReturn(scm_wrapper_t) 615 "src/t").AndReturn(scm_wrapper_t)
623 616
624 scm_wrapper_n.RunCommand('update', options, self.args, []) 617 scm_wrapper_n.RunCommand('update', options, self.args, [])
625 scm_wrapper_t.RunCommand('update', options, self.args, []) 618 scm_wrapper_t.RunCommand('update', options, self.args, [])
626 619
627 # NOTE: the dep src/b should not create an scm at all. 620 # NOTE: the dep src/b should not create an scm at all.
628 621
629 # After everything is done, an attempt is made to write an entries 622 # After everything is done, an attempt is made to write an entries
630 # file. 623 # file.
631 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 624 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
632 entries_content) 625 entries_content)
633 626
634 self.mox.ReplayAll() 627 self.mox.ReplayAll()
635 client = gclient.GClient(self.root_dir, options) 628 client = self._gclient_gclient(self.root_dir, options)
636 client.SetConfig(gclient_config) 629 client.SetConfig(gclient_config)
637 client.RunOnDeps('update', self.args) 630 client.RunOnDeps('update', self.args)
638 self.mox.VerifyAll() 631 self.mox.VerifyAll()
639 632
640 # Regression test for Issue #11. 633 # Regression test for Issue #11.
641 # http://code.google.com/p/gclient/issues/detail?id=11 634 # http://code.google.com/p/gclient/issues/detail?id=11
642 def testRunOnDepsSharedDependency(self): 635 def testRunOnDepsSharedDependency(self):
643 name_a = 'testRunOnDepsSharedDependency_a' 636 name_a = 'testRunOnDepsSharedDependency_a'
644 name_b = 'testRunOnDepsSharedDependency_b' 637 name_b = 'testRunOnDepsSharedDependency_b'
645 638
(...skipping 17 matching lines...) Expand all
663 "deps = {\n" 656 "deps = {\n"
664 " 'src/t' : 'http://svn.t/trunk',\n" 657 " 'src/t' : 'http://svn.t/trunk',\n"
665 "}\n") 658 "}\n")
666 659
667 entries_content = ( 660 entries_content = (
668 'entries = [\n "%s",\n' 661 'entries = [\n "%s",\n'
669 ' "%s",\n' 662 ' "%s",\n'
670 ' "src/t",\n' 663 ' "src/t",\n'
671 ']\n') % (name_a, name_b) 664 ']\n') % (name_a, name_b)
672 665
673 self.scm_wrapper = self.mox.CreateMockAnything() 666 scm_wrapper_a = self.mox.CreateMockAnything()
674 scm_wrapper_a = self.mox.CreateMock(gclient.SCMWrapper) 667 scm_wrapper_b = self.mox.CreateMockAnything()
675 scm_wrapper_b = self.mox.CreateMock(gclient.SCMWrapper) 668 scm_wrapper_dep = self.mox.CreateMockAnything()
676 scm_wrapper_dep = self.mox.CreateMock(gclient.SCMWrapper)
677 669
678 options = self.Options() 670 options = self.Options()
679 671
680 gclient.os.path.exists(os.path.join(self.root_dir, name_a, '.git') 672 gclient.os.path.exists(os.path.join(self.root_dir, name_a, '.git')
681 ).AndReturn(False) 673 ).AndReturn(False)
682 gclient.os.path.exists(os.path.join(self.root_dir, name_b, '.git') 674 gclient.os.path.exists(os.path.join(self.root_dir, name_b, '.git')
683 ).AndReturn(False) 675 ).AndReturn(False)
684 gclient.os.path.exists(os.path.join(self.root_dir, 'src/t', '.git') 676 gclient.os.path.exists(os.path.join(self.root_dir, 'src/t', '.git')
685 ).AndReturn(False) 677 ).AndReturn(False)
686 678
687 # Expect a check for the entries file and we say there is not one. 679 # Expect a check for the entries file and we say there is not one.
688 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 680 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
689 ).AndReturn(False) 681 ).AndReturn(False)
690 682
691 # An scm will be requested for the first solution. 683 # An scm will be requested for the first solution.
692 options.scm_wrapper(url_a, self.root_dir, name_a).AndReturn( 684 gclient.SCMWrapper(url_a, self.root_dir, name_a).AndReturn(
693 scm_wrapper_a) 685 scm_wrapper_a)
694 # Then an attempt will be made to read it's DEPS file. 686 # Then an attempt will be made to read it's DEPS file.
695 gclient.FileRead(os.path.join(self.root_dir, name_a, options.deps_file) 687 gclient.FileRead(os.path.join(self.root_dir, name_a, options.deps_file)
696 ).AndReturn(deps_a) 688 ).AndReturn(deps_a)
697 # Then an update will be performed. 689 # Then an update will be performed.
698 scm_wrapper_a.RunCommand('update', options, self.args, []) 690 scm_wrapper_a.RunCommand('update', options, self.args, [])
699 691
700 # An scm will be requested for the second solution. 692 # An scm will be requested for the second solution.
701 options.scm_wrapper(url_b, self.root_dir, name_b).AndReturn( 693 gclient.SCMWrapper(url_b, self.root_dir, name_b).AndReturn(
702 scm_wrapper_b) 694 scm_wrapper_b)
703 # Then an attempt will be made to read its DEPS file. 695 # Then an attempt will be made to read its DEPS file.
704 gclient.FileRead(os.path.join(self.root_dir, name_b, options.deps_file) 696 gclient.FileRead(os.path.join(self.root_dir, name_b, options.deps_file)
705 ).AndReturn(deps_b) 697 ).AndReturn(deps_b)
706 # Then an update will be performed. 698 # Then an update will be performed.
707 scm_wrapper_b.RunCommand('update', options, self.args, []) 699 scm_wrapper_b.RunCommand('update', options, self.args, [])
708 700
709 # Finally, an scm is requested for the shared dep. 701 # Finally, an scm is requested for the shared dep.
710 options.scm_wrapper('http://svn.t/trunk', self.root_dir, 'src/t' 702 gclient.SCMWrapper('http://svn.t/trunk', self.root_dir, 'src/t'
711 ).AndReturn(scm_wrapper_dep) 703 ).AndReturn(scm_wrapper_dep)
712 # And an update is run on it. 704 # And an update is run on it.
713 scm_wrapper_dep.RunCommand('update', options, self.args, []) 705 scm_wrapper_dep.RunCommand('update', options, self.args, [])
714 706
715 # After everything is done, an attempt is made to write an entries file. 707 # After everything is done, an attempt is made to write an entries file.
716 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 708 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
717 entries_content) 709 entries_content)
718 710
719 self.mox.ReplayAll() 711 self.mox.ReplayAll()
720 client = gclient.GClient(self.root_dir, options) 712 client = self._gclient_gclient(self.root_dir, options)
721 client.SetConfig(gclient_config) 713 client.SetConfig(gclient_config)
722 client.RunOnDeps('update', self.args) 714 client.RunOnDeps('update', self.args)
723 self.mox.VerifyAll() 715 self.mox.VerifyAll()
724 716
725 def testRunOnDepsSuccess(self): 717 def testRunOnDepsSuccess(self):
726 # Fake .gclient file. 718 # Fake .gclient file.
727 name = 'testRunOnDepsSuccess_solution_name' 719 name = 'testRunOnDepsSuccess_solution_name'
728 gclient_config = """solutions = [ { 720 gclient_config = """solutions = [ {
729 'name': '%s', 721 'name': '%s',
730 'url': '%s', 722 'url': '%s',
731 'custom_deps': {}, 723 'custom_deps': {},
732 }, ]""" % (name, self.url) 724 }, ]""" % (name, self.url)
733 725
734 # pymox has trouble to mock the class object and not a class instance.
735 self.scm_wrapper = self.mox.CreateMockAnything()
736 options = self.Options() 726 options = self.Options()
737 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') 727 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git')
738 ).AndReturn(False) 728 ).AndReturn(False)
739 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 729 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
740 ).AndReturn(False) 730 ).AndReturn(False)
741 options.scm_wrapper(self.url, self.root_dir, name).AndReturn( 731 gclient.SCMWrapper(self.url, self.root_dir, name).AndReturn(
742 options.scm_wrapper) 732 gclient.SCMWrapper)
743 options.scm_wrapper.RunCommand('update', options, self.args, []) 733 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
744 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 734 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
745 ).AndReturn("Boo = 'a'") 735 ).AndReturn("Boo = 'a'")
746 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 736 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
747 'entries = [\n "%s",\n]\n' % name) 737 'entries = [\n "%s",\n]\n' % name)
748 738
749 self.mox.ReplayAll() 739 self.mox.ReplayAll()
750 client = gclient.GClient(self.root_dir, options) 740 client = self._gclient_gclient(self.root_dir, options)
751 client.SetConfig(gclient_config) 741 client.SetConfig(gclient_config)
752 client.RunOnDeps('update', self.args) 742 client.RunOnDeps('update', self.args)
753 self.mox.VerifyAll() 743 self.mox.VerifyAll()
754 744
755 def testRunOnDepsRevisions(self): 745 def testRunOnDepsRevisions(self):
756 def OptIsRev(options, rev): 746 def OptIsRev(options, rev):
757 if not options.revision == str(rev): 747 if not options.revision == str(rev):
758 print("options.revision = %s" % options.revision) 748 print("options.revision = %s" % options.revision)
759 return options.revision == str(rev) 749 return options.revision == str(rev)
760 def OptIsRevNone(options): 750 def OptIsRevNone(options):
(...skipping 30 matching lines...) Expand all
791 entries_content = ( 781 entries_content = (
792 'entries = [\n "src",\n' 782 'entries = [\n "src",\n'
793 ' "foo/third_party/WebKit",\n' 783 ' "foo/third_party/WebKit",\n'
794 ' "src/third_party/cygwin",\n' 784 ' "src/third_party/cygwin",\n'
795 ' "src/third_party/python_24",\n' 785 ' "src/third_party/python_24",\n'
796 ' "src/breakpad/bar",\n' 786 ' "src/breakpad/bar",\n'
797 ']\n') 787 ']\n')
798 cygwin_path = 'dummy path cygwin' 788 cygwin_path = 'dummy path cygwin'
799 webkit_path = 'dummy path webkit' 789 webkit_path = 'dummy path webkit'
800 790
801 # pymox has trouble to mock the class object and not a class instance. 791 scm_wrapper_bleh = self.mox.CreateMockAnything()
802 self.scm_wrapper = self.mox.CreateMockAnything() 792 scm_wrapper_src = self.mox.CreateMockAnything()
803 scm_wrapper_bleh = self.mox.CreateMock(gclient.SCMWrapper) 793 scm_wrapper_src2 = self.mox.CreateMockAnything()
804 scm_wrapper_src = self.mox.CreateMock(gclient.SCMWrapper) 794 scm_wrapper_webkit = self.mox.CreateMockAnything()
805 scm_wrapper_src2 = self.mox.CreateMock(gclient.SCMWrapper) 795 scm_wrapper_breakpad = self.mox.CreateMockAnything()
806 scm_wrapper_webkit = self.mox.CreateMock(gclient.SCMWrapper) 796 scm_wrapper_cygwin = self.mox.CreateMockAnything()
807 scm_wrapper_breakpad = self.mox.CreateMock(gclient.SCMWrapper) 797 scm_wrapper_python = self.mox.CreateMockAnything()
808 scm_wrapper_cygwin = self.mox.CreateMock(gclient.SCMWrapper)
809 scm_wrapper_python = self.mox.CreateMock(gclient.SCMWrapper)
810 options = self.Options() 798 options = self.Options()
811 options.revisions = [ 'src@123', 'foo/third_party/WebKit@42', 799 options.revisions = [ 'src@123', 'foo/third_party/WebKit@42',
812 'src/third_party/cygwin@333' ] 800 'src/third_party/cygwin@333' ]
813 801
814 # Also, pymox doesn't verify the order of function calling w.r.t. different 802 # Also, pymox doesn't verify the order of function calling w.r.t. different
815 # mock objects. Pretty lame. So reorder as we wish to make it clearer. 803 # mock objects. Pretty lame. So reorder as we wish to make it clearer.
816 gclient.FileRead(os.path.join(self.root_dir, 'src', options.deps_file) 804 gclient.FileRead(os.path.join(self.root_dir, 'src', options.deps_file)
817 ).AndReturn(deps_content) 805 ).AndReturn(deps_content)
818 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 806 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
819 entries_content) 807 entries_content)
820 808
821 gclient.os.path.exists(os.path.join(self.root_dir, 'src', '.git') 809 gclient.os.path.exists(os.path.join(self.root_dir, 'src', '.git')
822 ).AndReturn(False) 810 ).AndReturn(False)
823 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', 811 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit',
824 '.git') 812 '.git')
825 ).AndReturn(False) 813 ).AndReturn(False)
826 gclient.os.path.exists(os.path.join(self.root_dir, 'src/third_party/cygwin', 814 gclient.os.path.exists(os.path.join(self.root_dir, 'src/third_party/cygwin',
827 '.git') 815 '.git')
828 ).AndReturn(False) 816 ).AndReturn(False)
829 gclient.os.path.exists(os.path.join(self.root_dir, 817 gclient.os.path.exists(os.path.join(self.root_dir,
830 'src/third_party/python_24', '.git') 818 'src/third_party/python_24', '.git')
831 ).AndReturn(False) 819 ).AndReturn(False)
832 gclient.os.path.exists(os.path.join(self.root_dir, 'src/breakpad/bar', 820 gclient.os.path.exists(os.path.join(self.root_dir, 'src/breakpad/bar',
833 '.git') 821 '.git')
834 ).AndReturn(False) 822 ).AndReturn(False)
835 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 823 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
836 ).AndReturn(False) 824 ).AndReturn(False)
837 825
838 options.scm_wrapper(self.url, self.root_dir, 'src').AndReturn( 826 gclient.SCMWrapper(self.url, self.root_dir, 'src').AndReturn(
839 scm_wrapper_src) 827 scm_wrapper_src)
840 scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, []) 828 scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, [])
841 829
842 options.scm_wrapper(self.url, self.root_dir, 830 gclient.SCMWrapper(self.url, self.root_dir,
843 None).AndReturn(scm_wrapper_src2) 831 None).AndReturn(scm_wrapper_src2)
844 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/cygwin@3248' 832 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/cygwin@3248'
845 ).AndReturn(cygwin_path) 833 ).AndReturn(cygwin_path)
846 834
847 options.scm_wrapper(self.url, self.root_dir, 835 gclient.SCMWrapper(self.url, self.root_dir,
848 None).AndReturn(scm_wrapper_src2) 836 None).AndReturn(scm_wrapper_src2)
849 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/WebKit' 837 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/WebKit'
850 ).AndReturn(webkit_path) 838 ).AndReturn(webkit_path)
851 839
852 options.scm_wrapper(webkit_path, self.root_dir, 840 gclient.SCMWrapper(webkit_path, self.root_dir,
853 'foo/third_party/WebKit').AndReturn(scm_wrapper_webkit) 841 'foo/third_party/WebKit').AndReturn(scm_wrapper_webkit)
854 scm_wrapper_webkit.RunCommand('update', mox.Func(OptIsRev42), self.args, []) 842 scm_wrapper_webkit.RunCommand('update', mox.Func(OptIsRev42), self.args, [])
855 843
856 options.scm_wrapper( 844 gclient.SCMWrapper(
857 'http://google-breakpad.googlecode.com/svn/trunk/src@285', 845 'http://google-breakpad.googlecode.com/svn/trunk/src@285',
858 self.root_dir, 'src/breakpad/bar').AndReturn(scm_wrapper_breakpad) 846 self.root_dir, 'src/breakpad/bar').AndReturn(scm_wrapper_breakpad)
859 scm_wrapper_breakpad.RunCommand('update', mox.Func(OptIsRevNone), 847 scm_wrapper_breakpad.RunCommand('update', mox.Func(OptIsRevNone),
860 self.args, []) 848 self.args, [])
861 849
862 options.scm_wrapper(cygwin_path, self.root_dir, 850 gclient.SCMWrapper(cygwin_path, self.root_dir,
863 'src/third_party/cygwin').AndReturn(scm_wrapper_cygwin) 851 'src/third_party/cygwin').AndReturn(scm_wrapper_cygwin)
864 scm_wrapper_cygwin.RunCommand('update', mox.Func(OptIsRev333), self.args, 852 scm_wrapper_cygwin.RunCommand('update', mox.Func(OptIsRev333), self.args,
865 []) 853 [])
866 854
867 options.scm_wrapper('svn://random_server:123/trunk/python_24@5580', 855 gclient.SCMWrapper('svn://random_server:123/trunk/python_24@5580',
868 self.root_dir, 856 self.root_dir,
869 'src/third_party/python_24').AndReturn( 857 'src/third_party/python_24').AndReturn(
870 scm_wrapper_python) 858 scm_wrapper_python)
871 scm_wrapper_python.RunCommand('update', mox.Func(OptIsRevNone), self.args, 859 scm_wrapper_python.RunCommand('update', mox.Func(OptIsRevNone), self.args,
872 []) 860 [])
873 861
874 self.mox.ReplayAll() 862 self.mox.ReplayAll()
875 client = gclient.GClient(self.root_dir, options) 863 client = self._gclient_gclient(self.root_dir, options)
876 client.SetConfig(gclient_config) 864 client.SetConfig(gclient_config)
877 client.RunOnDeps('update', self.args) 865 client.RunOnDeps('update', self.args)
878 self.mox.VerifyAll() 866 self.mox.VerifyAll()
879 867
880 def testRunOnDepsConflictingRevisions(self): 868 def testRunOnDepsConflictingRevisions(self):
881 # Fake .gclient file. 869 # Fake .gclient file.
882 name = 'testRunOnDepsConflictingRevisions_solution_name' 870 name = 'testRunOnDepsConflictingRevisions_solution_name'
883 gclient_config = """solutions = [ { 871 gclient_config = """solutions = [ {
884 'name': '%s', 872 'name': '%s',
885 'url': '%s', 873 'url': '%s',
886 'custom_deps': {}, 874 'custom_deps': {},
887 'custom_vars': {}, 875 'custom_vars': {},
888 }, ]""" % (name, self.url) 876 }, ]""" % (name, self.url)
889 # Fake DEPS file. 877 # Fake DEPS file.
890 deps_content = """deps = { 878 deps_content = """deps = {
891 'foo/third_party/WebKit': '/trunk/deps/third_party/WebKit', 879 'foo/third_party/WebKit': '/trunk/deps/third_party/WebKit',
892 }""" 880 }"""
893 881
894 options = self.Options() 882 options = self.Options()
895 options.revisions = [ 'foo/third_party/WebKit@42', 883 options.revisions = [ 'foo/third_party/WebKit@42',
896 'foo/third_party/WebKit@43' ] 884 'foo/third_party/WebKit@43' ]
897 client = gclient.GClient(self.root_dir, options) 885 client = self._gclient_gclient(self.root_dir, options)
898 client.SetConfig(gclient_config) 886 client.SetConfig(gclient_config)
899 exception = "Conflicting revision numbers specified." 887 exception = "Conflicting revision numbers specified."
900 try: 888 try:
901 client.RunOnDeps('update', self.args) 889 client.RunOnDeps('update', self.args)
902 except gclient.Error, e: 890 except gclient.Error, e:
903 self.assertEquals(e.args[0], exception) 891 self.assertEquals(e.args[0], exception)
904 else: 892 else:
905 self.fail('%s not raised' % exception) 893 self.fail('%s not raised' % exception)
906 894
907 def testRunOnDepsSuccessVars(self): 895 def testRunOnDepsSuccessVars(self):
(...skipping 11 matching lines...) Expand all
919 } 907 }
920 deps = { 908 deps = {
921 'foo/third_party/WebKit': Var('webkit') + 'WebKit', 909 'foo/third_party/WebKit': Var('webkit') + 'WebKit',
922 }""" 910 }"""
923 entries_content = ( 911 entries_content = (
924 'entries = [\n "foo/third_party/WebKit",\n' 912 'entries = [\n "foo/third_party/WebKit",\n'
925 ' "%s",\n' 913 ' "%s",\n'
926 ']\n') % name 914 ']\n') % name
927 webkit_path = 'dummy path webkit' 915 webkit_path = 'dummy path webkit'
928 916
929 # pymox has trouble to mock the class object and not a class instance. 917 scm_wrapper_webkit = self.mox.CreateMockAnything()
930 self.scm_wrapper = self.mox.CreateMockAnything() 918 scm_wrapper_src = self.mox.CreateMockAnything()
931 scm_wrapper_webkit = self.mox.CreateMock(gclient.SCMWrapper)
932 scm_wrapper_src = self.mox.CreateMock(gclient.SCMWrapper)
933 919
934 options = self.Options() 920 options = self.Options()
935 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 921 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
936 ).AndReturn(deps_content) 922 ).AndReturn(deps_content)
937 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 923 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
938 entries_content) 924 entries_content)
939 925
940 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', 926 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit',
941 '.git')).AndReturn(False) 927 '.git')).AndReturn(False)
942 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') 928 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git')
943 ).AndReturn(False) 929 ).AndReturn(False)
944 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 930 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
945 ).AndReturn(False) 931 ).AndReturn(False)
946 options.scm_wrapper(self.url, self.root_dir, name).AndReturn( 932 gclient.SCMWrapper(self.url, self.root_dir, name).AndReturn(
947 options.scm_wrapper) 933 gclient.SCMWrapper)
948 options.scm_wrapper.RunCommand('update', options, self.args, []) 934 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
949 935
950 options.scm_wrapper(self.url, self.root_dir, 936 gclient.SCMWrapper(self.url, self.root_dir,
951 None).AndReturn(scm_wrapper_src) 937 None).AndReturn(scm_wrapper_src)
952 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar/WebKit' 938 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar/WebKit'
953 ).AndReturn(webkit_path) 939 ).AndReturn(webkit_path)
954 940
955 options.scm_wrapper(webkit_path, self.root_dir, 941 gclient.SCMWrapper(webkit_path, self.root_dir,
956 'foo/third_party/WebKit').AndReturn(options.scm_wrapper) 942 'foo/third_party/WebKit').AndReturn(gclient.SCMWrapper)
957 options.scm_wrapper.RunCommand('update', options, self.args, []) 943 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
958 944
959 self.mox.ReplayAll() 945 self.mox.ReplayAll()
960 client = gclient.GClient(self.root_dir, options) 946 client = self._gclient_gclient(self.root_dir, options)
961 client.SetConfig(gclient_config) 947 client.SetConfig(gclient_config)
962 client.RunOnDeps('update', self.args) 948 client.RunOnDeps('update', self.args)
963 self.mox.VerifyAll() 949 self.mox.VerifyAll()
964 950
965 def testRunOnDepsSuccessCustomVars(self): 951 def testRunOnDepsSuccessCustomVars(self):
966 # Fake .gclient file. 952 # Fake .gclient file.
967 name = 'testRunOnDepsSuccessCustomVars_solution_name' 953 name = 'testRunOnDepsSuccessCustomVars_solution_name'
968 gclient_config = """solutions = [ { 954 gclient_config = """solutions = [ {
969 'name': '%s', 955 'name': '%s',
970 'url': '%s', 956 'url': '%s',
971 'custom_deps': {}, 957 'custom_deps': {},
972 'custom_vars': {'webkit': '/trunk/bar_custom/'}, 958 'custom_vars': {'webkit': '/trunk/bar_custom/'},
973 }, ]""" % (name, self.url) 959 }, ]""" % (name, self.url)
974 # Fake DEPS file. 960 # Fake DEPS file.
975 deps_content = """vars = { 961 deps_content = """vars = {
976 'webkit': '/trunk/bar/', 962 'webkit': '/trunk/bar/',
977 } 963 }
978 deps = { 964 deps = {
979 'foo/third_party/WebKit': Var('webkit') + 'WebKit', 965 'foo/third_party/WebKit': Var('webkit') + 'WebKit',
980 }""" 966 }"""
981 entries_content = ( 967 entries_content = (
982 'entries = [\n "foo/third_party/WebKit",\n' 968 'entries = [\n "foo/third_party/WebKit",\n'
983 ' "%s",\n' 969 ' "%s",\n'
984 ']\n') % name 970 ']\n') % name
985 webkit_path = 'dummy path webkit' 971 webkit_path = 'dummy path webkit'
986 972
987 # pymox has trouble to mock the class object and not a class instance. 973 scm_wrapper_webkit = self.mox.CreateMockAnything()
988 self.scm_wrapper = self.mox.CreateMockAnything() 974 scm_wrapper_src = self.mox.CreateMockAnything()
989 scm_wrapper_webkit = self.mox.CreateMock(gclient.SCMWrapper)
990 scm_wrapper_src = self.mox.CreateMock(gclient.SCMWrapper)
991 975
992 options = self.Options() 976 options = self.Options()
993 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 977 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
994 ).AndReturn(deps_content) 978 ).AndReturn(deps_content)
995 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 979 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
996 entries_content) 980 entries_content)
997 981
998 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', 982 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit',
999 '.git') 983 '.git')
1000 ).AndReturn(False) 984 ).AndReturn(False)
1001 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') 985 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git')
1002 ).AndReturn(False) 986 ).AndReturn(False)
1003 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 987 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
1004 ).AndReturn(False) 988 ).AndReturn(False)
1005 options.scm_wrapper(self.url, self.root_dir, name).AndReturn( 989 gclient.SCMWrapper(self.url, self.root_dir, name).AndReturn(
1006 options.scm_wrapper) 990 gclient.SCMWrapper)
1007 options.scm_wrapper.RunCommand('update', options, self.args, []) 991 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
1008 992
1009 options.scm_wrapper(self.url, self.root_dir, 993 gclient.SCMWrapper(self.url, self.root_dir,
1010 None).AndReturn(scm_wrapper_src) 994 None).AndReturn(scm_wrapper_src)
1011 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar_custom/WebKit' 995 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar_custom/WebKit'
1012 ).AndReturn(webkit_path) 996 ).AndReturn(webkit_path)
1013 997
1014 options.scm_wrapper(webkit_path, self.root_dir, 998 gclient.SCMWrapper(webkit_path, self.root_dir,
1015 'foo/third_party/WebKit').AndReturn(options.scm_wrapper) 999 'foo/third_party/WebKit').AndReturn(gclient.SCMWrapper)
1016 options.scm_wrapper.RunCommand('update', options, self.args, []) 1000 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
1017 1001
1018 self.mox.ReplayAll() 1002 self.mox.ReplayAll()
1019 client = gclient.GClient(self.root_dir, options) 1003 client = self._gclient_gclient(self.root_dir, options)
1020 client.SetConfig(gclient_config) 1004 client.SetConfig(gclient_config)
1021 client.RunOnDeps('update', self.args) 1005 client.RunOnDeps('update', self.args)
1022 self.mox.VerifyAll() 1006 self.mox.VerifyAll()
1023 1007
1024 def testRunOnDepsFailueVars(self): 1008 def testRunOnDepsFailueVars(self):
1025 # Fake .gclient file. 1009 # Fake .gclient file.
1026 name = 'testRunOnDepsFailureVars_solution_name' 1010 name = 'testRunOnDepsFailureVars_solution_name'
1027 gclient_config = """solutions = [ { 1011 gclient_config = """solutions = [ {
1028 'name': '%s', 1012 'name': '%s',
1029 'url': '%s', 1013 'url': '%s',
1030 'custom_deps': {}, 1014 'custom_deps': {},
1031 'custom_vars': {}, 1015 'custom_vars': {},
1032 }, ]""" % (name, self.url) 1016 }, ]""" % (name, self.url)
1033 # Fake DEPS file. 1017 # Fake DEPS file.
1034 deps_content = """deps = { 1018 deps_content = """deps = {
1035 'foo/third_party/WebKit': Var('webkit') + 'WebKit', 1019 'foo/third_party/WebKit': Var('webkit') + 'WebKit',
1036 }""" 1020 }"""
1037 1021
1038 # pymox has trouble to mock the class object and not a class instance.
1039 self.scm_wrapper = self.mox.CreateMockAnything()
1040
1041 options = self.Options() 1022 options = self.Options()
1042 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) 1023 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file)
1043 ).AndReturn(deps_content) 1024 ).AndReturn(deps_content)
1044 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), 1025 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename),
1045 'dummy entries content') 1026 'dummy entries content')
1046 1027
1047 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) 1028 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename)
1048 ).AndReturn(False) 1029 ).AndReturn(False)
1049 options.scm_wrapper(self.url, self.root_dir, name).AndReturn( 1030 gclient.SCMWrapper(self.url, self.root_dir, name).AndReturn(
1050 options.scm_wrapper) 1031 gclient.SCMWrapper)
1051 options.scm_wrapper.RunCommand('update', options, self.args, []) 1032 gclient.SCMWrapper.RunCommand('update', options, self.args, [])
1052 1033
1053 self.mox.ReplayAll() 1034 self.mox.ReplayAll()
1054 client = gclient.GClient(self.root_dir, options) 1035 client = self._gclient_gclient(self.root_dir, options)
1055 client.SetConfig(gclient_config) 1036 client.SetConfig(gclient_config)
1056 exception = "Var is not defined: webkit" 1037 exception = "Var is not defined: webkit"
1057 try: 1038 try:
1058 client.RunOnDeps('update', self.args) 1039 client.RunOnDeps('update', self.args)
1059 except gclient.Error, e: 1040 except gclient.Error, e:
1060 self.assertEquals(e.args[0], exception) 1041 self.assertEquals(e.args[0], exception)
1061 else: 1042 else:
1062 self.fail('%s not raised' % exception) 1043 self.fail('%s not raised' % exception)
1063 1044
1064 def testRunOnDepsFailureInvalidCommand(self): 1045 def testRunOnDepsFailureInvalidCommand(self):
1065 options = self.Options() 1046 options = self.Options()
1066 1047
1067 self.mox.ReplayAll() 1048 self.mox.ReplayAll()
1068 client = gclient.GClient(self.root_dir, options) 1049 client = self._gclient_gclient(self.root_dir, options)
1069 exception = "'foo' is an unsupported command" 1050 exception = "'foo' is an unsupported command"
1070 self.assertRaisesError(exception, gclient.GClient.RunOnDeps, client, 'foo', 1051 self.assertRaisesError(exception, self._gclient_gclient.RunOnDeps, client,
1071 self.args) 1052 'foo', self.args)
1072 self.mox.VerifyAll() 1053 self.mox.VerifyAll()
1073 1054
1074 def testRunOnDepsFailureEmpty(self): 1055 def testRunOnDepsFailureEmpty(self):
1075 options = self.Options() 1056 options = self.Options()
1076 1057
1077 self.mox.ReplayAll() 1058 self.mox.ReplayAll()
1078 client = gclient.GClient(self.root_dir, options) 1059 client = self._gclient_gclient(self.root_dir, options)
1079 exception = "No solution specified" 1060 exception = "No solution specified"
1080 self.assertRaisesError(exception, gclient.GClient.RunOnDeps, client, 1061 self.assertRaisesError(exception, self._gclient_gclient.RunOnDeps, client,
1081 'update', self.args) 1062 'update', self.args)
1082 self.mox.VerifyAll() 1063 self.mox.VerifyAll()
1083 1064
1084 def testFromImpl(self): 1065 def testFromImpl(self):
1085 # TODO(maruel): Test me! 1066 # TODO(maruel): Test me!
1086 pass 1067 pass
1087 1068
1088 def test_PrintRevInfo(self): 1069 def test_PrintRevInfo(self):
1089 # TODO(aharper): no test yet for revinfo, lock it down once we've verified 1070 # TODO(aharper): no test yet for revinfo, lock it down once we've verified
1090 # implementation for Pulse plugin 1071 # implementation for Pulse plugin
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 GClientBaseTestCase.tearDown(self) 1108 GClientBaseTestCase.tearDown(self)
1128 gclient.os.path.isdir = self._os_path_isdir 1109 gclient.os.path.isdir = self._os_path_isdir
1129 1110
1130 def testDir(self): 1111 def testDir(self):
1131 members = [ 1112 members = [
1132 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'relpath', 1113 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'relpath',
1133 'revert', 'scm_name', 'status', 'update', 'url', 1114 'revert', 'scm_name', 'status', 'update', 'url',
1134 ] 1115 ]
1135 1116
1136 # If you add a member, be sure to add the relevant test! 1117 # If you add a member, be sure to add the relevant test!
1137 self.compareMembers(gclient.SCMWrapper(), members) 1118 self.compareMembers(self._scm_wrapper(), members)
1138 1119
1139 def testFullUrlForRelativeUrl(self): 1120 def testFullUrlForRelativeUrl(self):
1140 self.url = 'svn://a/b/c/d' 1121 self.url = 'svn://a/b/c/d'
1141 1122
1142 self.mox.ReplayAll() 1123 self.mox.ReplayAll()
1143 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1124 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1144 relpath=self.relpath) 1125 relpath=self.relpath)
1145 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap') 1126 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap')
1146 self.mox.VerifyAll() 1127 self.mox.VerifyAll()
1147 1128
1148 def testRunCommandException(self): 1129 def testRunCommandException(self):
1149 options = self.Options(verbose=False) 1130 options = self.Options(verbose=False)
1150 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git') 1131 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git')
1151 ).AndReturn(False) 1132 ).AndReturn(False)
1152 1133
1153 self.mox.ReplayAll() 1134 self.mox.ReplayAll()
1154 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1135 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1155 relpath=self.relpath) 1136 relpath=self.relpath)
1156 exception = "Unsupported argument(s): %s" % ','.join(self.args) 1137 exception = "Unsupported argument(s): %s" % ','.join(self.args)
1157 self.assertRaisesError(exception, gclient.SCMWrapper.RunCommand, 1138 self.assertRaisesError(exception, self._scm_wrapper.RunCommand,
1158 scm, 'update', options, self.args) 1139 scm, 'update', options, self.args)
1159 self.mox.VerifyAll() 1140 self.mox.VerifyAll()
1160 1141
1161 def testRunCommandUnknown(self): 1142 def testRunCommandUnknown(self):
1162 # TODO(maruel): if ever used. 1143 # TODO(maruel): if ever used.
1163 pass 1144 pass
1164 1145
1165 def testRevertMissing(self): 1146 def testRevertMissing(self):
1166 options = self.Options(verbose=True) 1147 options = self.Options(verbose=True)
1167 base_path = os.path.join(self.root_dir, self.relpath) 1148 base_path = os.path.join(self.root_dir, self.relpath)
1168 gclient.os.path.isdir(base_path).AndReturn(False) 1149 gclient.os.path.isdir(base_path).AndReturn(False)
1169 # It'll to a checkout instead. 1150 # It'll to a checkout instead.
1170 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) 1151 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False)
1171 print("\n_____ %s is missing, synching instead" % self.relpath) 1152 print("\n_____ %s is missing, synching instead" % self.relpath)
1172 # Checkout. 1153 # Checkout.
1173 gclient.os.path.exists(base_path).AndReturn(False) 1154 gclient.os.path.exists(base_path).AndReturn(False)
1174 files_list = self.mox.CreateMockAnything() 1155 files_list = self.mox.CreateMockAnything()
1175 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path], 1156 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path],
1176 self.root_dir, files_list) 1157 self.root_dir, files_list)
1177 1158
1178 self.mox.ReplayAll() 1159 self.mox.ReplayAll()
1179 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1160 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1180 relpath=self.relpath) 1161 relpath=self.relpath)
1181 scm.revert(options, self.args, files_list) 1162 scm.revert(options, self.args, files_list)
1182 self.mox.VerifyAll() 1163 self.mox.VerifyAll()
1183 1164
1184 def testRevertNone(self): 1165 def testRevertNone(self):
1185 options = self.Options(verbose=True) 1166 options = self.Options(verbose=True)
1186 base_path = os.path.join(self.root_dir, self.relpath) 1167 base_path = os.path.join(self.root_dir, self.relpath)
1187 gclient.os.path.isdir(base_path).AndReturn(True) 1168 gclient.os.path.isdir(base_path).AndReturn(True)
1188 gclient.CaptureSVNStatus(base_path).AndReturn([]) 1169 gclient.CaptureSVNStatus(base_path).AndReturn([])
1189 1170
1190 self.mox.ReplayAll() 1171 self.mox.ReplayAll()
1191 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1172 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1192 relpath=self.relpath) 1173 relpath=self.relpath)
1193 file_list = [] 1174 file_list = []
1194 scm.revert(options, self.args, file_list) 1175 scm.revert(options, self.args, file_list)
1195 self.mox.VerifyAll() 1176 self.mox.VerifyAll()
1196 1177
1197 def testRevert2Files(self): 1178 def testRevert2Files(self):
1198 options = self.Options(verbose=True) 1179 options = self.Options(verbose=True)
1199 base_path = os.path.join(self.root_dir, self.relpath) 1180 base_path = os.path.join(self.root_dir, self.relpath)
1200 gclient.os.path.isdir(base_path).AndReturn(True) 1181 gclient.os.path.isdir(base_path).AndReturn(True)
1201 items = [ 1182 items = [
1202 ('M ', 'a'), 1183 ('M ', 'a'),
1203 ('A ', 'b'), 1184 ('A ', 'b'),
1204 ] 1185 ]
1205 gclient.CaptureSVNStatus(base_path).AndReturn(items) 1186 gclient.CaptureSVNStatus(base_path).AndReturn(items)
1206 1187
1207 print(os.path.join(base_path, 'a')) 1188 print(os.path.join(base_path, 'a'))
1208 print(os.path.join(base_path, 'b')) 1189 print(os.path.join(base_path, 'b'))
1209 gclient.RunSVN(['revert', 'a', 'b'], base_path) 1190 gclient.RunSVN(['revert', 'a', 'b'], base_path)
1210 1191
1211 self.mox.ReplayAll() 1192 self.mox.ReplayAll()
1212 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1193 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1213 relpath=self.relpath) 1194 relpath=self.relpath)
1214 file_list = [] 1195 file_list = []
1215 scm.revert(options, self.args, file_list) 1196 scm.revert(options, self.args, file_list)
1216 self.mox.VerifyAll() 1197 self.mox.VerifyAll()
1217 1198
1218 def testStatus(self): 1199 def testStatus(self):
1219 options = self.Options(verbose=True) 1200 options = self.Options(verbose=True)
1220 base_path = os.path.join(self.root_dir, self.relpath) 1201 base_path = os.path.join(self.root_dir, self.relpath)
1221 gclient.os.path.isdir(base_path).AndReturn(True) 1202 gclient.os.path.isdir(base_path).AndReturn(True)
1222 gclient.RunSVNAndGetFileList(['status'] + self.args, base_path, 1203 gclient.RunSVNAndGetFileList(['status'] + self.args, base_path,
1223 []).AndReturn(None) 1204 []).AndReturn(None)
1224 1205
1225 self.mox.ReplayAll() 1206 self.mox.ReplayAll()
1226 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1207 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1227 relpath=self.relpath) 1208 relpath=self.relpath)
1228 file_list = [] 1209 file_list = []
1229 self.assertEqual(scm.status(options, self.args, file_list), None) 1210 self.assertEqual(scm.status(options, self.args, file_list), None)
1230 self.mox.VerifyAll() 1211 self.mox.VerifyAll()
1231 1212
1232 1213
1233 # TODO(maruel): TEST REVISIONS!!! 1214 # TODO(maruel): TEST REVISIONS!!!
1234 # TODO(maruel): TEST RELOCATE!!! 1215 # TODO(maruel): TEST RELOCATE!!!
1235 def testUpdateCheckout(self): 1216 def testUpdateCheckout(self):
1236 options = self.Options(verbose=True) 1217 options = self.Options(verbose=True)
1237 base_path = os.path.join(self.root_dir, self.relpath) 1218 base_path = os.path.join(self.root_dir, self.relpath)
1238 file_info = gclient.PrintableObject() 1219 file_info = gclient.PrintableObject()
1239 file_info.root = 'blah' 1220 file_info.root = 'blah'
1240 file_info.url = self.url 1221 file_info.url = self.url
1241 file_info.uuid = 'ABC' 1222 file_info.uuid = 'ABC'
1242 file_info.revision = 42 1223 file_info.revision = 42
1243 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) 1224 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False)
1244 # Checkout. 1225 # Checkout.
1245 gclient.os.path.exists(base_path).AndReturn(False) 1226 gclient.os.path.exists(base_path).AndReturn(False)
1246 files_list = self.mox.CreateMockAnything() 1227 files_list = self.mox.CreateMockAnything()
1247 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path], 1228 gclient.RunSVNAndGetFileList(['checkout', self.url, base_path],
1248 self.root_dir, files_list) 1229 self.root_dir, files_list)
1249 self.mox.ReplayAll() 1230 self.mox.ReplayAll()
1250 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1231 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1251 relpath=self.relpath) 1232 relpath=self.relpath)
1252 scm.update(options, (), files_list) 1233 scm.update(options, (), files_list)
1253 self.mox.VerifyAll() 1234 self.mox.VerifyAll()
1254 1235
1255 def testUpdateUpdate(self): 1236 def testUpdateUpdate(self):
1256 options = self.Options(verbose=True) 1237 options = self.Options(verbose=True)
1257 base_path = os.path.join(self.root_dir, self.relpath) 1238 base_path = os.path.join(self.root_dir, self.relpath)
1258 options.force = True 1239 options.force = True
1259 file_info = { 1240 file_info = {
1260 'Repository Root': 'blah', 1241 'Repository Root': 'blah',
1261 'URL': self.url, 1242 'URL': self.url,
1262 'UUID': 'ABC', 1243 'UUID': 'ABC',
1263 'Revision': 42, 1244 'Revision': 42,
1264 } 1245 }
1265 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) 1246 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False)
1266 # Checkout or update. 1247 # Checkout or update.
1267 gclient.os.path.exists(base_path).AndReturn(True) 1248 gclient.os.path.exists(base_path).AndReturn(True)
1268 gclient.CaptureSVNInfo(os.path.join(base_path, "."), '.' 1249 gclient.CaptureSVNInfo(os.path.join(base_path, "."), '.'
1269 ).AndReturn(file_info) 1250 ).AndReturn(file_info)
1270 # Cheat a bit here. 1251 # Cheat a bit here.
1271 gclient.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) 1252 gclient.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info)
1272 additional_args = [] 1253 additional_args = []
1273 if options.manually_grab_svn_rev: 1254 if options.manually_grab_svn_rev:
1274 additional_args = ['--revision', str(file_info['Revision'])] 1255 additional_args = ['--revision', str(file_info['Revision'])]
1275 files_list = [] 1256 files_list = []
1276 gclient.RunSVNAndGetFileList(['update', base_path] + additional_args, 1257 gclient.RunSVNAndGetFileList(['update', base_path] + additional_args,
1277 self.root_dir, files_list) 1258 self.root_dir, files_list)
1278 1259
1279 self.mox.ReplayAll() 1260 self.mox.ReplayAll()
1280 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1261 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1281 relpath=self.relpath) 1262 relpath=self.relpath)
1282 scm.update(options, (), files_list) 1263 scm.update(options, (), files_list)
1283 self.mox.VerifyAll() 1264 self.mox.VerifyAll()
1284 1265
1285 def testUpdateGit(self): 1266 def testUpdateGit(self):
1286 options = self.Options(verbose=True) 1267 options = self.Options(verbose=True)
1287 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git') 1268 gclient.os.path.exists(os.path.join(self.root_dir, self.relpath, '.git')
1288 ).AndReturn(True) 1269 ).AndReturn(True)
1289 print("________ found .git directory; skipping %s" % self.relpath) 1270 print("________ found .git directory; skipping %s" % self.relpath)
1290 1271
1291 self.mox.ReplayAll() 1272 self.mox.ReplayAll()
1292 scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, 1273 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1293 relpath=self.relpath) 1274 relpath=self.relpath)
1294 file_list = [] 1275 file_list = []
1295 scm.update(options, self.args, file_list) 1276 scm.update(options, self.args, file_list)
1296 self.mox.VerifyAll() 1277 self.mox.VerifyAll()
1297 1278
1298 def testGetSVNFileInfo(self): 1279 def testGetSVNFileInfo(self):
1299 xml_text = r"""<?xml version="1.0"?> 1280 xml_text = r"""<?xml version="1.0"?>
1300 <info> 1281 <info>
1301 <entry kind="file" path="%s" revision="14628"> 1282 <entry kind="file" path="%s" revision="14628">
1302 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> 1283 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
1303 <repository><root>http://src.chromium.org/svn</root></repository> 1284 <repository><root>http://src.chromium.org/svn</root></repository>
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 """ 1477 """
1497 gclient.CaptureSVN = CaptureSVNMock 1478 gclient.CaptureSVN = CaptureSVNMock
1498 info = gclient.CaptureSVNStatus(None) 1479 info = gclient.CaptureSVNStatus(None)
1499 self.assertEquals(info, []) 1480 self.assertEquals(info, [])
1500 1481
1501 1482
1502 if __name__ == '__main__': 1483 if __name__ == '__main__':
1503 unittest.main() 1484 unittest.main()
1504 1485
1505 # vim: ts=2:sw=2:tw=80:et: 1486 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698