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

Side by Side Diff: tests/gclient_test.py

Issue 2265002: Reapply 48271 with fix (again) (Closed)
Patch Set: Another fix + more smoke tests Created 10 years, 6 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
« no previous file with comments | « tests/gclient_smoketest.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
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Unit tests for gclient.py."""
7
8 # Fixes include path.
9 from super_mox import mox, SuperMoxTestBase
10
11 import gclient
12
13
14 class BaseTestCase(SuperMoxTestBase):
15 # Like unittest's assertRaises, but checks for Gclient.Error.
16 def assertRaisesError(self, msg, fn, *args, **kwargs):
17 try:
18 fn(*args, **kwargs)
19 except gclient.gclient_utils.Error, e:
20 self.assertEquals(e.args[0], msg)
21 else:
22 self.fail('%s not raised' % msg)
23
24
25 class GClientBaseTestCase(BaseTestCase):
26 def Options(self, *args, **kwargs):
27 return self.OptionsObject(self, *args, **kwargs)
28
29 def setUp(self):
30 BaseTestCase.setUp(self)
31 # These are not tested.
32 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileRead')
33 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileWrite')
34 self.mox.StubOutWithMock(gclient.gclient_utils, 'SubprocessCall')
35 self.mox.StubOutWithMock(gclient.gclient_utils, 'RemoveDirectory')
36 # Mock them to be sure nothing bad happens.
37 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'Capture')
38 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'CaptureInfo')
39 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'CaptureStatus')
40 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'Run')
41 self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'RunAndGetFileList')
42 self._gclient_gclient = gclient.GClient
43 gclient.GClient = self.mox.CreateMockAnything()
44 gclient.GClient.DEPS_FILE = self._gclient_gclient.DEPS_FILE
45 gclient.GClient.DEFAULT_CLIENT_FILE_TEXT = (
46 self._gclient_gclient.DEFAULT_CLIENT_FILE_TEXT)
47 self._scm_wrapper = gclient.gclient_scm.CreateSCM
48 gclient.gclient_scm.CreateSCM = self.mox.CreateMockAnything()
49
50 def tearDown(self):
51 gclient.GClient = self._gclient_gclient
52 gclient.gclient_scm.CreateSCM = self._scm_wrapper
53 BaseTestCase.tearDown(self)
54
55
56 class GclientTestCase(GClientBaseTestCase):
57 class OptionsObject(object):
58 def __init__(self, test_case, verbose=0, spec=None,
59 config_filename='a_file_name',
60 entries_filename='a_entry_file_name',
61 force=False, nohooks=False):
62 self.verbose = verbose
63 self.config_filename = config_filename
64 self.entries_filename = entries_filename
65 self.spec = spec
66 self.name = None
67 self.force = force
68 self.nohooks = nohooks
69 self.revisions = []
70 self.manually_grab_svn_rev = True
71 self.deps_os = None
72 self.head = False
73
74 def setUp(self):
75 GClientBaseTestCase.setUp(self)
76 self.args = self.Args()
77 self.root_dir = self.Dir()
78 self.url = self.Url()
79
80
81 class GClientCommandsTestCase(GClientBaseTestCase):
82 def testCommands(self):
83 known_commands = [gclient.CMDcleanup, gclient.CMDconfig, gclient.CMDdiff,
84 gclient.CMDexport, gclient.CMDhelp, gclient.CMDpack,
85 gclient.CMDrevert, gclient.CMDrevinfo,
86 gclient.CMDrunhooks, gclient.CMDstatus, gclient.CMDsync,
87 gclient.CMDupdate]
88 cmds = [getattr(gclient, x) for x in dir(gclient) if x.startswith('CMD')]
89 self.assertEquals(len(known_commands), len(cmds))
90 for v in cmds:
91 # If it fails, you need to add a test case for the new command.
92 self.assert_(v in known_commands)
93 self.mox.ReplayAll()
94
95 class TestCMDconfig(GclientTestCase):
96 def testMissingArgument(self):
97 exception_msg = "required argument missing; see 'gclient help config'"
98
99 self.mox.ReplayAll()
100 self.assertRaisesError(exception_msg, gclient.CMDconfig, None,
101 self.Options(), ())
102
103 def testExistingClientFile(self):
104 options = self.Options()
105 exception_msg = ('%s file already exists in the current directory' %
106 options.config_filename)
107 gclient.os.path.exists(options.config_filename).AndReturn(True)
108
109 self.mox.ReplayAll()
110 self.assertRaisesError(exception_msg, gclient.CMDconfig, None, options,
111 (1,))
112
113 def testFromText(self):
114 options = self.Options(spec='config_source_content')
115 gclient.os.path.exists(options.config_filename).AndReturn(False)
116 gclient.GClient('.', options).AndReturn(gclient.GClient)
117 gclient.GClient.SetConfig(options.spec)
118 gclient.GClient.SaveConfig()
119
120 self.mox.ReplayAll()
121 gclient.CMDconfig(None, options, (1,),)
122
123 def testCreateClientFile(self):
124 options = self.Options()
125 gclient.os.path.exists(options.config_filename).AndReturn(False)
126 gclient.GClient('.', options).AndReturn(gclient.GClient)
127 gclient.GClient.SetDefaultConfig('the_name', 'http://svn/url/the_name',
128 'other')
129 gclient.GClient.SaveConfig()
130
131 self.mox.ReplayAll()
132 gclient.CMDconfig(None, options,
133 ('http://svn/url/the_name', 'other', 'args', 'ignored'))
134
135
136 class GenericCommandTestCase(GclientTestCase):
137 def ReturnValue(self, command, return_value):
138 options = self.Options()
139 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
140 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
141
142 self.mox.ReplayAll()
143 function = getattr(gclient, 'CMD' + command)
144 result = function(None, options, self.args)
145 self.assertEquals(result, return_value)
146
147 def BadClient(self, command):
148 options = self.Options()
149 gclient.GClient.LoadCurrentConfig(options).AndReturn(None)
150
151 self.mox.ReplayAll()
152 function = getattr(gclient, 'CMD' + command)
153 self.assertRaisesError(
154 "client not configured; see 'gclient config'",
155 function, None, options, self.args)
156
157 def Verbose(self, command):
158 options = self.Options(verbose=True)
159 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
160 text = "# Dummy content\nclient = 'my client'"
161 gclient.GClient.ConfigContent().AndReturn(text)
162 print(text)
163 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
164
165 self.mox.ReplayAll()
166 function = getattr(gclient, 'CMD' + command)
167 result = function(None, options, self.args)
168 self.assertEquals(result, 0)
169
170
171 class TestCMDcleanup(GenericCommandTestCase):
172 def testGoodClient(self):
173 self.ReturnValue('cleanup', 0)
174 def testError(self):
175 self.ReturnValue('cleanup', 42)
176 def testBadClient(self):
177 self.BadClient('cleanup')
178
179
180 class TestCMDstatus(GenericCommandTestCase):
181 def testGoodClient(self):
182 self.ReturnValue('status', 0)
183 def testError(self):
184 self.ReturnValue('status', 42)
185 def testBadClient(self):
186 self.BadClient('status')
187
188
189 class TestCMDrunhooks(GenericCommandTestCase):
190 def Options(self, verbose=False, *args, **kwargs):
191 return self.OptionsObject(self, verbose=verbose, *args, **kwargs)
192
193 def testGoodClient(self):
194 self.ReturnValue('runhooks', 0)
195 def testError(self):
196 self.ReturnValue('runhooks', 42)
197 def testBadClient(self):
198 self.BadClient('runhooks')
199
200
201 class TestCMDupdate(GenericCommandTestCase):
202 def ReturnValue(self, command, return_value):
203 options = self.Options()
204 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
205 gclient.GClient.GetVar("solutions")
206 gclient.GClient.RunOnDeps(command, self.args).AndReturn(return_value)
207
208 self.mox.ReplayAll()
209 function = getattr(gclient, 'CMD' + command)
210 result = function(None, options, self.args)
211 self.assertEquals(result, return_value)
212
213 def Verbose(self, command):
214 options = self.Options(verbose=True)
215 gclient.GClient.LoadCurrentConfig(options).AndReturn(gclient.GClient)
216 gclient.GClient.GetVar("solutions")
217 text = "# Dummy content\nclient = 'my client'"
218 gclient.GClient.ConfigContent().AndReturn(text)
219 print(text)
220 gclient.GClient.RunOnDeps(command, self.args).AndReturn(0)
221
222 self.mox.ReplayAll()
223 function = getattr(gclient, 'CMD' + command)
224 result = function(None, options, self.args)
225 self.assertEquals(result, 0)
226
227 def Options(self, verbose=False, *args, **kwargs):
228 return self.OptionsObject(self, verbose=verbose, *args, **kwargs)
229
230 def testBasic(self):
231 self.ReturnValue('update', 0)
232 def testError(self):
233 self.ReturnValue('update', 42)
234 def testBadClient(self):
235 self.BadClient('update')
236 def testVerbose(self):
237 self.Verbose('update')
238
239
240 class TestCMDdiff(GenericCommandTestCase):
241 def Options(self, *args, **kwargs):
242 return self.OptionsObject(self, *args, **kwargs)
243
244 def testBasic(self):
245 self.ReturnValue('diff', 0)
246 def testError(self):
247 self.ReturnValue('diff', 42)
248 def testBadClient(self):
249 self.BadClient('diff')
250 def testVerbose(self):
251 self.Verbose('diff')
252
253
254 class TestCMDexport(GenericCommandTestCase):
255 def testBasic(self):
256 self.args = ['dir']
257 self.ReturnValue('export', 0)
258 def testError(self):
259 self.args = ['dir']
260 self.ReturnValue('export', 42)
261 def testBadClient(self):
262 self.args = ['dir']
263 self.BadClient('export')
264
265
266 class TestCMDpack(GenericCommandTestCase):
267 def Options(self, *args, **kwargs):
268 return self.OptionsObject(self, *args, **kwargs)
269
270 def testBasic(self):
271 self.ReturnValue('pack', 0)
272 def testError(self):
273 self.ReturnValue('pack', 42)
274 def testBadClient(self):
275 self.BadClient('pack')
276
277
278 class TestCMDrevert(GenericCommandTestCase):
279 def testBasic(self):
280 self.ReturnValue('revert', 0)
281 def testError(self):
282 self.ReturnValue('revert', 42)
283 def testBadClient(self):
284 self.BadClient('revert')
285
286
287 class GClientClassTestCase(GclientTestCase):
288 def testDir(self):
289 members = [
290 'ConfigContent', 'DEFAULT_CLIENT_FILE_TEXT',
291 'DEFAULT_SNAPSHOT_FILE_TEXT', 'DEFAULT_SNAPSHOT_SOLUTION_TEXT',
292 'DEPS_FILE', 'FileImpl', 'FromImpl', 'GetVar', 'LoadCurrentConfig',
293 'PrintRevInfo', 'RunOnDeps', 'SaveConfig', 'SetConfig',
294 'SetDefaultConfig',
295 'deps_os_choices', 'supported_commands',
296 ]
297
298 # If you add a member, be sure to add the relevant test!
299 self.compareMembers(self._gclient_gclient('root_dir', 'options'), members)
300
301 def testSetConfig_ConfigContent_GetVar_SaveConfig_SetDefaultConfig(self):
302 options = self.Options()
303 text = "# Dummy content\nclient = 'my client'"
304 gclient.gclient_utils.FileWrite(
305 gclient.os.path.join(self.root_dir, options.config_filename),
306 text)
307
308 self.mox.ReplayAll()
309 client = self._gclient_gclient(self.root_dir, options)
310 client.SetConfig(text)
311 self.assertEqual(client.ConfigContent(), text)
312 self.assertEqual(client.GetVar('client'), 'my client')
313 self.assertEqual(client.GetVar('foo'), None)
314 client.SaveConfig()
315
316 solution_name = 'solution name'
317 solution_url = 'solution url'
318 safesync_url = 'safesync url'
319 default_text = gclient.GClient.DEFAULT_CLIENT_FILE_TEXT % {
320 'solution_name' : solution_name,
321 'solution_url' : solution_url,
322 'safesync_url' : safesync_url
323 }
324 client.SetDefaultConfig(solution_name, solution_url, safesync_url)
325 self.assertEqual(client.ConfigContent(), default_text)
326 solutions = [{
327 'name': solution_name,
328 'url': solution_url,
329 'custom_deps': {},
330 'safesync_url': safesync_url
331 }]
332 self.assertEqual(client.GetVar('solutions'), solutions)
333 self.assertEqual(client.GetVar('foo'), None)
334
335 def testLoadCurrentConfig(self):
336 options = self.Options()
337 gclient.os.path.realpath(self.root_dir).AndReturn(self.root_dir)
338 gclient.os.path.exists(
339 gclient.os.path.join(self.root_dir, options.config_filename)
340 ).AndReturn(True)
341 gclient.GClient(self.root_dir, options).AndReturn(gclient.GClient)
342 gclient.GClient._LoadConfig()
343
344 self.mox.ReplayAll()
345 client = self._gclient_gclient.LoadCurrentConfig(options, self.root_dir)
346
347 def testRunOnDepsNoDeps(self):
348 solution_name = 'testRunOnDepsNoDeps_solution_name'
349 gclient_config = (
350 "solutions = [ {\n"
351 " 'name': '%s',\n"
352 " 'url': '%s',\n"
353 " 'custom_deps': {},\n"
354 "} ]\n"
355 ) % (solution_name, self.url)
356
357 # pprint.pformat() is non-deterministic in this case!!
358 entries_content = (
359 "entries = \\\n"
360 "{ '%s': '%s'}\n"
361 ) % (solution_name, self.url)
362
363 options = self.Options()
364
365 checkout_path = gclient.os.path.join(self.root_dir, solution_name)
366 gclient.os.path.exists(gclient.os.path.join(checkout_path, '.git')
367 ).AndReturn(False)
368 # Expect a check for the entries file and we say there is not one.
369 gclient.os.path.exists(
370 gclient.os.path.join(self.root_dir, options.entries_filename)
371 ).AndReturn(False)
372
373 # An scm will be requested for the solution.
374 scm_wrapper_sol = self.mox.CreateMockAnything()
375 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, solution_name
376 ).AndReturn(scm_wrapper_sol)
377 # Then an update will be performed.
378 scm_wrapper_sol.RunCommand('update', options, self.args, [])
379 # Then an attempt will be made to read its DEPS file.
380 gclient.gclient_utils.FileRead(
381 gclient.os.path.join(self.root_dir, solution_name,
382 gclient.GClient.DEPS_FILE)
383 ).AndRaise(IOError(2, 'No DEPS file'))
384
385 # After everything is done, an attempt is made to write an entries
386 # file.
387 gclient.gclient_utils.FileWrite(
388 gclient.os.path.join(self.root_dir, options.entries_filename),
389 entries_content)
390
391 self.mox.ReplayAll()
392 client = self._gclient_gclient(self.root_dir, options)
393 client.SetConfig(gclient_config)
394 client.RunOnDeps('update', self.args)
395
396 def testRunOnDepsRelativePaths(self):
397 solution_name = 'testRunOnDepsRelativePaths_solution_name'
398 gclient_config = (
399 "solutions = [ {\n"
400 " 'name': '%s',\n"
401 " 'url': '%s',\n"
402 " 'custom_deps': {},\n"
403 "} ]\n"
404 ) % (solution_name, self.url)
405
406 deps = (
407 "use_relative_paths = True\n"
408 "deps = {\n"
409 " 'src/t': 'svn://scm.t/trunk',\n"
410 "}\n")
411 entry_path = gclient.os.path.join(solution_name, 'src', 't'
412 ).replace('\\', '\\\\')
413 entries_content = (
414 "entries = \\\n"
415 "{ '%s': '%s',\n"
416 " '%s': 'svn://scm.t/trunk'}\n"
417 ) % (solution_name, self.url, entry_path)
418
419 scm_wrapper_sol = self.mox.CreateMockAnything()
420 scm_wrapper_t = self.mox.CreateMockAnything()
421
422 options = self.Options()
423
424 gclient.os.path.exists(
425 gclient.os.path.join(self.root_dir, solution_name, 'src', 't', '.git')
426 ).AndReturn(False)
427 gclient.os.path.exists(
428 gclient.os.path.join(self.root_dir, solution_name, '.git')
429 ).AndReturn(False)
430 # Expect a check for the entries file and we say there is not one.
431 gclient.os.path.exists(
432 gclient.os.path.join(self.root_dir, options.entries_filename)
433 ).AndReturn(False)
434
435 # An scm will be requested for the solution.
436 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, solution_name
437 ).AndReturn(scm_wrapper_sol)
438 # Then an update will be performed.
439 scm_wrapper_sol.RunCommand('update', options, self.args, [])
440 # Then an attempt will be made to read its DEPS file.
441 gclient.gclient_utils.FileRead(
442 gclient.os.path.join(self.root_dir, solution_name,
443 gclient.GClient.DEPS_FILE)
444 ).AndReturn(deps)
445
446 # Next we expect an scm to be request for dep src/t but it should
447 # use the url specified in deps and the relative path should now
448 # be relative to the DEPS file.
449 gclient.gclient_scm.CreateSCM(
450 'svn://scm.t/trunk',
451 self.root_dir,
452 gclient.os.path.join(solution_name, "src", "t")
453 ).AndReturn(scm_wrapper_t)
454 scm_wrapper_t.RunCommand('update', options, self.args, [])
455
456 # After everything is done, an attempt is made to write an entries
457 # file.
458 gclient.gclient_utils.FileWrite(
459 gclient.os.path.join(self.root_dir, options.entries_filename),
460 entries_content)
461
462 self.mox.ReplayAll()
463 client = self._gclient_gclient(self.root_dir, options)
464 client.SetConfig(gclient_config)
465 client.RunOnDeps('update', self.args)
466
467 def testRunOnDepsCustomDeps(self):
468 solution_name = 'testRunOnDepsCustomDeps_solution_name'
469 gclient_config = (
470 "solutions = [ {\n"
471 " 'name': '%s',\n"
472 " 'url': '%s',\n"
473 " 'custom_deps': {\n"
474 " 'src/b': None,\n"
475 " 'src/n': 'svn://custom.n/trunk',\n"
476 " 'src/t': 'svn://custom.t/trunk',\n"
477 " }\n} ]\n"
478 ) % (solution_name, self.url)
479
480 deps = (
481 "deps = {\n"
482 " 'src/b': 'svn://original.b/trunk',\n"
483 " 'src/t': 'svn://original.t/trunk',\n"
484 "}\n"
485 )
486
487 entries_content = (
488 "entries = \\\n"
489 "{ 'src/n': 'svn://custom.n/trunk',\n"
490 " 'src/t': 'svn://custom.t/trunk',\n"
491 " '%s': '%s'}\n"
492 ) % (solution_name, self.url)
493
494 scm_wrapper_sol = self.mox.CreateMockAnything()
495 scm_wrapper_t = self.mox.CreateMockAnything()
496 scm_wrapper_n = self.mox.CreateMockAnything()
497
498 options = self.Options()
499
500 checkout_path = gclient.os.path.join(self.root_dir, solution_name)
501 gclient.os.path.exists(
502 gclient.os.path.join(checkout_path, '.git')).AndReturn(False)
503 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'src/n', '.git')
504 ).AndReturn(False)
505 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'src/t', '.git')
506 ).AndReturn(False)
507
508 # Expect a check for the entries file and we say there is not one.
509 gclient.os.path.exists(
510 gclient.os.path.join(self.root_dir, options.entries_filename)
511 ).AndReturn(False)
512
513 # An scm will be requested for the solution.
514 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, solution_name
515 ).AndReturn(scm_wrapper_sol)
516 # Then an update will be performed.
517 scm_wrapper_sol.RunCommand('update', options, self.args, [])
518 # Then an attempt will be made to read its DEPS file.
519 gclient.gclient_utils.FileRead(
520 gclient.os.path.join(checkout_path, gclient.GClient.DEPS_FILE)
521 ).AndReturn(deps)
522
523 # Next we expect an scm to be request for dep src/n even though it does not
524 # exist in the DEPS file.
525 gclient.gclient_scm.CreateSCM('svn://custom.n/trunk',
526 self.root_dir,
527 "src/n").AndReturn(scm_wrapper_n)
528
529 # Next we expect an scm to be request for dep src/t but it should
530 # use the url specified in custom_deps.
531 gclient.gclient_scm.CreateSCM('svn://custom.t/trunk',
532 self.root_dir,
533 "src/t").AndReturn(scm_wrapper_t)
534
535 scm_wrapper_n.RunCommand('update', options, self.args, [])
536 scm_wrapper_t.RunCommand('update', options, self.args, [])
537
538 # NOTE: the dep src/b should not create an scm at all.
539
540 # After everything is done, an attempt is made to write an entries
541 # file.
542 gclient.gclient_utils.FileWrite(
543 gclient.os.path.join(self.root_dir, options.entries_filename),
544 entries_content)
545
546 self.mox.ReplayAll()
547 client = self._gclient_gclient(self.root_dir, options)
548 client.SetConfig(gclient_config)
549 client.RunOnDeps('update', self.args)
550
551 # Regression test for Issue #11.
552 # http://code.google.com/p/gclient/issues/detail?id=11
553 def testRunOnDepsSharedDependency(self):
554 name_a = 'testRunOnDepsSharedDependency_a'
555 name_b = 'testRunOnDepsSharedDependency_b'
556
557 url_a = self.url + '/a'
558 url_b = self.url + '/b'
559
560 # config declares two solutions and each has a dependency to place
561 # http://svn.t/trunk at src/t.
562 gclient_config = (
563 "solutions = [ {\n"
564 " 'name': '%s',\n"
565 " 'url': '%s',\n"
566 " 'custom_deps': {},\n"
567 "}, {\n"
568 " 'name': '%s',\n"
569 " 'url': '%s',\n"
570 " 'custom_deps': {},\n"
571 "}\n]\n") % (name_a, url_a, name_b, url_b)
572
573 deps_b = deps_a = (
574 "deps = {\n"
575 " 'src/t' : 'http://svn.t/trunk',\n"
576 "}\n")
577
578 entries_content = (
579 "entries = \\\n"
580 "{ 'src/t': 'http://svn.t/trunk',\n"
581 " '%s': '%s',\n"
582 " '%s': '%s'}\n"
583 ) % (name_a, url_a, name_b, url_b)
584
585 scm_wrapper_a = self.mox.CreateMockAnything()
586 scm_wrapper_b = self.mox.CreateMockAnything()
587 scm_wrapper_dep = self.mox.CreateMockAnything()
588
589 options = self.Options()
590
591 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name_a, '.git')
592 ).AndReturn(False)
593 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name_b, '.git')
594 ).AndReturn(False)
595 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'src/t', '.git')
596 ).AndReturn(False)
597
598 # Expect a check for the entries file and we say there is not one.
599 gclient.os.path.exists(
600 gclient.os.path.join(self.root_dir, options.entries_filename)
601 ).AndReturn(False)
602
603 # An scm will be requested for the first solution.
604 gclient.gclient_scm.CreateSCM(url_a, self.root_dir, name_a).AndReturn(
605 scm_wrapper_a)
606 # Then an attempt will be made to read it's DEPS file.
607 gclient.gclient_utils.FileRead(
608 gclient.os.path.join(self.root_dir, name_a, gclient.GClient.DEPS_FILE)
609 ).AndReturn(deps_a)
610 # Then an update will be performed.
611 scm_wrapper_a.RunCommand('update', options, self.args, [])
612
613 # An scm will be requested for the second solution.
614 gclient.gclient_scm.CreateSCM(url_b, self.root_dir, name_b).AndReturn(
615 scm_wrapper_b)
616 # Then an attempt will be made to read its DEPS file.
617 gclient.gclient_utils.FileRead(
618 gclient.os.path.join(self.root_dir, name_b, gclient.GClient.DEPS_FILE)
619 ).AndReturn(deps_b)
620 # Then an update will be performed.
621 scm_wrapper_b.RunCommand('update', options, self.args, [])
622
623 # Finally, an scm is requested for the shared dep.
624 gclient.gclient_scm.CreateSCM('http://svn.t/trunk', self.root_dir, 'src/t'
625 ).AndReturn(scm_wrapper_dep)
626 # And an update is run on it.
627 scm_wrapper_dep.RunCommand('update', options, self.args, [])
628
629 # After everything is done, an attempt is made to write an entries file.
630 gclient.gclient_utils.FileWrite(
631 gclient.os.path.join(self.root_dir, options.entries_filename),
632 entries_content)
633
634 self.mox.ReplayAll()
635 client = self._gclient_gclient(self.root_dir, options)
636 client.SetConfig(gclient_config)
637 client.RunOnDeps('update', self.args)
638
639 def testRunOnDepsSuccess(self):
640 # Fake .gclient file.
641 name = 'testRunOnDepsSuccess_solution_name'
642 gclient_config = """solutions = [ {
643 'name': '%s',
644 'url': '%s',
645 'custom_deps': {},
646 }, ]""" % (name, self.url)
647
648 # pprint.pformat() is non-deterministic in this case!!
649 entries_content = (
650 "entries = \\\n"
651 "{ '%s': '%s'}\n"
652 ) % (name, self.url)
653
654 options = self.Options()
655 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git')
656 ).AndReturn(False)
657 gclient.os.path.exists(
658 gclient.os.path.join(self.root_dir, options.entries_filename)
659 ).AndReturn(False)
660 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
661 gclient.gclient_scm.CreateSCM)
662 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
663 gclient.gclient_utils.FileRead(
664 gclient.os.path.join(self.root_dir, name, gclient.GClient.DEPS_FILE)
665 ).AndReturn("Boo = 'a'")
666 gclient.gclient_utils.FileWrite(
667 gclient.os.path.join(self.root_dir, options.entries_filename),
668 entries_content)
669
670 self.mox.ReplayAll()
671 client = self._gclient_gclient(self.root_dir, options)
672 client.SetConfig(gclient_config)
673 client.RunOnDeps('update', self.args)
674
675 def testRunOnDepsRevisions(self):
676 def OptIsRev(options, rev):
677 if not options.revision == str(rev):
678 print("options.revision = %s" % options.revision)
679 return options.revision == str(rev)
680 def OptIsRevNone(options):
681 if options.revision:
682 print("options.revision = %s" % options.revision)
683 return options.revision == None
684 def OptIsRev42(options):
685 return OptIsRev(options, 42)
686 def OptIsRev123(options):
687 return OptIsRev(options, 123)
688 def OptIsRev333(options):
689 return OptIsRev(options, 333)
690
691 # Fake .gclient file.
692 gclient_config = """solutions = [ {
693 'name': 'src',
694 'url': '%s',
695 'custom_deps': {},
696 }, ]""" % self.url
697 # Fake DEPS file.
698 deps_content = """deps = {
699 'src/breakpad/bar': 'http://google-breakpad.googlecode.com/svn/trunk/src@285',
700 'foo/third_party/WebKit': '/trunk/deps/third_party/WebKit',
701 'src/third_party/cygwin': '/trunk/deps/third_party/cygwin@3248',
702 }
703 deps_os = {
704 'win': {
705 'src/foosad/asdf': 'svn://random_server:123/asd/python_24@5580',
706 },
707 'mac': {
708 'src/third_party/python_24': 'svn://random_server:123/trunk/python_24@5580',
709 },
710 }"""
711
712 cygwin_path = 'dummy path cygwin'
713 webkit_path = 'dummy path webkit'
714
715 entries_content = (
716 "entries = \\\n"
717 "{ 'foo/third_party/WebKit': '%s',\n"
718 " 'src': '%s',\n"
719 " 'src/breakpad/bar':"
720 " 'http://google-breakpad.googlecode.com/svn/trunk/src@285',\n"
721 " 'src/third_party/cygwin': '%s',\n"
722 " 'src/third_party/python_24':"
723 " 'svn://random_server:123/trunk/python_24@5580'}\n"
724 ) % (webkit_path, self.url, cygwin_path)
725
726 scm_wrapper_bleh = self.mox.CreateMockAnything()
727 scm_wrapper_src = self.mox.CreateMockAnything()
728 scm_wrapper_src2 = self.mox.CreateMockAnything()
729 scm_wrapper_webkit = self.mox.CreateMockAnything()
730 scm_wrapper_breakpad = self.mox.CreateMockAnything()
731 scm_wrapper_cygwin = self.mox.CreateMockAnything()
732 scm_wrapper_python = self.mox.CreateMockAnything()
733 options = self.Options()
734 options.revisions = [ 'src@123', 'foo/third_party/WebKit@42',
735 'src/third_party/cygwin@333' ]
736 options.deps_os = 'mac'
737 # Also, pymox doesn't verify the order of function calling w.r.t. different
738 # mock objects. Pretty lame. So reorder as we wish to make it clearer.
739 gclient.gclient_utils.FileRead(
740 gclient.os.path.join(self.root_dir, 'src', gclient.GClient.DEPS_FILE)
741 ).AndReturn(deps_content)
742 gclient.gclient_utils.FileWrite(
743 gclient.os.path.join(self.root_dir, options.entries_filename),
744 entries_content)
745
746 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'src', '.git')
747 ).AndReturn(False)
748 gclient.os.path.exists(
749 gclient.os.path.join(self.root_dir, 'foo/third_party/WebKit', '.git')
750 ).AndReturn(False)
751 gclient.os.path.exists(
752 gclient.os.path.join(self.root_dir, 'src/third_party/cygwin', '.git')
753 ).AndReturn(False)
754 gclient.os.path.exists(
755 gclient.os.path.join(self.root_dir, 'src/third_party/python_24', '.git')
756 ).AndReturn(False)
757 gclient.os.path.exists(
758 gclient.os.path.join(self.root_dir, 'src/breakpad/bar', '.git')
759 ).AndReturn(False)
760 gclient.os.path.exists(
761 gclient.os.path.join(self.root_dir, options.entries_filename)
762 ).AndReturn(False)
763
764 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, 'src').AndReturn(
765 scm_wrapper_src)
766 scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, [])
767
768 gclient.gclient_scm.CreateSCM(self.url, self.root_dir,
769 None).AndReturn(scm_wrapper_src2)
770 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/cygwin@3248'
771 ).AndReturn(cygwin_path)
772
773 gclient.gclient_scm.CreateSCM(self.url, self.root_dir,
774 None).AndReturn(scm_wrapper_src2)
775 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/WebKit'
776 ).AndReturn(webkit_path)
777
778 gclient.gclient_scm.CreateSCM(
779 webkit_path, self.root_dir, 'foo/third_party/WebKit'
780 ).AndReturn(scm_wrapper_webkit)
781 scm_wrapper_webkit.RunCommand('update', mox.Func(OptIsRev42), self.args, [])
782
783 gclient.gclient_scm.CreateSCM(
784 'http://google-breakpad.googlecode.com/svn/trunk/src@285',
785 self.root_dir, 'src/breakpad/bar').AndReturn(scm_wrapper_breakpad)
786 scm_wrapper_breakpad.RunCommand('update', mox.Func(OptIsRevNone),
787 self.args, [])
788
789 gclient.gclient_scm.CreateSCM(
790 cygwin_path, self.root_dir, 'src/third_party/cygwin'
791 ).AndReturn(scm_wrapper_cygwin)
792 scm_wrapper_cygwin.RunCommand('update', mox.Func(OptIsRev333), self.args,
793 [])
794
795 gclient.gclient_scm.CreateSCM(
796 'svn://random_server:123/trunk/python_24@5580',
797 self.root_dir,
798 'src/third_party/python_24'
799 ).AndReturn(scm_wrapper_python)
800 scm_wrapper_python.RunCommand('update', mox.Func(OptIsRevNone), self.args,
801 [])
802
803 self.mox.ReplayAll()
804 client = self._gclient_gclient(self.root_dir, options)
805 client.SetConfig(gclient_config)
806 client.RunOnDeps('update', self.args)
807
808 def testRunOnDepsConflictingRevisions(self):
809 # Fake .gclient file.
810 name = 'testRunOnDepsConflictingRevisions_solution_name'
811 gclient_config = """solutions = [ {
812 'name': '%s',
813 'url': '%s',
814 'custom_deps': {},
815 'custom_vars': {},
816 }, ]""" % (name, self.url)
817 # Fake DEPS file.
818 deps_content = """deps = {
819 'foo/third_party/WebKit': '/trunk/deps/third_party/WebKit',
820 }"""
821
822 options = self.Options()
823 options.revisions = [ 'foo/third_party/WebKit@42',
824 'foo/third_party/WebKit@43' ]
825 client = self._gclient_gclient(self.root_dir, options)
826 client.SetConfig(gclient_config)
827 exception = "Conflicting revision numbers specified."
828 try:
829 client.RunOnDeps('update', self.args)
830 except gclient.gclient_utils.Error, e:
831 self.assertEquals(e.args[0], exception)
832 else:
833 self.fail('%s not raised' % exception)
834
835 def testRunOnDepsSuccessVars(self):
836 # Fake .gclient file.
837 name = 'testRunOnDepsSuccessVars_solution_name'
838 gclient_config = """solutions = [ {
839 'name': '%s',
840 'url': '%s',
841 'custom_deps': {},
842 'custom_vars': {},
843 }, ]""" % (name, self.url)
844 # Fake DEPS file.
845 deps_content = """vars = {
846 'webkit': '/trunk/bar/',
847 }
848 deps = {
849 'foo/third_party/WebKit': Var('webkit') + 'WebKit',
850 }"""
851
852 webkit_path = 'dummy path webkit'
853
854 entries_content = (
855 "entries = \\\n"
856 "{ 'foo/third_party/WebKit': '%s',\n"
857 " '%s': '%s'}\n"
858 ) % (webkit_path, name, self.url)
859
860 scm_wrapper_webkit = self.mox.CreateMockAnything()
861 scm_wrapper_src = self.mox.CreateMockAnything()
862
863 options = self.Options()
864 gclient.gclient_utils.FileRead(
865 gclient.os.path.join(self.root_dir, name,
866 gclient.GClient.DEPS_FILE)
867 ).AndReturn(deps_content)
868 gclient.gclient_utils.FileWrite(
869 gclient.os.path.join(self.root_dir, options.entries_filename),
870 entries_content)
871
872 gclient.os.path.exists(
873 gclient.os.path.join(self.root_dir, 'foo/third_party/WebKit', '.git')
874 ).AndReturn(False)
875 gclient.os.path.exists(
876 gclient.os.path.join(self.root_dir, name, '.git')
877 ).AndReturn(False)
878 gclient.os.path.exists(
879 gclient.os.path.join(self.root_dir, options.entries_filename)
880 ).AndReturn(False)
881 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
882 gclient.gclient_scm.CreateSCM)
883 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
884
885 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, None
886 ).AndReturn(scm_wrapper_src)
887 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar/WebKit'
888 ).AndReturn(webkit_path)
889
890 gclient.gclient_scm.CreateSCM(
891 webkit_path, self.root_dir, 'foo/third_party/WebKit'
892 ).AndReturn(gclient.gclient_scm.CreateSCM)
893 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
894
895 self.mox.ReplayAll()
896 client = self._gclient_gclient(self.root_dir, options)
897 client.SetConfig(gclient_config)
898 client.RunOnDeps('update', self.args)
899
900 def testRunOnDepsSuccessCustomVars(self):
901 # Fake .gclient file.
902 name = 'testRunOnDepsSuccessCustomVars_solution_name'
903 gclient_config = """solutions = [ {
904 'name': '%s',
905 'url': '%s',
906 'custom_deps': {},
907 'custom_vars': {'webkit': '/trunk/bar_custom/'},
908 }, ]""" % (name, self.url)
909 # Fake DEPS file.
910 deps_content = """vars = {
911 'webkit': '/trunk/bar/',
912 }
913 deps = {
914 'foo/third_party/WebKit': Var('webkit') + 'WebKit',
915 }"""
916
917 webkit_path = 'dummy path webkit'
918
919 entries_content = (
920 "entries = \\\n"
921 "{ 'foo/third_party/WebKit': '%s',\n"
922 " '%s': '%s'}\n"
923 ) % (webkit_path, name, self.url)
924
925 scm_wrapper_webkit = self.mox.CreateMockAnything()
926 scm_wrapper_src = self.mox.CreateMockAnything()
927
928 options = self.Options()
929 gclient.gclient_utils.FileRead(
930 gclient.os.path.join(self.root_dir, name, gclient.GClient.DEPS_FILE)
931 ).AndReturn(deps_content)
932 gclient.gclient_utils.FileWrite(
933 gclient.os.path.join(self.root_dir, options.entries_filename),
934 entries_content)
935
936 gclient.os.path.exists(
937 gclient.os.path.join(self.root_dir, 'foo/third_party/WebKit', '.git')
938 ).AndReturn(False)
939 gclient.os.path.exists(
940 gclient.os.path.join(self.root_dir, name, '.git')
941 ).AndReturn(False)
942 gclient.os.path.exists(
943 gclient.os.path.join(self.root_dir, options.entries_filename)
944 ).AndReturn(False)
945 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
946 gclient.gclient_scm.CreateSCM)
947 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
948
949 gclient.gclient_scm.CreateSCM(self.url, self.root_dir,
950 None).AndReturn(scm_wrapper_src)
951 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar_custom/WebKit'
952 ).AndReturn(webkit_path)
953
954 gclient.gclient_scm.CreateSCM(webkit_path, self.root_dir,
955 'foo/third_party/WebKit').AndReturn(gclient.gclient_scm.CreateSCM)
956 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
957
958 self.mox.ReplayAll()
959 client = self._gclient_gclient(self.root_dir, options)
960 client.SetConfig(gclient_config)
961 client.RunOnDeps('update', self.args)
962
963 def testRunOnDepsFailureVars(self):
964 # Fake .gclient file.
965 name = 'testRunOnDepsFailureVars_solution_name'
966 gclient_config = """solutions = [ {
967 'name': '%s',
968 'url': '%s',
969 'custom_deps': {},
970 'custom_vars': {},
971 }, ]""" % (name, self.url)
972 # Fake DEPS file.
973 deps_content = """deps = {
974 'foo/third_party/WebKit': Var('webkit') + 'WebKit',
975 }"""
976
977 options = self.Options()
978 gclient.gclient_utils.FileRead(
979 gclient.os.path.join(self.root_dir, name, gclient.GClient.DEPS_FILE)
980 ).AndReturn(deps_content)
981 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
982 gclient.gclient_scm.CreateSCM)
983 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
984
985 self.mox.ReplayAll()
986 client = self._gclient_gclient(self.root_dir, options)
987 client.SetConfig(gclient_config)
988 exception = "Var is not defined: webkit"
989 try:
990 client.RunOnDeps('update', self.args)
991 except gclient.gclient_utils.Error, e:
992 self.assertEquals(e.args[0], exception)
993 else:
994 self.fail('%s not raised' % exception)
995
996 def testRunOnDepsFailureInvalidCommand(self):
997 options = self.Options()
998
999 self.mox.ReplayAll()
1000 client = self._gclient_gclient(self.root_dir, options)
1001 exception = "'foo' is an unsupported command"
1002 self.assertRaisesError(exception, self._gclient_gclient.RunOnDeps, client,
1003 'foo', self.args)
1004
1005 def testRunOnDepsFailureEmpty(self):
1006 options = self.Options()
1007
1008 self.mox.ReplayAll()
1009 client = self._gclient_gclient(self.root_dir, options)
1010 exception = "No solution specified"
1011 self.assertRaisesError(exception, self._gclient_gclient.RunOnDeps, client,
1012 'update', self.args)
1013
1014 def testFromImplOne(self):
1015 base_url = 'svn://base@123'
1016 deps_content = (
1017 "deps = {\n"
1018 " 'base': '%s',\n"
1019 " 'main': From('base'),\n"
1020 "}\n" % base_url
1021 )
1022 main_url = 'svn://main@456'
1023 base_deps_content = (
1024 "deps = {\n"
1025 " 'main': '%s',\n"
1026 "}\n" % main_url
1027 )
1028 # Fake .gclient file.
1029 name = 'testFromImplOne_solution_name'
1030 gclient_config = (
1031 "solutions = [ {\n"
1032 "'name': '%s',\n"
1033 "'url': '%s',\n"
1034 "'custom_deps': {},\n"
1035 "}, ]" % (name, self.url))
1036
1037 options = self.Options()
1038 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'main', '.git')
1039 ).AndReturn(False)
1040 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'base', '.git')
1041 ).AndReturn(False)
1042 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git')
1043 ).AndReturn(False)
1044 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
1045 gclient.gclient_scm.CreateSCM)
1046 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1047 gclient.gclient_utils.FileRead(
1048 gclient.os.path.join(self.root_dir, name, gclient.GClient.DEPS_FILE)
1049 ).AndReturn(deps_content)
1050
1051 # base gets updated.
1052 gclient.gclient_scm.CreateSCM(base_url, self.root_dir, 'base').AndReturn(
1053 gclient.gclient_scm.CreateSCM)
1054 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1055 gclient.gclient_utils.FileRead(
1056 gclient.os.path.join(self.root_dir, 'base', gclient.GClient.DEPS_FILE)
1057 ).AndReturn(base_deps_content)
1058
1059 # main gets updated.
1060 gclient.gclient_scm.CreateSCM(main_url, self.root_dir, 'main').AndReturn(
1061 gclient.gclient_scm.CreateSCM)
1062 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1063
1064 # Process is done and will write an .gclient_entries.
1065 gclient.os.path.exists(
1066 gclient.os.path.join(self.root_dir, options.entries_filename)
1067 ).AndReturn(False)
1068 gclient.gclient_utils.FileWrite(
1069 gclient.os.path.join(self.root_dir, options.entries_filename),
1070 mox.IgnoreArg())
1071
1072 self.mox.ReplayAll()
1073 client = self._gclient_gclient(self.root_dir, options)
1074 client.SetConfig(gclient_config)
1075 client.RunOnDeps('update', self.args)
1076
1077 def testFromImplTwo(self):
1078 base_url = 'svn://base@123'
1079 deps_content = (
1080 "deps = {\n"
1081 " 'base': '%s',\n"
1082 " 'main': From('base', 'src/main'),\n"
1083 "}\n" % base_url
1084 )
1085 main_url = 'svn://main@456'
1086 base_deps_content = (
1087 "deps = {\n"
1088 " 'src/main': '%s',\n"
1089 "}\n" % main_url
1090 )
1091 # Fake .gclient file.
1092 name = 'testFromImplTwo_solution_name'
1093 gclient_config = (
1094 "solutions = [ {\n"
1095 "'name': '%s',\n"
1096 "'url': '%s',\n"
1097 "'custom_deps': {},\n"
1098 "}, ]" % (name, self.url))
1099
1100 options = self.Options()
1101 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'main', '.git')
1102 ).AndReturn(False)
1103 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'base', '.git')
1104 ).AndReturn(False)
1105 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git')
1106 ).AndReturn(False)
1107 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
1108 gclient.gclient_scm.CreateSCM)
1109 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1110 gclient.gclient_utils.FileRead(
1111 gclient.os.path.join(self.root_dir, name, gclient.GClient.DEPS_FILE)
1112 ).AndReturn(deps_content)
1113
1114 # base gets updated.
1115 gclient.gclient_scm.CreateSCM(base_url, self.root_dir, 'base').AndReturn(
1116 gclient.gclient_scm.CreateSCM)
1117 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1118 gclient.gclient_utils.FileRead(
1119 gclient.os.path.join(self.root_dir, 'base', gclient.GClient.DEPS_FILE)
1120 ).AndReturn(base_deps_content)
1121
1122 # main gets updated.
1123 gclient.gclient_scm.CreateSCM(main_url, self.root_dir, 'main').AndReturn(
1124 gclient.gclient_scm.CreateSCM)
1125 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1126
1127 # Process is done and will write an .gclient_entries.
1128 gclient.os.path.exists(
1129 gclient.os.path.join(self.root_dir, options.entries_filename)
1130 ).AndReturn(False)
1131 gclient.gclient_utils.FileWrite(
1132 gclient.os.path.join(self.root_dir, options.entries_filename),
1133 mox.IgnoreArg())
1134
1135 self.mox.ReplayAll()
1136 client = self._gclient_gclient(self.root_dir, options)
1137 client.SetConfig(gclient_config)
1138 client.RunOnDeps('update', self.args)
1139
1140 def testFromImplTwoRelatvie(self):
1141 base_url = 'svn://base@123'
1142 deps_content = (
1143 "deps = {\n"
1144 " 'base': '%s',\n"
1145 " 'main': From('base', 'src/main'),\n"
1146 "}\n" % base_url
1147 )
1148 main_url = '/relative@456'
1149 base_deps_content = (
1150 "deps = {\n"
1151 " 'src/main': '%s',\n"
1152 "}\n" % main_url
1153 )
1154 # Fake .gclient file.
1155 name = 'testFromImplTwo_solution_name'
1156 gclient_config = (
1157 "solutions = [ {\n"
1158 "'name': '%s',\n"
1159 "'url': '%s',\n"
1160 "'custom_deps': {},\n"
1161 "}, ]" % (name, self.url))
1162
1163 options = self.Options()
1164 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'main', '.git')
1165 ).AndReturn(False)
1166 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'base', '.git')
1167 ).AndReturn(False)
1168 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git')
1169 ).AndReturn(False)
1170 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
1171 gclient.gclient_scm.CreateSCM)
1172 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1173 gclient.gclient_utils.FileRead(
1174 gclient.os.path.join(self.root_dir, name, gclient.GClient.DEPS_FILE)
1175 ).AndReturn(deps_content)
1176
1177 # base gets updated.
1178 gclient.gclient_scm.CreateSCM(base_url, self.root_dir, 'base').AndReturn(
1179 gclient.gclient_scm.CreateSCM)
1180 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1181 gclient.gclient_utils.FileRead(
1182 gclient.os.path.join(self.root_dir, 'base', gclient.GClient.DEPS_FILE)
1183 ).AndReturn(base_deps_content)
1184
1185 # main gets updated after resolving the relative url.
1186 gclient.gclient_scm.CreateSCM(base_url, self.root_dir, None).AndReturn(
1187 gclient.gclient_scm.CreateSCM)
1188 gclient.gclient_scm.CreateSCM.FullUrlForRelativeUrl(main_url
1189 ).AndReturn('svn://base' + main_url)
1190 gclient.gclient_scm.CreateSCM('svn://base' + main_url, self.root_dir,
1191 'main').AndReturn(gclient.gclient_scm.CreateSCM)
1192 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1193
1194 # Process is done and will write an .gclient_entries.
1195 gclient.os.path.exists(
1196 gclient.os.path.join(self.root_dir, options.entries_filename)
1197 ).AndReturn(False)
1198 gclient.gclient_utils.FileWrite(
1199 gclient.os.path.join(self.root_dir, options.entries_filename),
1200 mox.IgnoreArg())
1201
1202 self.mox.ReplayAll()
1203 client = self._gclient_gclient(self.root_dir, options)
1204 client.SetConfig(gclient_config)
1205 client.RunOnDeps('update', self.args)
1206
1207 def testFileImpl(self):
1208 # Fake .gclient file.
1209 name = "testFileImpl"
1210 gclient_config = (
1211 "solutions = [ { 'name': '%s',"
1212 "'url': '%s', } ]" % (name, self.url)
1213 )
1214 # Fake DEPS file.
1215 target = "chromium_deps"
1216 deps_content = (
1217 "deps = {"
1218 " '%s': File('%s/DEPS') }" % (target, self.url)
1219 )
1220
1221 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
1222 gclient.gclient_scm.CreateSCM)
1223 options = self.Options()
1224 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
1225 gclient.gclient_utils.FileRead(
1226 gclient.os.path.join(self.root_dir, name, gclient.GClient.DEPS_FILE)
1227 ).AndReturn(deps_content)
1228 gclient.os.path.exists(
1229 gclient.os.path.join(self.root_dir, name, '.git')
1230 ).AndReturn(False)
1231 gclient.os.path.exists(
1232 gclient.os.path.join(self.root_dir, options.entries_filename)
1233 ).AndReturn(False)
1234
1235 # This is where gclient tries to do the initial checkout.
1236 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, target).AndReturn(
1237 gclient.gclient_scm.CreateSCM)
1238 gclient.gclient_scm.CreateSCM.RunCommand('updatesingle', options,
1239 self.args + ["DEPS"], [])
1240 gclient.gclient_utils.FileWrite(
1241 gclient.os.path.join(self.root_dir, options.entries_filename),
1242 "entries = \\\n{ '%s': '%s'}\n" % (name, self.url))
1243
1244 self.mox.ReplayAll()
1245 client = self._gclient_gclient(self.root_dir, options)
1246 client.SetConfig(gclient_config)
1247 client.RunOnDeps('update', self.args)
1248
1249 def test_PrintRevInfo(self):
1250 # TODO(aharper): no test yet for revinfo, lock it down once we've verified
1251 # implementation for Pulse plugin
1252 pass
1253
1254 # No test for internal functions.
1255 def test_GetAllDeps(self):
1256 pass
1257 def test_GetDefaultSolutionDeps(self):
1258 pass
1259 def test_LoadConfig(self):
1260 pass
1261 def test_ReadEntries(self):
1262 pass
1263 def test_SaveEntries(self):
1264 pass
1265 def test_VarImpl(self):
1266 pass
1267
1268
1269 if __name__ == '__main__':
1270 import unittest
1271 unittest.main()
1272
1273 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « tests/gclient_smoketest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698