OLD | NEW |
---|---|
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 # |
11 # Unless required by applicable law or agreed to in writing, software | 11 # Unless required by applicable law or agreed to in writing, software |
12 # distributed under the License is distributed on an "AS IS" BASIS, | 12 # distributed under the License is distributed on an "AS IS" BASIS, |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 # See the License for the specific language governing permissions and | 14 # See the License for the specific language governing permissions and |
15 # limitations under the License. | 15 # limitations under the License. |
16 | 16 |
17 """Unit tests for gclient.py.""" | 17 """Unit tests for gclient.py.""" |
18 | 18 |
19 __author__ = 'stephen5.ng@gmail.com (Stephen Ng)' | 19 __author__ = 'stephen5.ng@gmail.com (Stephen Ng)' |
20 | 20 |
21 import __builtin__ | 21 import __builtin__ |
22 import os | |
23 import re | |
24 import StringIO | 22 import StringIO |
25 import unittest | |
26 | 23 |
27 import gclient | 24 import gclient |
28 import gclient_scm | 25 from super_mox import mox, SuperMoxTestBase |
29 import gclient_utils | |
30 import super_mox | |
31 from super_mox import mox | |
32 | 26 |
33 | 27 |
34 class IsOneOf(mox.Comparator): | 28 class IsOneOf(mox.Comparator): |
35 def __init__(self, keys): | 29 def __init__(self, keys): |
36 self._keys = keys | 30 self._keys = keys |
37 | 31 |
38 def equals(self, rhs): | 32 def equals(self, rhs): |
39 return rhs in self._keys | 33 return rhs in self._keys |
40 | 34 |
41 def __repr__(self): | 35 def __repr__(self): |
42 return '<sequence or map containing \'%s\'>' % str(self._keys) | 36 return '<sequence or map containing \'%s\'>' % str(self._keys) |
43 | 37 |
44 | 38 |
45 class BaseTestCase(super_mox.SuperMoxTestBase): | 39 class BaseTestCase(SuperMoxTestBase): |
46 def setUp(self): | 40 def setUp(self): |
47 super_mox.SuperMoxTestBase.setUp(self) | 41 SuperMoxTestBase.setUp(self) |
48 | 42 |
49 # Like unittest's assertRaises, but checks for Gclient.Error. | 43 # Like unittest's assertRaises, but checks for Gclient.Error. |
50 def assertRaisesError(self, msg, fn, *args, **kwargs): | 44 def assertRaisesError(self, msg, fn, *args, **kwargs): |
51 try: | 45 try: |
52 fn(*args, **kwargs) | 46 fn(*args, **kwargs) |
53 except gclient_utils.Error, e: | 47 except gclient.gclient_utils.Error, e: |
54 self.assertEquals(e.args[0], msg) | 48 self.assertEquals(e.args[0], msg) |
55 else: | 49 else: |
56 self.fail('%s not raised' % msg) | 50 self.fail('%s not raised' % msg) |
57 | 51 |
58 | 52 |
59 class GClientBaseTestCase(BaseTestCase): | 53 class GClientBaseTestCase(BaseTestCase): |
60 def Options(self, *args, **kwargs): | 54 def Options(self, *args, **kwargs): |
61 return self.OptionsObject(self, *args, **kwargs) | 55 return self.OptionsObject(self, *args, **kwargs) |
62 | 56 |
63 def setUp(self): | 57 def setUp(self): |
64 BaseTestCase.setUp(self) | 58 BaseTestCase.setUp(self) |
65 self.mox.StubOutWithMock(gclient.os.path, 'exists') | 59 self.mox.StubOutWithMock(gclient.os.path, 'exists') |
66 self.mox.StubOutWithMock(gclient.os.path, 'isfile') | 60 self.mox.StubOutWithMock(gclient.os.path, 'isfile') |
67 self.mox.StubOutWithMock(gclient.os.path, 'isdir') | 61 self.mox.StubOutWithMock(gclient.os.path, 'isdir') |
68 self.mox.StubOutWithMock(gclient.os, 'remove') | 62 self.mox.StubOutWithMock(gclient.os, 'remove') |
69 self.mox.StubOutWithMock(gclient.sys, 'stdout') | 63 self.mox.StubOutWithMock(gclient.sys, 'stdout') |
70 self.mox.StubOutWithMock(gclient_utils, 'subprocess') | 64 self.mox.StubOutWithMock(gclient.gclient_utils, 'subprocess') |
71 # These are not tested. | 65 # These are not tested. |
72 self.mox.StubOutWithMock(gclient_utils, 'FileRead') | 66 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileRead') |
73 self.mox.StubOutWithMock(gclient_utils, 'FileWrite') | 67 self.mox.StubOutWithMock(gclient.gclient_utils, 'FileWrite') |
74 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') | 68 self.mox.StubOutWithMock(gclient.gclient_utils, 'SubprocessCall') |
75 self.mox.StubOutWithMock(gclient_utils, 'RemoveDirectory') | 69 self.mox.StubOutWithMock(gclient.gclient_utils, 'RemoveDirectory') |
76 # Mock them to be sure nothing bad happens. | 70 # Mock them to be sure nothing bad happens. |
77 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVN') | 71 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVN') |
78 self._CaptureSVNInfo = gclient_scm.CaptureSVNInfo | 72 self._CaptureSVNInfo = gclient.gclient_scm.CaptureSVNInfo |
79 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNInfo') | 73 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVNInfo') |
80 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNStatus') | 74 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVNStatus') |
81 self.mox.StubOutWithMock(gclient_scm, 'RunSVN') | 75 self.mox.StubOutWithMock(gclient.gclient_scm, 'RunSVN') |
82 self.mox.StubOutWithMock(gclient_scm, 'RunSVNAndGetFileList') | 76 self.mox.StubOutWithMock(gclient.gclient_scm, 'RunSVNAndGetFileList') |
83 self._gclient_gclient = gclient.GClient | 77 self._gclient_gclient = gclient.GClient |
84 gclient.GClient = self.mox.CreateMockAnything() | 78 gclient.GClient = self.mox.CreateMockAnything() |
85 self._scm_wrapper = gclient_scm.CreateSCM | 79 self._scm_wrapper = gclient.gclient_scm.CreateSCM |
86 gclient_scm.CreateSCM = self.mox.CreateMockAnything() | 80 gclient.gclient_scm.CreateSCM = self.mox.CreateMockAnything() |
87 | 81 |
88 def tearDown(self): | 82 def tearDown(self): |
89 gclient.GClient = self._gclient_gclient | 83 gclient.GClient = self._gclient_gclient |
90 gclient_scm.CreateSCM = self._scm_wrapper | 84 gclient.gclient_scm.CreateSCM = self._scm_wrapper |
91 BaseTestCase.tearDown(self) | 85 BaseTestCase.tearDown(self) |
92 | 86 |
93 | 87 |
94 class GclientTestCase(GClientBaseTestCase): | 88 class GclientTestCase(GClientBaseTestCase): |
95 class OptionsObject(object): | 89 class OptionsObject(object): |
96 def __init__(self, test_case, verbose=False, spec=None, | 90 def __init__(self, test_case, verbose=False, spec=None, |
97 config_filename='a_file_name', | 91 config_filename='a_file_name', |
98 entries_filename='a_entry_file_name', | 92 entries_filename='a_entry_file_name', |
99 deps_file='a_deps_file_name', force=False, nohooks=False): | 93 deps_file='a_deps_file_name', force=False, nohooks=False): |
100 self.verbose = verbose | 94 self.verbose = verbose |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 'RunOnDeps', 'SaveConfig', 'SetConfig', 'SetDefaultConfig', | 340 'RunOnDeps', 'SaveConfig', 'SetConfig', 'SetDefaultConfig', |
347 'supported_commands', 'PrintRevInfo', | 341 'supported_commands', 'PrintRevInfo', |
348 ] | 342 ] |
349 | 343 |
350 # If you add a member, be sure to add the relevant test! | 344 # If you add a member, be sure to add the relevant test! |
351 self.compareMembers(self._gclient_gclient('root_dir', 'options'), members) | 345 self.compareMembers(self._gclient_gclient('root_dir', 'options'), members) |
352 | 346 |
353 def testSetConfig_ConfigContent_GetVar_SaveConfig_SetDefaultConfig(self): | 347 def testSetConfig_ConfigContent_GetVar_SaveConfig_SetDefaultConfig(self): |
354 options = self.Options() | 348 options = self.Options() |
355 text = "# Dummy content\nclient = 'my client'" | 349 text = "# Dummy content\nclient = 'my client'" |
356 gclient_utils.FileWrite( | 350 gclient.gclient_utils.FileWrite( |
357 os.path.join(self.root_dir, options.config_filename), | 351 gclient.os.path.join(self.root_dir, options.config_filename), |
Dirk Pranke
2009/11/10 19:53:38
at some point I need to learn how pxmox works ...
M-A Ruel
2009/11/10 20:07:12
Actually, this is so we don't have multiple entry
| |
358 text) | 352 text) |
359 | 353 |
360 self.mox.ReplayAll() | 354 self.mox.ReplayAll() |
361 client = self._gclient_gclient(self.root_dir, options) | 355 client = self._gclient_gclient(self.root_dir, options) |
362 client.SetConfig(text) | 356 client.SetConfig(text) |
363 self.assertEqual(client.ConfigContent(), text) | 357 self.assertEqual(client.ConfigContent(), text) |
364 self.assertEqual(client.GetVar('client'), 'my client') | 358 self.assertEqual(client.GetVar('client'), 'my client') |
365 self.assertEqual(client.GetVar('foo'), None) | 359 self.assertEqual(client.GetVar('foo'), None) |
366 client.SaveConfig() | 360 client.SaveConfig() |
367 | 361 |
(...skipping 11 matching lines...) Expand all Loading... | |
379 'name': solution_name, | 373 'name': solution_name, |
380 'url': solution_url, | 374 'url': solution_url, |
381 'custom_deps': {}, | 375 'custom_deps': {}, |
382 'safesync_url': safesync_url | 376 'safesync_url': safesync_url |
383 }] | 377 }] |
384 self.assertEqual(client.GetVar('solutions'), solutions) | 378 self.assertEqual(client.GetVar('solutions'), solutions) |
385 self.assertEqual(client.GetVar('foo'), None) | 379 self.assertEqual(client.GetVar('foo'), None) |
386 | 380 |
387 def testLoadCurrentConfig(self): | 381 def testLoadCurrentConfig(self): |
388 options = self.Options() | 382 options = self.Options() |
389 path = os.path.realpath(self.root_dir) | 383 path = gclient.os.path.realpath(self.root_dir) |
390 gclient.os.path.exists(os.path.join(path, options.config_filename) | 384 gclient.os.path.exists(gclient.os.path.join(path, options.config_filename) |
391 ).AndReturn(True) | 385 ).AndReturn(True) |
392 gclient.GClient(path, options).AndReturn(gclient.GClient) | 386 gclient.GClient(path, options).AndReturn(gclient.GClient) |
393 gclient.GClient._LoadConfig() | 387 gclient.GClient._LoadConfig() |
394 | 388 |
395 self.mox.ReplayAll() | 389 self.mox.ReplayAll() |
396 client = self._gclient_gclient.LoadCurrentConfig(options, self.root_dir) | 390 client = self._gclient_gclient.LoadCurrentConfig(options, self.root_dir) |
397 | 391 |
398 def testRunOnDepsNoDeps(self): | 392 def testRunOnDepsNoDeps(self): |
399 solution_name = 'testRunOnDepsNoDeps_solution_name' | 393 solution_name = 'testRunOnDepsNoDeps_solution_name' |
400 gclient_config = ( | 394 gclient_config = ( |
401 "solutions = [ {\n" | 395 "solutions = [ {\n" |
402 " 'name': '%s',\n" | 396 " 'name': '%s',\n" |
403 " 'url': '%s',\n" | 397 " 'url': '%s',\n" |
404 " 'custom_deps': {},\n" | 398 " 'custom_deps': {},\n" |
405 "} ]\n" | 399 "} ]\n" |
406 ) % (solution_name, self.url) | 400 ) % (solution_name, self.url) |
407 | 401 |
408 # pprint.pformat() is non-deterministic in this case!! | 402 # pprint.pformat() is non-deterministic in this case!! |
409 entries_content1 = ( | 403 entries_content1 = ( |
410 "entries = \\\n" | 404 "entries = \\\n" |
411 "{ '%s': '%s'}\n" | 405 "{ '%s': '%s'}\n" |
412 ) % (solution_name, self.url) | 406 ) % (solution_name, self.url) |
413 entries_content2 = ( | 407 entries_content2 = ( |
414 "entries = \\\n" | 408 "entries = \\\n" |
415 "{'%s': '%s'}\n" | 409 "{'%s': '%s'}\n" |
416 ) % (solution_name, self.url) | 410 ) % (solution_name, self.url) |
417 | 411 |
418 options = self.Options() | 412 options = self.Options() |
419 | 413 |
420 checkout_path = os.path.join(self.root_dir, solution_name) | 414 checkout_path = gclient.os.path.join(self.root_dir, solution_name) |
421 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False) | 415 gclient.os.path.exists(gclient.os.path.join(checkout_path, '.git') |
416 ).AndReturn(False) | |
422 # Expect a check for the entries file and we say there is not one. | 417 # Expect a check for the entries file and we say there is not one. |
423 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 418 gclient.os.path.exists( |
419 gclient.os.path.join(self.root_dir, options.entries_filename) | |
424 ).AndReturn(False) | 420 ).AndReturn(False) |
425 | 421 |
426 # An scm will be requested for the solution. | 422 # An scm will be requested for the solution. |
427 scm_wrapper_sol = self.mox.CreateMockAnything() | 423 scm_wrapper_sol = self.mox.CreateMockAnything() |
428 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name | 424 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, solution_name |
429 ).AndReturn(scm_wrapper_sol) | 425 ).AndReturn(scm_wrapper_sol) |
430 # Then an update will be performed. | 426 # Then an update will be performed. |
431 scm_wrapper_sol.RunCommand('update', options, self.args, []) | 427 scm_wrapper_sol.RunCommand('update', options, self.args, []) |
432 # Then an attempt will be made to read its DEPS file. | 428 # Then an attempt will be made to read its DEPS file. |
433 gclient_utils.FileRead(os.path.join(self.root_dir, | 429 gclient.gclient_utils.FileRead( |
434 solution_name, | 430 gclient.os.path.join(self.root_dir, solution_name, options.deps_file) |
435 options.deps_file) | 431 ).AndRaise(IOError(2, 'No DEPS file')) |
436 ).AndRaise(IOError(2, 'No DEPS file')) | |
437 | 432 |
438 # After everything is done, an attempt is made to write an entries | 433 # After everything is done, an attempt is made to write an entries |
439 # file. | 434 # file. |
440 gclient_utils.FileWrite( | 435 gclient.gclient_utils.FileWrite( |
441 os.path.join(self.root_dir, options.entries_filename), | 436 gclient.os.path.join(self.root_dir, options.entries_filename), |
442 IsOneOf((entries_content1, entries_content2))) | 437 IsOneOf((entries_content1, entries_content2))) |
443 | 438 |
444 self.mox.ReplayAll() | 439 self.mox.ReplayAll() |
445 client = self._gclient_gclient(self.root_dir, options) | 440 client = self._gclient_gclient(self.root_dir, options) |
446 client.SetConfig(gclient_config) | 441 client.SetConfig(gclient_config) |
447 client.RunOnDeps('update', self.args) | 442 client.RunOnDeps('update', self.args) |
448 | 443 |
449 def testRunOnDepsRelativePaths(self): | 444 def testRunOnDepsRelativePaths(self): |
450 solution_name = 'testRunOnDepsRelativePaths_solution_name' | 445 solution_name = 'testRunOnDepsRelativePaths_solution_name' |
451 gclient_config = ( | 446 gclient_config = ( |
452 "solutions = [ {\n" | 447 "solutions = [ {\n" |
453 " 'name': '%s',\n" | 448 " 'name': '%s',\n" |
454 " 'url': '%s',\n" | 449 " 'url': '%s',\n" |
455 " 'custom_deps': {},\n" | 450 " 'custom_deps': {},\n" |
456 "} ]\n" | 451 "} ]\n" |
457 ) % (solution_name, self.url) | 452 ) % (solution_name, self.url) |
458 | 453 |
459 deps = ( | 454 deps = ( |
460 "use_relative_paths = True\n" | 455 "use_relative_paths = True\n" |
461 "deps = {\n" | 456 "deps = {\n" |
462 " 'src/t': 'svn://scm.t/trunk',\n" | 457 " 'src/t': 'svn://scm.t/trunk',\n" |
463 "}\n") | 458 "}\n") |
464 entry_path = os.path.join(solution_name, 'src', 't').replace('\\', '\\\\') | 459 entry_path = gclient.os.path.join(solution_name, 'src', 't' |
460 ).replace('\\', '\\\\') | |
465 entries_content = ( | 461 entries_content = ( |
466 "entries = \\\n" | 462 "entries = \\\n" |
467 "{ '%s': '%s',\n" | 463 "{ '%s': '%s',\n" |
468 " '%s': 'svn://scm.t/trunk'}\n" | 464 " '%s': 'svn://scm.t/trunk'}\n" |
469 ) % (solution_name, self.url, entry_path) | 465 ) % (solution_name, self.url, entry_path) |
470 | 466 |
471 scm_wrapper_sol = self.mox.CreateMockAnything() | 467 scm_wrapper_sol = self.mox.CreateMockAnything() |
472 scm_wrapper_t = self.mox.CreateMockAnything() | 468 scm_wrapper_t = self.mox.CreateMockAnything() |
473 | 469 |
474 options = self.Options() | 470 options = self.Options() |
475 | 471 |
476 gclient.os.path.exists(os.path.join(self.root_dir, solution_name, 'src', | 472 gclient.os.path.exists( |
477 't', '.git') | 473 gclient.os.path.join(self.root_dir, solution_name, 'src', 't', '.git') |
478 ).AndReturn(False) | 474 ).AndReturn(False) |
479 gclient.os.path.exists(os.path.join(self.root_dir, solution_name, '.git') | 475 gclient.os.path.exists( |
476 gclient.os.path.join(self.root_dir, solution_name, '.git') | |
480 ).AndReturn(False) | 477 ).AndReturn(False) |
481 # Expect a check for the entries file and we say there is not one. | 478 # Expect a check for the entries file and we say there is not one. |
482 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 479 gclient.os.path.exists( |
480 gclient.os.path.join(self.root_dir, options.entries_filename) | |
483 ).AndReturn(False) | 481 ).AndReturn(False) |
484 | 482 |
485 # An scm will be requested for the solution. | 483 # An scm will be requested for the solution. |
486 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name | 484 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, solution_name |
487 ).AndReturn(scm_wrapper_sol) | 485 ).AndReturn(scm_wrapper_sol) |
488 # Then an update will be performed. | 486 # Then an update will be performed. |
489 scm_wrapper_sol.RunCommand('update', options, self.args, []) | 487 scm_wrapper_sol.RunCommand('update', options, self.args, []) |
490 # Then an attempt will be made to read its DEPS file. | 488 # Then an attempt will be made to read its DEPS file. |
491 gclient_utils.FileRead(os.path.join(self.root_dir, | 489 gclient.gclient_utils.FileRead( |
492 solution_name, | 490 gclient.os.path.join(self.root_dir, solution_name, options.deps_file) |
493 options.deps_file)).AndReturn(deps) | 491 ).AndReturn(deps) |
494 | 492 |
495 # Next we expect an scm to be request for dep src/t but it should | 493 # Next we expect an scm to be request for dep src/t but it should |
496 # use the url specified in deps and the relative path should now | 494 # use the url specified in deps and the relative path should now |
497 # be relative to the DEPS file. | 495 # be relative to the DEPS file. |
498 gclient_scm.CreateSCM( | 496 gclient.gclient_scm.CreateSCM( |
499 'svn://scm.t/trunk', | 497 'svn://scm.t/trunk', |
500 self.root_dir, | 498 self.root_dir, |
501 os.path.join(solution_name, "src", "t")).AndReturn(scm_wrapper_t) | 499 gclient.os.path.join(solution_name, "src", "t") |
500 ).AndReturn(scm_wrapper_t) | |
502 scm_wrapper_t.RunCommand('update', options, self.args, []) | 501 scm_wrapper_t.RunCommand('update', options, self.args, []) |
503 | 502 |
504 # After everything is done, an attempt is made to write an entries | 503 # After everything is done, an attempt is made to write an entries |
505 # file. | 504 # file. |
506 gclient_utils.FileWrite( | 505 gclient.gclient_utils.FileWrite( |
507 os.path.join(self.root_dir, options.entries_filename), | 506 gclient.os.path.join(self.root_dir, options.entries_filename), |
508 entries_content) | 507 entries_content) |
509 | 508 |
510 self.mox.ReplayAll() | 509 self.mox.ReplayAll() |
511 client = self._gclient_gclient(self.root_dir, options) | 510 client = self._gclient_gclient(self.root_dir, options) |
512 client.SetConfig(gclient_config) | 511 client.SetConfig(gclient_config) |
513 client.RunOnDeps('update', self.args) | 512 client.RunOnDeps('update', self.args) |
514 | 513 |
515 def testRunOnDepsCustomDeps(self): | 514 def testRunOnDepsCustomDeps(self): |
516 solution_name = 'testRunOnDepsCustomDeps_solution_name' | 515 solution_name = 'testRunOnDepsCustomDeps_solution_name' |
517 gclient_config = ( | 516 gclient_config = ( |
(...skipping 20 matching lines...) Expand all Loading... | |
538 " 'src/t': 'svn://custom.t/trunk',\n" | 537 " 'src/t': 'svn://custom.t/trunk',\n" |
539 " '%s': '%s'}\n" | 538 " '%s': '%s'}\n" |
540 ) % (solution_name, self.url) | 539 ) % (solution_name, self.url) |
541 | 540 |
542 scm_wrapper_sol = self.mox.CreateMockAnything() | 541 scm_wrapper_sol = self.mox.CreateMockAnything() |
543 scm_wrapper_t = self.mox.CreateMockAnything() | 542 scm_wrapper_t = self.mox.CreateMockAnything() |
544 scm_wrapper_n = self.mox.CreateMockAnything() | 543 scm_wrapper_n = self.mox.CreateMockAnything() |
545 | 544 |
546 options = self.Options() | 545 options = self.Options() |
547 | 546 |
548 checkout_path = os.path.join(self.root_dir, solution_name) | 547 checkout_path = gclient.os.path.join(self.root_dir, solution_name) |
549 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False) | 548 gclient.os.path.exists( |
550 gclient.os.path.exists(os.path.join(self.root_dir, 'src/n', '.git') | 549 gclient.os.path.join(checkout_path, '.git')).AndReturn(False) |
550 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'src/n', '.git') | |
551 ).AndReturn(False) | 551 ).AndReturn(False) |
552 gclient.os.path.exists(os.path.join(self.root_dir, 'src/t', '.git') | 552 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'src/t', '.git') |
553 ).AndReturn(False) | 553 ).AndReturn(False) |
554 | 554 |
555 # Expect a check for the entries file and we say there is not one. | 555 # Expect a check for the entries file and we say there is not one. |
556 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 556 gclient.os.path.exists( |
557 gclient.os.path.join(self.root_dir, options.entries_filename) | |
557 ).AndReturn(False) | 558 ).AndReturn(False) |
558 | 559 |
559 # An scm will be requested for the solution. | 560 # An scm will be requested for the solution. |
560 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name | 561 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, solution_name |
561 ).AndReturn(scm_wrapper_sol) | 562 ).AndReturn(scm_wrapper_sol) |
562 # Then an update will be performed. | 563 # Then an update will be performed. |
563 scm_wrapper_sol.RunCommand('update', options, self.args, []) | 564 scm_wrapper_sol.RunCommand('update', options, self.args, []) |
564 # Then an attempt will be made to read its DEPS file. | 565 # Then an attempt will be made to read its DEPS file. |
565 gclient_utils.FileRead(os.path.join(checkout_path, options.deps_file) | 566 gclient.gclient_utils.FileRead( |
567 gclient.os.path.join(checkout_path, options.deps_file) | |
566 ).AndReturn(deps) | 568 ).AndReturn(deps) |
567 | 569 |
568 # Next we expect an scm to be request for dep src/n even though it does not | 570 # Next we expect an scm to be request for dep src/n even though it does not |
569 # exist in the DEPS file. | 571 # exist in the DEPS file. |
570 gclient_scm.CreateSCM('svn://custom.n/trunk', | 572 gclient.gclient_scm.CreateSCM('svn://custom.n/trunk', |
571 self.root_dir, | 573 self.root_dir, |
572 "src/n").AndReturn(scm_wrapper_n) | 574 "src/n").AndReturn(scm_wrapper_n) |
573 | 575 |
574 # Next we expect an scm to be request for dep src/t but it should | 576 # Next we expect an scm to be request for dep src/t but it should |
575 # use the url specified in custom_deps. | 577 # use the url specified in custom_deps. |
576 gclient_scm.CreateSCM('svn://custom.t/trunk', | 578 gclient.gclient_scm.CreateSCM('svn://custom.t/trunk', |
577 self.root_dir, | 579 self.root_dir, |
578 "src/t").AndReturn(scm_wrapper_t) | 580 "src/t").AndReturn(scm_wrapper_t) |
579 | 581 |
580 scm_wrapper_n.RunCommand('update', options, self.args, []) | 582 scm_wrapper_n.RunCommand('update', options, self.args, []) |
581 scm_wrapper_t.RunCommand('update', options, self.args, []) | 583 scm_wrapper_t.RunCommand('update', options, self.args, []) |
582 | 584 |
583 # NOTE: the dep src/b should not create an scm at all. | 585 # NOTE: the dep src/b should not create an scm at all. |
584 | 586 |
585 # After everything is done, an attempt is made to write an entries | 587 # After everything is done, an attempt is made to write an entries |
586 # file. | 588 # file. |
587 gclient_utils.FileWrite( | 589 gclient.gclient_utils.FileWrite( |
588 os.path.join(self.root_dir, options.entries_filename), | 590 gclient.os.path.join(self.root_dir, options.entries_filename), |
589 entries_content) | 591 entries_content) |
590 | 592 |
591 self.mox.ReplayAll() | 593 self.mox.ReplayAll() |
592 client = self._gclient_gclient(self.root_dir, options) | 594 client = self._gclient_gclient(self.root_dir, options) |
593 client.SetConfig(gclient_config) | 595 client.SetConfig(gclient_config) |
594 client.RunOnDeps('update', self.args) | 596 client.RunOnDeps('update', self.args) |
595 | 597 |
596 # Regression test for Issue #11. | 598 # Regression test for Issue #11. |
597 # http://code.google.com/p/gclient/issues/detail?id=11 | 599 # http://code.google.com/p/gclient/issues/detail?id=11 |
598 def testRunOnDepsSharedDependency(self): | 600 def testRunOnDepsSharedDependency(self): |
(...skipping 27 matching lines...) Expand all Loading... | |
626 " '%s': '%s',\n" | 628 " '%s': '%s',\n" |
627 " '%s': '%s'}\n" | 629 " '%s': '%s'}\n" |
628 ) % (name_a, url_a, name_b, url_b) | 630 ) % (name_a, url_a, name_b, url_b) |
629 | 631 |
630 scm_wrapper_a = self.mox.CreateMockAnything() | 632 scm_wrapper_a = self.mox.CreateMockAnything() |
631 scm_wrapper_b = self.mox.CreateMockAnything() | 633 scm_wrapper_b = self.mox.CreateMockAnything() |
632 scm_wrapper_dep = self.mox.CreateMockAnything() | 634 scm_wrapper_dep = self.mox.CreateMockAnything() |
633 | 635 |
634 options = self.Options() | 636 options = self.Options() |
635 | 637 |
636 gclient.os.path.exists(os.path.join(self.root_dir, name_a, '.git') | 638 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name_a, '.git') |
637 ).AndReturn(False) | 639 ).AndReturn(False) |
638 gclient.os.path.exists(os.path.join(self.root_dir, name_b, '.git') | 640 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name_b, '.git') |
639 ).AndReturn(False) | 641 ).AndReturn(False) |
640 gclient.os.path.exists(os.path.join(self.root_dir, 'src/t', '.git') | 642 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'src/t', '.git') |
641 ).AndReturn(False) | 643 ).AndReturn(False) |
642 | 644 |
643 # Expect a check for the entries file and we say there is not one. | 645 # Expect a check for the entries file and we say there is not one. |
644 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 646 gclient.os.path.exists( |
647 gclient.os.path.join(self.root_dir, options.entries_filename) | |
645 ).AndReturn(False) | 648 ).AndReturn(False) |
646 | 649 |
647 # An scm will be requested for the first solution. | 650 # An scm will be requested for the first solution. |
648 gclient_scm.CreateSCM(url_a, self.root_dir, name_a).AndReturn( | 651 gclient.gclient_scm.CreateSCM(url_a, self.root_dir, name_a).AndReturn( |
649 scm_wrapper_a) | 652 scm_wrapper_a) |
650 # Then an attempt will be made to read it's DEPS file. | 653 # Then an attempt will be made to read it's DEPS file. |
651 gclient_utils.FileRead( | 654 gclient.gclient_utils.FileRead( |
652 os.path.join(self.root_dir, name_a, options.deps_file) | 655 gclient.os.path.join(self.root_dir, name_a, options.deps_file) |
653 ).AndReturn(deps_a) | 656 ).AndReturn(deps_a) |
654 # Then an update will be performed. | 657 # Then an update will be performed. |
655 scm_wrapper_a.RunCommand('update', options, self.args, []) | 658 scm_wrapper_a.RunCommand('update', options, self.args, []) |
656 | 659 |
657 # An scm will be requested for the second solution. | 660 # An scm will be requested for the second solution. |
658 gclient_scm.CreateSCM(url_b, self.root_dir, name_b).AndReturn( | 661 gclient.gclient_scm.CreateSCM(url_b, self.root_dir, name_b).AndReturn( |
659 scm_wrapper_b) | 662 scm_wrapper_b) |
660 # Then an attempt will be made to read its DEPS file. | 663 # Then an attempt will be made to read its DEPS file. |
661 gclient_utils.FileRead( | 664 gclient.gclient_utils.FileRead( |
662 os.path.join(self.root_dir, name_b, options.deps_file) | 665 gclient.os.path.join(self.root_dir, name_b, options.deps_file) |
663 ).AndReturn(deps_b) | 666 ).AndReturn(deps_b) |
664 # Then an update will be performed. | 667 # Then an update will be performed. |
665 scm_wrapper_b.RunCommand('update', options, self.args, []) | 668 scm_wrapper_b.RunCommand('update', options, self.args, []) |
666 | 669 |
667 # Finally, an scm is requested for the shared dep. | 670 # Finally, an scm is requested for the shared dep. |
668 gclient_scm.CreateSCM('http://svn.t/trunk', self.root_dir, 'src/t' | 671 gclient.gclient_scm.CreateSCM('http://svn.t/trunk', self.root_dir, 'src/t' |
669 ).AndReturn(scm_wrapper_dep) | 672 ).AndReturn(scm_wrapper_dep) |
670 # And an update is run on it. | 673 # And an update is run on it. |
671 scm_wrapper_dep.RunCommand('update', options, self.args, []) | 674 scm_wrapper_dep.RunCommand('update', options, self.args, []) |
672 | 675 |
673 # After everything is done, an attempt is made to write an entries file. | 676 # After everything is done, an attempt is made to write an entries file. |
674 gclient_utils.FileWrite( | 677 gclient.gclient_utils.FileWrite( |
675 os.path.join(self.root_dir, options.entries_filename), | 678 gclient.os.path.join(self.root_dir, options.entries_filename), |
676 entries_content) | 679 entries_content) |
677 | 680 |
678 self.mox.ReplayAll() | 681 self.mox.ReplayAll() |
679 client = self._gclient_gclient(self.root_dir, options) | 682 client = self._gclient_gclient(self.root_dir, options) |
680 client.SetConfig(gclient_config) | 683 client.SetConfig(gclient_config) |
681 client.RunOnDeps('update', self.args) | 684 client.RunOnDeps('update', self.args) |
682 | 685 |
683 def testRunOnDepsSuccess(self): | 686 def testRunOnDepsSuccess(self): |
684 # Fake .gclient file. | 687 # Fake .gclient file. |
685 name = 'testRunOnDepsSuccess_solution_name' | 688 name = 'testRunOnDepsSuccess_solution_name' |
686 gclient_config = """solutions = [ { | 689 gclient_config = """solutions = [ { |
687 'name': '%s', | 690 'name': '%s', |
688 'url': '%s', | 691 'url': '%s', |
689 'custom_deps': {}, | 692 'custom_deps': {}, |
690 }, ]""" % (name, self.url) | 693 }, ]""" % (name, self.url) |
691 | 694 |
692 entries_content = ( | 695 # pprint.pformat() is non-deterministic in this case!! |
Dirk Pranke
2009/11/10 19:53:38
odd. is that a python bug?
M-A Ruel
2009/11/10 20:07:12
Yes.
| |
696 entries_content1 = ( | |
693 "entries = \\\n" | 697 "entries = \\\n" |
694 "{ '%s': '%s'}\n" | 698 "{ '%s': '%s'}\n" |
695 ) % (name, self.url) | 699 ) % (name, self.url) |
700 entries_content2 = ( | |
701 "entries = \\\n" | |
702 "{'%s': '%s'}\n" | |
703 ) % (name, self.url) | |
704 | |
696 | 705 |
697 options = self.Options() | 706 options = self.Options() |
698 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') | 707 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git') |
699 ).AndReturn(False) | 708 ).AndReturn(False) |
700 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 709 gclient.os.path.exists( |
710 gclient.os.path.join(self.root_dir, options.entries_filename) | |
701 ).AndReturn(False) | 711 ).AndReturn(False) |
702 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | 712 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( |
703 gclient_scm.CreateSCM) | 713 gclient.gclient_scm.CreateSCM) |
704 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 714 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) |
705 gclient_utils.FileRead(os.path.join(self.root_dir, name, options.deps_file) | 715 gclient.gclient_utils.FileRead( |
716 gclient.os.path.join(self.root_dir, name, options.deps_file) | |
706 ).AndReturn("Boo = 'a'") | 717 ).AndReturn("Boo = 'a'") |
707 gclient_utils.FileWrite( | 718 gclient.gclient_utils.FileWrite( |
708 os.path.join(self.root_dir, options.entries_filename), | 719 gclient.os.path.join(self.root_dir, options.entries_filename), |
709 entries_content) | 720 IsOneOf((entries_content1, entries_content2))) |
710 | 721 |
711 self.mox.ReplayAll() | 722 self.mox.ReplayAll() |
712 client = self._gclient_gclient(self.root_dir, options) | 723 client = self._gclient_gclient(self.root_dir, options) |
713 client.SetConfig(gclient_config) | 724 client.SetConfig(gclient_config) |
714 client.RunOnDeps('update', self.args) | 725 client.RunOnDeps('update', self.args) |
715 | 726 |
716 def testRunOnDepsRevisions(self): | 727 def testRunOnDepsRevisions(self): |
717 def OptIsRev(options, rev): | 728 def OptIsRev(options, rev): |
718 if not options.revision == str(rev): | 729 if not options.revision == str(rev): |
719 print("options.revision = %s" % options.revision) | 730 print("options.revision = %s" % options.revision) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 scm_wrapper_webkit = self.mox.CreateMockAnything() | 781 scm_wrapper_webkit = self.mox.CreateMockAnything() |
771 scm_wrapper_breakpad = self.mox.CreateMockAnything() | 782 scm_wrapper_breakpad = self.mox.CreateMockAnything() |
772 scm_wrapper_cygwin = self.mox.CreateMockAnything() | 783 scm_wrapper_cygwin = self.mox.CreateMockAnything() |
773 scm_wrapper_python = self.mox.CreateMockAnything() | 784 scm_wrapper_python = self.mox.CreateMockAnything() |
774 options = self.Options() | 785 options = self.Options() |
775 options.revisions = [ 'src@123', 'foo/third_party/WebKit@42', | 786 options.revisions = [ 'src@123', 'foo/third_party/WebKit@42', |
776 'src/third_party/cygwin@333' ] | 787 'src/third_party/cygwin@333' ] |
777 | 788 |
778 # Also, pymox doesn't verify the order of function calling w.r.t. different | 789 # Also, pymox doesn't verify the order of function calling w.r.t. different |
779 # mock objects. Pretty lame. So reorder as we wish to make it clearer. | 790 # mock objects. Pretty lame. So reorder as we wish to make it clearer. |
780 gclient_utils.FileRead( | 791 gclient.gclient_utils.FileRead( |
781 os.path.join(self.root_dir, 'src', options.deps_file) | 792 gclient.os.path.join(self.root_dir, 'src', options.deps_file) |
782 ).AndReturn(deps_content) | 793 ).AndReturn(deps_content) |
783 gclient_utils.FileWrite( | 794 gclient.gclient_utils.FileWrite( |
784 os.path.join(self.root_dir, options.entries_filename), | 795 gclient.os.path.join(self.root_dir, options.entries_filename), |
785 entries_content) | 796 entries_content) |
786 | 797 |
787 gclient.os.path.exists(os.path.join(self.root_dir, 'src', '.git') | 798 gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'src', '.git') |
788 ).AndReturn(False) | 799 ).AndReturn(False) |
789 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', | 800 gclient.os.path.exists( |
790 '.git') | 801 gclient.os.path.join(self.root_dir, 'foo/third_party/WebKit', '.git') |
791 ).AndReturn(False) | 802 ).AndReturn(False) |
792 gclient.os.path.exists(os.path.join(self.root_dir, 'src/third_party/cygwin', | 803 gclient.os.path.exists( |
793 '.git') | 804 gclient.os.path.join(self.root_dir, 'src/third_party/cygwin', '.git') |
794 ).AndReturn(False) | 805 ).AndReturn(False) |
795 gclient.os.path.exists(os.path.join(self.root_dir, | 806 gclient.os.path.exists( |
796 'src/third_party/python_24', '.git') | 807 gclient.os.path.join(self.root_dir, 'src/third_party/python_24', '.git') |
797 ).AndReturn(False) | 808 ).AndReturn(False) |
798 gclient.os.path.exists(os.path.join(self.root_dir, 'src/breakpad/bar', | 809 gclient.os.path.exists( |
799 '.git') | 810 gclient.os.path.join(self.root_dir, 'src/breakpad/bar', '.git') |
800 ).AndReturn(False) | 811 ).AndReturn(False) |
801 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 812 gclient.os.path.exists( |
813 gclient.os.path.join(self.root_dir, options.entries_filename) | |
802 ).AndReturn(False) | 814 ).AndReturn(False) |
803 | 815 |
804 gclient_scm.CreateSCM(self.url, self.root_dir, 'src').AndReturn( | 816 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, 'src').AndReturn( |
805 scm_wrapper_src) | 817 scm_wrapper_src) |
806 scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, []) | 818 scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, []) |
807 | 819 |
808 gclient_scm.CreateSCM(self.url, self.root_dir, | 820 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, |
809 None).AndReturn(scm_wrapper_src2) | 821 None).AndReturn(scm_wrapper_src2) |
810 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/cygwin@3248' | 822 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/cygwin@3248' |
811 ).AndReturn(cygwin_path) | 823 ).AndReturn(cygwin_path) |
812 | 824 |
813 gclient_scm.CreateSCM(self.url, self.root_dir, | 825 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, |
814 None).AndReturn(scm_wrapper_src2) | 826 None).AndReturn(scm_wrapper_src2) |
815 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/WebKit' | 827 scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/WebKit' |
816 ).AndReturn(webkit_path) | 828 ).AndReturn(webkit_path) |
817 | 829 |
818 gclient_scm.CreateSCM(webkit_path, self.root_dir, | 830 gclient.gclient_scm.CreateSCM( |
819 'foo/third_party/WebKit').AndReturn(scm_wrapper_webkit) | 831 webkit_path, self.root_dir, 'foo/third_party/WebKit' |
832 ).AndReturn(scm_wrapper_webkit) | |
820 scm_wrapper_webkit.RunCommand('update', mox.Func(OptIsRev42), self.args, []) | 833 scm_wrapper_webkit.RunCommand('update', mox.Func(OptIsRev42), self.args, []) |
821 | 834 |
822 gclient_scm.CreateSCM( | 835 gclient.gclient_scm.CreateSCM( |
823 'http://google-breakpad.googlecode.com/svn/trunk/src@285', | 836 'http://google-breakpad.googlecode.com/svn/trunk/src@285', |
824 self.root_dir, 'src/breakpad/bar').AndReturn(scm_wrapper_breakpad) | 837 self.root_dir, 'src/breakpad/bar').AndReturn(scm_wrapper_breakpad) |
825 scm_wrapper_breakpad.RunCommand('update', mox.Func(OptIsRevNone), | 838 scm_wrapper_breakpad.RunCommand('update', mox.Func(OptIsRevNone), |
826 self.args, []) | 839 self.args, []) |
827 | 840 |
828 gclient_scm.CreateSCM(cygwin_path, self.root_dir, | 841 gclient.gclient_scm.CreateSCM( |
829 'src/third_party/cygwin').AndReturn(scm_wrapper_cygwin) | 842 cygwin_path, self.root_dir, 'src/third_party/cygwin' |
843 ).AndReturn(scm_wrapper_cygwin) | |
830 scm_wrapper_cygwin.RunCommand('update', mox.Func(OptIsRev333), self.args, | 844 scm_wrapper_cygwin.RunCommand('update', mox.Func(OptIsRev333), self.args, |
831 []) | 845 []) |
832 | 846 |
833 gclient_scm.CreateSCM('svn://random_server:123/trunk/python_24@5580', | 847 gclient.gclient_scm.CreateSCM( |
834 self.root_dir, | 848 'svn://random_server:123/trunk/python_24@5580', |
835 'src/third_party/python_24').AndReturn( | 849 self.root_dir, |
836 scm_wrapper_python) | 850 'src/third_party/python_24' |
851 ).AndReturn(scm_wrapper_python) | |
837 scm_wrapper_python.RunCommand('update', mox.Func(OptIsRevNone), self.args, | 852 scm_wrapper_python.RunCommand('update', mox.Func(OptIsRevNone), self.args, |
838 []) | 853 []) |
839 | 854 |
840 self.mox.ReplayAll() | 855 self.mox.ReplayAll() |
841 client = self._gclient_gclient(self.root_dir, options) | 856 client = self._gclient_gclient(self.root_dir, options) |
842 client.SetConfig(gclient_config) | 857 client.SetConfig(gclient_config) |
843 client.RunOnDeps('update', self.args) | 858 client.RunOnDeps('update', self.args) |
844 | 859 |
845 def testRunOnDepsConflictingRevisions(self): | 860 def testRunOnDepsConflictingRevisions(self): |
846 # Fake .gclient file. | 861 # Fake .gclient file. |
(...skipping 10 matching lines...) Expand all Loading... | |
857 }""" | 872 }""" |
858 | 873 |
859 options = self.Options() | 874 options = self.Options() |
860 options.revisions = [ 'foo/third_party/WebKit@42', | 875 options.revisions = [ 'foo/third_party/WebKit@42', |
861 'foo/third_party/WebKit@43' ] | 876 'foo/third_party/WebKit@43' ] |
862 client = self._gclient_gclient(self.root_dir, options) | 877 client = self._gclient_gclient(self.root_dir, options) |
863 client.SetConfig(gclient_config) | 878 client.SetConfig(gclient_config) |
864 exception = "Conflicting revision numbers specified." | 879 exception = "Conflicting revision numbers specified." |
865 try: | 880 try: |
866 client.RunOnDeps('update', self.args) | 881 client.RunOnDeps('update', self.args) |
867 except gclient_utils.Error, e: | 882 except gclient.gclient_utils.Error, e: |
868 self.assertEquals(e.args[0], exception) | 883 self.assertEquals(e.args[0], exception) |
869 else: | 884 else: |
870 self.fail('%s not raised' % exception) | 885 self.fail('%s not raised' % exception) |
871 | 886 |
872 def testRunOnDepsSuccessVars(self): | 887 def testRunOnDepsSuccessVars(self): |
873 # Fake .gclient file. | 888 # Fake .gclient file. |
874 name = 'testRunOnDepsSuccessVars_solution_name' | 889 name = 'testRunOnDepsSuccessVars_solution_name' |
875 gclient_config = """solutions = [ { | 890 gclient_config = """solutions = [ { |
876 'name': '%s', | 891 'name': '%s', |
877 'url': '%s', | 892 'url': '%s', |
(...skipping 13 matching lines...) Expand all Loading... | |
891 entries_content = ( | 906 entries_content = ( |
892 "entries = \\\n" | 907 "entries = \\\n" |
893 "{ 'foo/third_party/WebKit': '%s',\n" | 908 "{ 'foo/third_party/WebKit': '%s',\n" |
894 " '%s': '%s'}\n" | 909 " '%s': '%s'}\n" |
895 ) % (webkit_path, name, self.url) | 910 ) % (webkit_path, name, self.url) |
896 | 911 |
897 scm_wrapper_webkit = self.mox.CreateMockAnything() | 912 scm_wrapper_webkit = self.mox.CreateMockAnything() |
898 scm_wrapper_src = self.mox.CreateMockAnything() | 913 scm_wrapper_src = self.mox.CreateMockAnything() |
899 | 914 |
900 options = self.Options() | 915 options = self.Options() |
901 gclient_utils.FileRead( | 916 gclient.gclient_utils.FileRead( |
902 os.path.join(self.root_dir, name, options.deps_file) | 917 gclient.os.path.join(self.root_dir, name, options.deps_file) |
903 ).AndReturn(deps_content) | 918 ).AndReturn(deps_content) |
904 gclient_utils.FileWrite( | 919 gclient.gclient_utils.FileWrite( |
905 os.path.join(self.root_dir, options.entries_filename), | 920 gclient.os.path.join(self.root_dir, options.entries_filename), |
906 entries_content) | 921 entries_content) |
907 | 922 |
908 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', | 923 gclient.os.path.exists( |
909 '.git')).AndReturn(False) | 924 gclient.os.path.join(self.root_dir, 'foo/third_party/WebKit', '.git') |
910 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') | |
911 ).AndReturn(False) | 925 ).AndReturn(False) |
912 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 926 gclient.os.path.exists( |
927 gclient.os.path.join(self.root_dir, name, '.git') | |
913 ).AndReturn(False) | 928 ).AndReturn(False) |
914 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | 929 gclient.os.path.exists( |
915 gclient_scm.CreateSCM) | 930 gclient.os.path.join(self.root_dir, options.entries_filename) |
916 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 931 ).AndReturn(False) |
932 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | |
933 gclient.gclient_scm.CreateSCM) | |
934 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | |
917 | 935 |
918 gclient_scm.CreateSCM(self.url, self.root_dir, | 936 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, None |
919 None).AndReturn(scm_wrapper_src) | 937 ).AndReturn(scm_wrapper_src) |
920 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar/WebKit' | 938 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar/WebKit' |
921 ).AndReturn(webkit_path) | 939 ).AndReturn(webkit_path) |
922 | 940 |
923 gclient_scm.CreateSCM(webkit_path, self.root_dir, | 941 gclient.gclient_scm.CreateSCM( |
924 'foo/third_party/WebKit').AndReturn(gclient_scm.CreateSCM) | 942 webkit_path, self.root_dir, 'foo/third_party/WebKit' |
925 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 943 ).AndReturn(gclient.gclient_scm.CreateSCM) |
944 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | |
926 | 945 |
927 self.mox.ReplayAll() | 946 self.mox.ReplayAll() |
928 client = self._gclient_gclient(self.root_dir, options) | 947 client = self._gclient_gclient(self.root_dir, options) |
929 client.SetConfig(gclient_config) | 948 client.SetConfig(gclient_config) |
930 client.RunOnDeps('update', self.args) | 949 client.RunOnDeps('update', self.args) |
931 | 950 |
932 def testRunOnDepsSuccessCustomVars(self): | 951 def testRunOnDepsSuccessCustomVars(self): |
933 # Fake .gclient file. | 952 # Fake .gclient file. |
934 name = 'testRunOnDepsSuccessCustomVars_solution_name' | 953 name = 'testRunOnDepsSuccessCustomVars_solution_name' |
935 gclient_config = """solutions = [ { | 954 gclient_config = """solutions = [ { |
(...skipping 15 matching lines...) Expand all Loading... | |
951 entries_content = ( | 970 entries_content = ( |
952 "entries = \\\n" | 971 "entries = \\\n" |
953 "{ 'foo/third_party/WebKit': '%s',\n" | 972 "{ 'foo/third_party/WebKit': '%s',\n" |
954 " '%s': '%s'}\n" | 973 " '%s': '%s'}\n" |
955 ) % (webkit_path, name, self.url) | 974 ) % (webkit_path, name, self.url) |
956 | 975 |
957 scm_wrapper_webkit = self.mox.CreateMockAnything() | 976 scm_wrapper_webkit = self.mox.CreateMockAnything() |
958 scm_wrapper_src = self.mox.CreateMockAnything() | 977 scm_wrapper_src = self.mox.CreateMockAnything() |
959 | 978 |
960 options = self.Options() | 979 options = self.Options() |
961 gclient_utils.FileRead( | 980 gclient.gclient_utils.FileRead( |
962 os.path.join(self.root_dir, name, options.deps_file) | 981 gclient.os.path.join(self.root_dir, name, options.deps_file) |
963 ).AndReturn(deps_content) | 982 ).AndReturn(deps_content) |
964 gclient_utils.FileWrite( | 983 gclient.gclient_utils.FileWrite( |
965 os.path.join(self.root_dir, options.entries_filename), | 984 gclient.os.path.join(self.root_dir, options.entries_filename), |
966 entries_content) | 985 entries_content) |
967 | 986 |
968 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', | 987 gclient.os.path.exists( |
969 '.git') | 988 gclient.os.path.join(self.root_dir, 'foo/third_party/WebKit', '.git') |
970 ).AndReturn(False) | 989 ).AndReturn(False) |
971 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') | 990 gclient.os.path.exists( |
991 gclient.os.path.join(self.root_dir, name, '.git') | |
972 ).AndReturn(False) | 992 ).AndReturn(False) |
973 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 993 gclient.os.path.exists( |
994 gclient.os.path.join(self.root_dir, options.entries_filename) | |
974 ).AndReturn(False) | 995 ).AndReturn(False) |
975 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | 996 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( |
976 gclient_scm.CreateSCM) | 997 gclient.gclient_scm.CreateSCM) |
977 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 998 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) |
978 | 999 |
979 gclient_scm.CreateSCM(self.url, self.root_dir, | 1000 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, |
980 None).AndReturn(scm_wrapper_src) | 1001 None).AndReturn(scm_wrapper_src) |
981 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar_custom/WebKit' | 1002 scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar_custom/WebKit' |
982 ).AndReturn(webkit_path) | 1003 ).AndReturn(webkit_path) |
983 | 1004 |
984 gclient_scm.CreateSCM(webkit_path, self.root_dir, | 1005 gclient.gclient_scm.CreateSCM(webkit_path, self.root_dir, |
985 'foo/third_party/WebKit').AndReturn(gclient_scm.CreateSCM) | 1006 'foo/third_party/WebKit').AndReturn(gclient.gclient_scm.CreateSCM) |
986 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 1007 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) |
987 | 1008 |
988 self.mox.ReplayAll() | 1009 self.mox.ReplayAll() |
989 client = self._gclient_gclient(self.root_dir, options) | 1010 client = self._gclient_gclient(self.root_dir, options) |
990 client.SetConfig(gclient_config) | 1011 client.SetConfig(gclient_config) |
991 client.RunOnDeps('update', self.args) | 1012 client.RunOnDeps('update', self.args) |
992 | 1013 |
993 def testRunOnDepsFailureVars(self): | 1014 def testRunOnDepsFailureVars(self): |
994 # Fake .gclient file. | 1015 # Fake .gclient file. |
995 name = 'testRunOnDepsFailureVars_solution_name' | 1016 name = 'testRunOnDepsFailureVars_solution_name' |
996 gclient_config = """solutions = [ { | 1017 gclient_config = """solutions = [ { |
997 'name': '%s', | 1018 'name': '%s', |
998 'url': '%s', | 1019 'url': '%s', |
999 'custom_deps': {}, | 1020 'custom_deps': {}, |
1000 'custom_vars': {}, | 1021 'custom_vars': {}, |
1001 }, ]""" % (name, self.url) | 1022 }, ]""" % (name, self.url) |
1002 # Fake DEPS file. | 1023 # Fake DEPS file. |
1003 deps_content = """deps = { | 1024 deps_content = """deps = { |
1004 'foo/third_party/WebKit': Var('webkit') + 'WebKit', | 1025 'foo/third_party/WebKit': Var('webkit') + 'WebKit', |
1005 }""" | 1026 }""" |
1006 | 1027 |
1007 options = self.Options() | 1028 options = self.Options() |
1008 gclient_utils.FileRead( | 1029 gclient.gclient_utils.FileRead( |
1009 os.path.join(self.root_dir, name, options.deps_file) | 1030 gclient.os.path.join(self.root_dir, name, options.deps_file) |
1010 ).AndReturn(deps_content) | 1031 ).AndReturn(deps_content) |
1011 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | 1032 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( |
1012 gclient_scm.CreateSCM) | 1033 gclient.gclient_scm.CreateSCM) |
1013 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 1034 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) |
1014 | 1035 |
1015 self.mox.ReplayAll() | 1036 self.mox.ReplayAll() |
1016 client = self._gclient_gclient(self.root_dir, options) | 1037 client = self._gclient_gclient(self.root_dir, options) |
1017 client.SetConfig(gclient_config) | 1038 client.SetConfig(gclient_config) |
1018 exception = "Var is not defined: webkit" | 1039 exception = "Var is not defined: webkit" |
1019 try: | 1040 try: |
1020 client.RunOnDeps('update', self.args) | 1041 client.RunOnDeps('update', self.args) |
1021 except gclient_utils.Error, e: | 1042 except gclient.gclient_utils.Error, e: |
1022 self.assertEquals(e.args[0], exception) | 1043 self.assertEquals(e.args[0], exception) |
1023 else: | 1044 else: |
1024 self.fail('%s not raised' % exception) | 1045 self.fail('%s not raised' % exception) |
1025 | 1046 |
1026 def testRunOnDepsFailureInvalidCommand(self): | 1047 def testRunOnDepsFailureInvalidCommand(self): |
1027 options = self.Options() | 1048 options = self.Options() |
1028 | 1049 |
1029 self.mox.ReplayAll() | 1050 self.mox.ReplayAll() |
1030 client = self._gclient_gclient(self.root_dir, options) | 1051 client = self._gclient_gclient(self.root_dir, options) |
1031 exception = "'foo' is an unsupported command" | 1052 exception = "'foo' is an unsupported command" |
(...skipping 29 matching lines...) Expand all Loading... | |
1061 pass | 1082 pass |
1062 def test_SaveEntries(self): | 1083 def test_SaveEntries(self): |
1063 pass | 1084 pass |
1064 def test_VarImpl(self): | 1085 def test_VarImpl(self): |
1065 pass | 1086 pass |
1066 | 1087 |
1067 | 1088 |
1068 class SubprocessCallAndFilterTestCase(BaseTestCase): | 1089 class SubprocessCallAndFilterTestCase(BaseTestCase): |
1069 def setUp(self): | 1090 def setUp(self): |
1070 BaseTestCase.setUp(self) | 1091 BaseTestCase.setUp(self) |
1071 self.mox.StubOutWithMock(gclient_utils, 'subprocess') | 1092 self.mox.StubOutWithMock(gclient.gclient_utils, 'subprocess') |
1072 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVN') | 1093 self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVN') |
1073 | 1094 |
1074 def testSubprocessCallAndFilter(self): | 1095 def testSubprocessCallAndFilter(self): |
1075 command = ['boo', 'foo', 'bar'] | 1096 command = ['boo', 'foo', 'bar'] |
1076 in_directory = 'bleh' | 1097 in_directory = 'bleh' |
1077 fail_status = None | 1098 fail_status = None |
1078 pattern = 'a(.*)b' | 1099 pattern = 'a(.*)b' |
1079 test_string = 'ahah\naccb\nallo\naddb\n' | 1100 test_string = 'ahah\naccb\nallo\naddb\n' |
1080 class Mock(object): | 1101 class Mock(object): |
1081 stdout = StringIO.StringIO(test_string) | 1102 stdout = StringIO.StringIO(test_string) |
1082 def wait(self): | 1103 def wait(self): |
1083 pass | 1104 pass |
1084 kid = Mock() | 1105 kid = Mock() |
1085 print("\n________ running 'boo foo bar' in 'bleh'") | 1106 print("\n________ running 'boo foo bar' in 'bleh'") |
1086 for i in test_string: | 1107 for i in test_string: |
1087 gclient.sys.stdout.write(i) | 1108 gclient.sys.stdout.write(i) |
1088 gclient_utils.subprocess.Popen(command, bufsize=0, cwd=in_directory, | 1109 gclient.gclient_utils.subprocess.Popen( |
1089 shell=(gclient.sys.platform == 'win32'), | 1110 command, bufsize=0, cwd=in_directory, |
1090 stdout=gclient_utils.subprocess.PIPE, | 1111 shell=(gclient.sys.platform == 'win32'), |
1091 stderr=gclient_utils.subprocess.STDOUT).AndReturn(kid) | 1112 stdout=gclient.gclient_utils.subprocess.PIPE, |
1113 stderr=gclient.gclient_utils.subprocess.STDOUT).AndReturn(kid) | |
1092 self.mox.ReplayAll() | 1114 self.mox.ReplayAll() |
1093 compiled_pattern = re.compile(pattern) | 1115 compiled_pattern = gclient.re.compile(pattern) |
1094 line_list = [] | 1116 line_list = [] |
1095 capture_list = [] | 1117 capture_list = [] |
1096 def FilterLines(line): | 1118 def FilterLines(line): |
1097 line_list.append(line) | 1119 line_list.append(line) |
1098 match = compiled_pattern.search(line) | 1120 match = compiled_pattern.search(line) |
1099 if match: | 1121 if match: |
1100 capture_list.append(match.group(1)) | 1122 capture_list.append(match.group(1)) |
1101 gclient_utils.SubprocessCallAndFilter(command, in_directory, | 1123 gclient.gclient_utils.SubprocessCallAndFilter( |
1102 True, True, | 1124 command, in_directory, |
1103 fail_status, FilterLines) | 1125 True, True, |
1126 fail_status, FilterLines) | |
1104 self.assertEquals(line_list, ['ahah', 'accb', 'allo', 'addb']) | 1127 self.assertEquals(line_list, ['ahah', 'accb', 'allo', 'addb']) |
1105 self.assertEquals(capture_list, ['cc', 'dd']) | 1128 self.assertEquals(capture_list, ['cc', 'dd']) |
1106 | 1129 |
1107 def testCaptureSVNStatus(self): | 1130 def testCaptureSVNStatus(self): |
1108 x = self | 1131 gclient.gclient_scm.CaptureSVN( |
1109 def CaptureSVNMock(command, in_directory=None, print_error=True): | 1132 ['status', '--xml', '.'] |
1110 x.assertEquals(in_directory, None) | 1133 ).AndReturn(r"""<?xml version="1.0"?> |
1111 x.assertEquals(print_error, True) | |
1112 x.assertEquals(['status', '--xml', '.'], command) | |
1113 return r"""<?xml version="1.0"?> | |
1114 <status> | 1134 <status> |
1115 <target path="."> | 1135 <target path="."> |
1116 <entry path="unversionned_file.txt"> | 1136 <entry path="unversionned_file.txt"> |
1117 <wc-status props="none" item="unversioned"></wc-status> | 1137 <wc-status props="none" item="unversioned"></wc-status> |
1118 </entry> | 1138 </entry> |
1119 <entry path="build\internal\essential.vsprops"> | 1139 <entry path="build\internal\essential.vsprops"> |
1120 <wc-status props="normal" item="modified" revision="14628"> | 1140 <wc-status props="normal" item="modified" revision="14628"> |
1121 <commit revision="13818"> | 1141 <commit revision="13818"> |
1122 <author>ajwong@chromium.org</author> | 1142 <author>ajwong@chromium.org</author> |
1123 <date>2009-04-16T00:42:06.872358Z</date> | 1143 <date>2009-04-16T00:42:06.872358Z</date> |
(...skipping 15 matching lines...) Expand all Loading... | |
1139 <entry path="scripts\master\factory\gclient_factory.py"> | 1159 <entry path="scripts\master\factory\gclient_factory.py"> |
1140 <wc-status props="normal" item="conflicted" revision="14725"> | 1160 <wc-status props="normal" item="conflicted" revision="14725"> |
1141 <commit revision="14633"> | 1161 <commit revision="14633"> |
1142 <author>nsylvain@chromium.org</author> | 1162 <author>nsylvain@chromium.org</author> |
1143 <date>2009-04-27T19:37:17.977400Z</date> | 1163 <date>2009-04-27T19:37:17.977400Z</date> |
1144 </commit> | 1164 </commit> |
1145 </wc-status> | 1165 </wc-status> |
1146 </entry> | 1166 </entry> |
1147 </target> | 1167 </target> |
1148 </status> | 1168 </status> |
1149 """ | 1169 """) |
1150 gclient_scm.CaptureSVN = CaptureSVNMock | 1170 self.mox.ReplayAll() |
1151 info = gclient_scm.CaptureSVNStatus('.') | 1171 info = gclient.gclient_scm.CaptureSVNStatus('.') |
1152 expected = [ | 1172 expected = [ |
1153 ('? ', 'unversionned_file.txt'), | 1173 ('? ', 'unversionned_file.txt'), |
1154 ('M ', 'build\\internal\\essential.vsprops'), | 1174 ('M ', 'build\\internal\\essential.vsprops'), |
1155 ('A + ', 'chrome\\app\\d'), | 1175 ('A + ', 'chrome\\app\\d'), |
1156 ('MM ', 'chrome\\app\\DEPS'), | 1176 ('MM ', 'chrome\\app\\DEPS'), |
1157 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), | 1177 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), |
1158 ] | 1178 ] |
1159 self.assertEquals(sorted(info), sorted(expected)) | 1179 self.assertEquals(sorted(info), sorted(expected)) |
1160 | 1180 |
1161 def testCaptureSVNStatusEmpty(self): | 1181 def testCaptureSVNStatusEmpty(self): |
1162 x = self | 1182 gclient.gclient_scm.CaptureSVN( |
1163 def CaptureSVNMock(command, in_directory=None, print_error=True): | 1183 ['status', '--xml'] |
1164 x.assertEquals(in_directory, None) | 1184 ).AndReturn(r"""<?xml version="1.0"?> |
1165 x.assertEquals(['status', '--xml'], command) | |
1166 return r"""<?xml version="1.0"?> | |
1167 <status> | 1185 <status> |
1168 <target | 1186 <target |
1169 path="perf"> | 1187 path="perf"> |
1170 </target> | 1188 </target> |
1171 </status> | 1189 </status> |
1172 """ | 1190 """) |
1173 gclient_scm.CaptureSVN = CaptureSVNMock | 1191 self.mox.ReplayAll() |
1174 info = gclient_scm.CaptureSVNStatus(None) | 1192 info = gclient.gclient_scm.CaptureSVNStatus(None) |
1175 self.assertEquals(info, []) | 1193 self.assertEquals(info, []) |
1176 | 1194 |
1177 | 1195 |
1178 if __name__ == '__main__': | 1196 if __name__ == '__main__': |
1197 import unittest | |
1179 unittest.main() | 1198 unittest.main() |
1180 | 1199 |
1181 # vim: ts=2:sw=2:tw=80:et: | 1200 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |