| 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 # |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 | 44 |
| 45 class BaseTestCase(super_mox.SuperMoxTestBase): | 45 class BaseTestCase(super_mox.SuperMoxTestBase): |
| 46 def setUp(self): | 46 def setUp(self): |
| 47 super_mox.SuperMoxTestBase.setUp(self) | 47 super_mox.SuperMoxTestBase.setUp(self) |
| 48 | 48 |
| 49 # Like unittest's assertRaises, but checks for Gclient.Error. | 49 # Like unittest's assertRaises, but checks for Gclient.Error. |
| 50 def assertRaisesError(self, msg, fn, *args, **kwargs): | 50 def assertRaisesError(self, msg, fn, *args, **kwargs): |
| 51 try: | 51 try: |
| 52 fn(*args, **kwargs) | 52 fn(*args, **kwargs) |
| 53 except gclient.Error, e: | 53 except gclient_utils.Error, e: |
| 54 self.assertEquals(e.args[0], msg) | 54 self.assertEquals(e.args[0], msg) |
| 55 else: | 55 else: |
| 56 self.fail('%s not raised' % msg) | 56 self.fail('%s not raised' % msg) |
| 57 | 57 |
| 58 | 58 |
| 59 class GClientBaseTestCase(BaseTestCase): | 59 class GClientBaseTestCase(BaseTestCase): |
| 60 def Options(self, *args, **kwargs): | 60 def Options(self, *args, **kwargs): |
| 61 return self.OptionsObject(self, *args, **kwargs) | 61 return self.OptionsObject(self, *args, **kwargs) |
| 62 | 62 |
| 63 def setUp(self): | 63 def setUp(self): |
| 64 BaseTestCase.setUp(self) | 64 BaseTestCase.setUp(self) |
| 65 self.mox.StubOutWithMock(gclient.os.path, 'exists') | 65 self.mox.StubOutWithMock(gclient.os.path, 'exists') |
| 66 self.mox.StubOutWithMock(gclient.os.path, 'isfile') | 66 self.mox.StubOutWithMock(gclient.os.path, 'isfile') |
| 67 self.mox.StubOutWithMock(gclient.os.path, 'isdir') | 67 self.mox.StubOutWithMock(gclient.os.path, 'isdir') |
| 68 self.mox.StubOutWithMock(gclient.os, 'remove') | 68 self.mox.StubOutWithMock(gclient.os, 'remove') |
| 69 self.mox.StubOutWithMock(gclient.sys, 'stdout') | 69 self.mox.StubOutWithMock(gclient.sys, 'stdout') |
| 70 self.mox.StubOutWithMock(gclient_utils, 'subprocess') | 70 self.mox.StubOutWithMock(gclient_utils, 'subprocess') |
| 71 # These are not tested. | 71 # These are not tested. |
| 72 self.mox.StubOutWithMock(gclient, 'FileRead') | 72 self.mox.StubOutWithMock(gclient_utils, 'FileRead') |
| 73 self.mox.StubOutWithMock(gclient, 'FileWrite') | 73 self.mox.StubOutWithMock(gclient_utils, 'FileWrite') |
| 74 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') | 74 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') |
| 75 self.mox.StubOutWithMock(gclient_utils, 'RemoveDirectory') | 75 self.mox.StubOutWithMock(gclient_utils, 'RemoveDirectory') |
| 76 # Mock them to be sure nothing bad happens. | 76 # Mock them to be sure nothing bad happens. |
| 77 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVN') | 77 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVN') |
| 78 self._CaptureSVNInfo = gclient_scm.CaptureSVNInfo | 78 self._CaptureSVNInfo = gclient_scm.CaptureSVNInfo |
| 79 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNInfo') | 79 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNInfo') |
| 80 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNStatus') | 80 self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNStatus') |
| 81 self.mox.StubOutWithMock(gclient_scm, 'RunSVN') | 81 self.mox.StubOutWithMock(gclient_scm, 'RunSVN') |
| 82 self.mox.StubOutWithMock(gclient_scm, 'RunSVNAndGetFileList') | 82 self.mox.StubOutWithMock(gclient_scm, 'RunSVNAndGetFileList') |
| 83 self._gclient_gclient = gclient.GClient | 83 self._gclient_gclient = gclient.GClient |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 self.args = self.Args() | 119 self.args = self.Args() |
| 120 self.root_dir = self.Dir() | 120 self.root_dir = self.Dir() |
| 121 self.url = self.Url() | 121 self.url = self.Url() |
| 122 | 122 |
| 123 | 123 |
| 124 class GClientCommandsTestCase(GClientBaseTestCase): | 124 class GClientCommandsTestCase(GClientBaseTestCase): |
| 125 def testCommands(self): | 125 def testCommands(self): |
| 126 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff, | 126 known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff, |
| 127 gclient.DoExport, gclient.DoHelp, gclient.DoStatus, | 127 gclient.DoExport, gclient.DoHelp, gclient.DoStatus, |
| 128 » » gclient.DoUpdate, gclient.DoRevert, gclient.DoRunHooks, | 128 gclient.DoUpdate, gclient.DoRevert, gclient.DoRunHooks, |
| 129 » » gclient.DoRevInfo, gclient.DoPack] | 129 gclient.DoRevInfo, gclient.DoPack] |
| 130 for (k,v) in gclient.gclient_command_map.iteritems(): | 130 for (k,v) in gclient.gclient_command_map.iteritems(): |
| 131 # If it fails, you need to add a test case for the new command. | 131 # If it fails, you need to add a test case for the new command. |
| 132 self.assert_(v in known_commands) | 132 self.assert_(v in known_commands) |
| 133 self.mox.ReplayAll() | 133 self.mox.ReplayAll() |
| 134 | 134 |
| 135 class TestDoConfig(GclientTestCase): | 135 class TestDoConfig(GclientTestCase): |
| 136 def testMissingArgument(self): | 136 def testMissingArgument(self): |
| 137 exception_msg = "required argument missing; see 'gclient help config'" | 137 exception_msg = "required argument missing; see 'gclient help config'" |
| 138 | 138 |
| 139 self.mox.ReplayAll() | 139 self.mox.ReplayAll() |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 'RunOnDeps', 'SaveConfig', 'SetConfig', 'SetDefaultConfig', | 346 'RunOnDeps', 'SaveConfig', 'SetConfig', 'SetDefaultConfig', |
| 347 'supported_commands', 'PrintRevInfo', | 347 'supported_commands', 'PrintRevInfo', |
| 348 ] | 348 ] |
| 349 | 349 |
| 350 # If you add a member, be sure to add the relevant test! | 350 # If you add a member, be sure to add the relevant test! |
| 351 self.compareMembers(self._gclient_gclient('root_dir', 'options'), members) | 351 self.compareMembers(self._gclient_gclient('root_dir', 'options'), members) |
| 352 | 352 |
| 353 def testSetConfig_ConfigContent_GetVar_SaveConfig_SetDefaultConfig(self): | 353 def testSetConfig_ConfigContent_GetVar_SaveConfig_SetDefaultConfig(self): |
| 354 options = self.Options() | 354 options = self.Options() |
| 355 text = "# Dummy content\nclient = 'my client'" | 355 text = "# Dummy content\nclient = 'my client'" |
| 356 gclient.FileWrite(os.path.join(self.root_dir, options.config_filename), | 356 gclient_utils.FileWrite( |
| 357 text) | 357 os.path.join(self.root_dir, options.config_filename), |
| 358 text) |
| 358 | 359 |
| 359 self.mox.ReplayAll() | 360 self.mox.ReplayAll() |
| 360 client = self._gclient_gclient(self.root_dir, options) | 361 client = self._gclient_gclient(self.root_dir, options) |
| 361 client.SetConfig(text) | 362 client.SetConfig(text) |
| 362 self.assertEqual(client.ConfigContent(), text) | 363 self.assertEqual(client.ConfigContent(), text) |
| 363 self.assertEqual(client.GetVar('client'), 'my client') | 364 self.assertEqual(client.GetVar('client'), 'my client') |
| 364 self.assertEqual(client.GetVar('foo'), None) | 365 self.assertEqual(client.GetVar('foo'), None) |
| 365 client.SaveConfig() | 366 client.SaveConfig() |
| 366 | 367 |
| 367 solution_name = 'solution name' | 368 solution_name = 'solution name' |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 423 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) |
| 423 ).AndReturn(False) | 424 ).AndReturn(False) |
| 424 | 425 |
| 425 # An scm will be requested for the solution. | 426 # An scm will be requested for the solution. |
| 426 scm_wrapper_sol = self.mox.CreateMockAnything() | 427 scm_wrapper_sol = self.mox.CreateMockAnything() |
| 427 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name | 428 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name |
| 428 ).AndReturn(scm_wrapper_sol) | 429 ).AndReturn(scm_wrapper_sol) |
| 429 # Then an update will be performed. | 430 # Then an update will be performed. |
| 430 scm_wrapper_sol.RunCommand('update', options, self.args, []) | 431 scm_wrapper_sol.RunCommand('update', options, self.args, []) |
| 431 # Then an attempt will be made to read its DEPS file. | 432 # Then an attempt will be made to read its DEPS file. |
| 432 gclient.FileRead(os.path.join(self.root_dir, | 433 gclient_utils.FileRead(os.path.join(self.root_dir, |
| 433 solution_name, | 434 solution_name, |
| 434 options.deps_file)).AndRaise(IOError(2, 'No DEPS file')) | 435 options.deps_file) |
| 436 ).AndRaise(IOError(2, 'No DEPS file')) |
| 435 | 437 |
| 436 # After everything is done, an attempt is made to write an entries | 438 # After everything is done, an attempt is made to write an entries |
| 437 # file. | 439 # file. |
| 438 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), | 440 gclient_utils.FileWrite( |
| 441 os.path.join(self.root_dir, options.entries_filename), |
| 439 IsOneOf((entries_content1, entries_content2))) | 442 IsOneOf((entries_content1, entries_content2))) |
| 440 | 443 |
| 441 self.mox.ReplayAll() | 444 self.mox.ReplayAll() |
| 442 client = self._gclient_gclient(self.root_dir, options) | 445 client = self._gclient_gclient(self.root_dir, options) |
| 443 client.SetConfig(gclient_config) | 446 client.SetConfig(gclient_config) |
| 444 client.RunOnDeps('update', self.args) | 447 client.RunOnDeps('update', self.args) |
| 445 | 448 |
| 446 def testRunOnDepsRelativePaths(self): | 449 def testRunOnDepsRelativePaths(self): |
| 447 solution_name = 'testRunOnDepsRelativePaths_solution_name' | 450 solution_name = 'testRunOnDepsRelativePaths_solution_name' |
| 448 gclient_config = ( | 451 gclient_config = ( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 478 # Expect a check for the entries file and we say there is not one. | 481 # Expect a check for the entries file and we say there is not one. |
| 479 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 482 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) |
| 480 ).AndReturn(False) | 483 ).AndReturn(False) |
| 481 | 484 |
| 482 # An scm will be requested for the solution. | 485 # An scm will be requested for the solution. |
| 483 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name | 486 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name |
| 484 ).AndReturn(scm_wrapper_sol) | 487 ).AndReturn(scm_wrapper_sol) |
| 485 # Then an update will be performed. | 488 # Then an update will be performed. |
| 486 scm_wrapper_sol.RunCommand('update', options, self.args, []) | 489 scm_wrapper_sol.RunCommand('update', options, self.args, []) |
| 487 # Then an attempt will be made to read its DEPS file. | 490 # Then an attempt will be made to read its DEPS file. |
| 488 gclient.FileRead(os.path.join(self.root_dir, | 491 gclient_utils.FileRead(os.path.join(self.root_dir, |
| 489 solution_name, | 492 solution_name, |
| 490 options.deps_file)).AndReturn(deps) | 493 options.deps_file)).AndReturn(deps) |
| 491 | 494 |
| 492 # Next we expect an scm to be request for dep src/t but it should | 495 # Next we expect an scm to be request for dep src/t but it should |
| 493 # use the url specified in deps and the relative path should now | 496 # use the url specified in deps and the relative path should now |
| 494 # be relative to the DEPS file. | 497 # be relative to the DEPS file. |
| 495 gclient_scm.CreateSCM( | 498 gclient_scm.CreateSCM( |
| 496 'svn://scm.t/trunk', | 499 'svn://scm.t/trunk', |
| 497 self.root_dir, | 500 self.root_dir, |
| 498 os.path.join(solution_name, "src", "t")).AndReturn(scm_wrapper_t) | 501 os.path.join(solution_name, "src", "t")).AndReturn(scm_wrapper_t) |
| 499 scm_wrapper_t.RunCommand('update', options, self.args, []) | 502 scm_wrapper_t.RunCommand('update', options, self.args, []) |
| 500 | 503 |
| 501 # After everything is done, an attempt is made to write an entries | 504 # After everything is done, an attempt is made to write an entries |
| 502 # file. | 505 # file. |
| 503 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), | 506 gclient_utils.FileWrite( |
| 507 os.path.join(self.root_dir, options.entries_filename), |
| 504 entries_content) | 508 entries_content) |
| 505 | 509 |
| 506 self.mox.ReplayAll() | 510 self.mox.ReplayAll() |
| 507 client = self._gclient_gclient(self.root_dir, options) | 511 client = self._gclient_gclient(self.root_dir, options) |
| 508 client.SetConfig(gclient_config) | 512 client.SetConfig(gclient_config) |
| 509 client.RunOnDeps('update', self.args) | 513 client.RunOnDeps('update', self.args) |
| 510 | 514 |
| 511 def testRunOnDepsCustomDeps(self): | 515 def testRunOnDepsCustomDeps(self): |
| 512 solution_name = 'testRunOnDepsCustomDeps_solution_name' | 516 solution_name = 'testRunOnDepsCustomDeps_solution_name' |
| 513 gclient_config = ( | 517 gclient_config = ( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 # 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. |
| 552 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 556 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) |
| 553 ).AndReturn(False) | 557 ).AndReturn(False) |
| 554 | 558 |
| 555 # An scm will be requested for the solution. | 559 # An scm will be requested for the solution. |
| 556 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name | 560 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name |
| 557 ).AndReturn(scm_wrapper_sol) | 561 ).AndReturn(scm_wrapper_sol) |
| 558 # Then an update will be performed. | 562 # Then an update will be performed. |
| 559 scm_wrapper_sol.RunCommand('update', options, self.args, []) | 563 scm_wrapper_sol.RunCommand('update', options, self.args, []) |
| 560 # Then an attempt will be made to read its DEPS file. | 564 # Then an attempt will be made to read its DEPS file. |
| 561 gclient.FileRead(os.path.join(checkout_path, options.deps_file) | 565 gclient_utils.FileRead(os.path.join(checkout_path, options.deps_file) |
| 562 ).AndReturn(deps) | 566 ).AndReturn(deps) |
| 563 | 567 |
| 564 # Next we expect an scm to be request for dep src/n even though it does not | 568 # Next we expect an scm to be request for dep src/n even though it does not |
| 565 # exist in the DEPS file. | 569 # exist in the DEPS file. |
| 566 gclient_scm.CreateSCM('svn://custom.n/trunk', | 570 gclient_scm.CreateSCM('svn://custom.n/trunk', |
| 567 self.root_dir, | 571 self.root_dir, |
| 568 "src/n").AndReturn(scm_wrapper_n) | 572 "src/n").AndReturn(scm_wrapper_n) |
| 569 | 573 |
| 570 # Next we expect an scm to be request for dep src/t but it should | 574 # Next we expect an scm to be request for dep src/t but it should |
| 571 # use the url specified in custom_deps. | 575 # use the url specified in custom_deps. |
| 572 gclient_scm.CreateSCM('svn://custom.t/trunk', | 576 gclient_scm.CreateSCM('svn://custom.t/trunk', |
| 573 self.root_dir, | 577 self.root_dir, |
| 574 "src/t").AndReturn(scm_wrapper_t) | 578 "src/t").AndReturn(scm_wrapper_t) |
| 575 | 579 |
| 576 scm_wrapper_n.RunCommand('update', options, self.args, []) | 580 scm_wrapper_n.RunCommand('update', options, self.args, []) |
| 577 scm_wrapper_t.RunCommand('update', options, self.args, []) | 581 scm_wrapper_t.RunCommand('update', options, self.args, []) |
| 578 | 582 |
| 579 # NOTE: the dep src/b should not create an scm at all. | 583 # NOTE: the dep src/b should not create an scm at all. |
| 580 | 584 |
| 581 # After everything is done, an attempt is made to write an entries | 585 # After everything is done, an attempt is made to write an entries |
| 582 # file. | 586 # file. |
| 583 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), | 587 gclient_utils.FileWrite( |
| 588 os.path.join(self.root_dir, options.entries_filename), |
| 584 entries_content) | 589 entries_content) |
| 585 | 590 |
| 586 self.mox.ReplayAll() | 591 self.mox.ReplayAll() |
| 587 client = self._gclient_gclient(self.root_dir, options) | 592 client = self._gclient_gclient(self.root_dir, options) |
| 588 client.SetConfig(gclient_config) | 593 client.SetConfig(gclient_config) |
| 589 client.RunOnDeps('update', self.args) | 594 client.RunOnDeps('update', self.args) |
| 590 | 595 |
| 591 # Regression test for Issue #11. | 596 # Regression test for Issue #11. |
| 592 # http://code.google.com/p/gclient/issues/detail?id=11 | 597 # http://code.google.com/p/gclient/issues/detail?id=11 |
| 593 def testRunOnDepsSharedDependency(self): | 598 def testRunOnDepsSharedDependency(self): |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 ).AndReturn(False) | 641 ).AndReturn(False) |
| 637 | 642 |
| 638 # Expect a check for the entries file and we say there is not one. | 643 # Expect a check for the entries file and we say there is not one. |
| 639 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 644 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) |
| 640 ).AndReturn(False) | 645 ).AndReturn(False) |
| 641 | 646 |
| 642 # An scm will be requested for the first solution. | 647 # An scm will be requested for the first solution. |
| 643 gclient_scm.CreateSCM(url_a, self.root_dir, name_a).AndReturn( | 648 gclient_scm.CreateSCM(url_a, self.root_dir, name_a).AndReturn( |
| 644 scm_wrapper_a) | 649 scm_wrapper_a) |
| 645 # Then an attempt will be made to read it's DEPS file. | 650 # Then an attempt will be made to read it's DEPS file. |
| 646 gclient.FileRead(os.path.join(self.root_dir, name_a, options.deps_file) | 651 gclient_utils.FileRead( |
| 652 os.path.join(self.root_dir, name_a, options.deps_file) |
| 647 ).AndReturn(deps_a) | 653 ).AndReturn(deps_a) |
| 648 # Then an update will be performed. | 654 # Then an update will be performed. |
| 649 scm_wrapper_a.RunCommand('update', options, self.args, []) | 655 scm_wrapper_a.RunCommand('update', options, self.args, []) |
| 650 | 656 |
| 651 # An scm will be requested for the second solution. | 657 # An scm will be requested for the second solution. |
| 652 gclient_scm.CreateSCM(url_b, self.root_dir, name_b).AndReturn( | 658 gclient_scm.CreateSCM(url_b, self.root_dir, name_b).AndReturn( |
| 653 scm_wrapper_b) | 659 scm_wrapper_b) |
| 654 # Then an attempt will be made to read its DEPS file. | 660 # Then an attempt will be made to read its DEPS file. |
| 655 gclient.FileRead(os.path.join(self.root_dir, name_b, options.deps_file) | 661 gclient_utils.FileRead( |
| 662 os.path.join(self.root_dir, name_b, options.deps_file) |
| 656 ).AndReturn(deps_b) | 663 ).AndReturn(deps_b) |
| 657 # Then an update will be performed. | 664 # Then an update will be performed. |
| 658 scm_wrapper_b.RunCommand('update', options, self.args, []) | 665 scm_wrapper_b.RunCommand('update', options, self.args, []) |
| 659 | 666 |
| 660 # Finally, an scm is requested for the shared dep. | 667 # Finally, an scm is requested for the shared dep. |
| 661 gclient_scm.CreateSCM('http://svn.t/trunk', self.root_dir, 'src/t' | 668 gclient_scm.CreateSCM('http://svn.t/trunk', self.root_dir, 'src/t' |
| 662 ).AndReturn(scm_wrapper_dep) | 669 ).AndReturn(scm_wrapper_dep) |
| 663 # And an update is run on it. | 670 # And an update is run on it. |
| 664 scm_wrapper_dep.RunCommand('update', options, self.args, []) | 671 scm_wrapper_dep.RunCommand('update', options, self.args, []) |
| 665 | 672 |
| 666 # After everything is done, an attempt is made to write an entries file. | 673 # After everything is done, an attempt is made to write an entries file. |
| 667 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), | 674 gclient_utils.FileWrite( |
| 675 os.path.join(self.root_dir, options.entries_filename), |
| 668 entries_content) | 676 entries_content) |
| 669 | 677 |
| 670 self.mox.ReplayAll() | 678 self.mox.ReplayAll() |
| 671 client = self._gclient_gclient(self.root_dir, options) | 679 client = self._gclient_gclient(self.root_dir, options) |
| 672 client.SetConfig(gclient_config) | 680 client.SetConfig(gclient_config) |
| 673 client.RunOnDeps('update', self.args) | 681 client.RunOnDeps('update', self.args) |
| 674 | 682 |
| 675 def testRunOnDepsSuccess(self): | 683 def testRunOnDepsSuccess(self): |
| 676 # Fake .gclient file. | 684 # Fake .gclient file. |
| 677 name = 'testRunOnDepsSuccess_solution_name' | 685 name = 'testRunOnDepsSuccess_solution_name' |
| 678 gclient_config = """solutions = [ { | 686 gclient_config = """solutions = [ { |
| 679 'name': '%s', | 687 'name': '%s', |
| 680 'url': '%s', | 688 'url': '%s', |
| 681 'custom_deps': {}, | 689 'custom_deps': {}, |
| 682 }, ]""" % (name, self.url) | 690 }, ]""" % (name, self.url) |
| 683 | 691 |
| 684 entries_content = ( | 692 entries_content = ( |
| 685 "entries = \\\n" | 693 "entries = \\\n" |
| 686 "{ '%s': '%s'}\n" | 694 "{ '%s': '%s'}\n" |
| 687 ) % (name, self.url) | 695 ) % (name, self.url) |
| 688 | 696 |
| 689 options = self.Options() | 697 options = self.Options() |
| 690 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') | 698 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') |
| 691 ).AndReturn(False) | 699 ).AndReturn(False) |
| 692 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 700 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) |
| 693 ).AndReturn(False) | 701 ).AndReturn(False) |
| 694 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | 702 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( |
| 695 gclient_scm.CreateSCM) | 703 gclient_scm.CreateSCM) |
| 696 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 704 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) |
| 697 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) | 705 gclient_utils.FileRead(os.path.join(self.root_dir, name, options.deps_file) |
| 698 ).AndReturn("Boo = 'a'") | 706 ).AndReturn("Boo = 'a'") |
| 699 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), | 707 gclient_utils.FileWrite( |
| 700 entries_content) | 708 os.path.join(self.root_dir, options.entries_filename), |
| 709 entries_content) |
| 701 | 710 |
| 702 self.mox.ReplayAll() | 711 self.mox.ReplayAll() |
| 703 client = self._gclient_gclient(self.root_dir, options) | 712 client = self._gclient_gclient(self.root_dir, options) |
| 704 client.SetConfig(gclient_config) | 713 client.SetConfig(gclient_config) |
| 705 client.RunOnDeps('update', self.args) | 714 client.RunOnDeps('update', self.args) |
| 706 | 715 |
| 707 def testRunOnDepsRevisions(self): | 716 def testRunOnDepsRevisions(self): |
| 708 def OptIsRev(options, rev): | 717 def OptIsRev(options, rev): |
| 709 if not options.revision == str(rev): | 718 if not options.revision == str(rev): |
| 710 print("options.revision = %s" % options.revision) | 719 print("options.revision = %s" % options.revision) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 scm_wrapper_webkit = self.mox.CreateMockAnything() | 770 scm_wrapper_webkit = self.mox.CreateMockAnything() |
| 762 scm_wrapper_breakpad = self.mox.CreateMockAnything() | 771 scm_wrapper_breakpad = self.mox.CreateMockAnything() |
| 763 scm_wrapper_cygwin = self.mox.CreateMockAnything() | 772 scm_wrapper_cygwin = self.mox.CreateMockAnything() |
| 764 scm_wrapper_python = self.mox.CreateMockAnything() | 773 scm_wrapper_python = self.mox.CreateMockAnything() |
| 765 options = self.Options() | 774 options = self.Options() |
| 766 options.revisions = [ 'src@123', 'foo/third_party/WebKit@42', | 775 options.revisions = [ 'src@123', 'foo/third_party/WebKit@42', |
| 767 'src/third_party/cygwin@333' ] | 776 'src/third_party/cygwin@333' ] |
| 768 | 777 |
| 769 # Also, pymox doesn't verify the order of function calling w.r.t. different | 778 # Also, pymox doesn't verify the order of function calling w.r.t. different |
| 770 # mock objects. Pretty lame. So reorder as we wish to make it clearer. | 779 # mock objects. Pretty lame. So reorder as we wish to make it clearer. |
| 771 gclient.FileRead(os.path.join(self.root_dir, 'src', options.deps_file) | 780 gclient_utils.FileRead( |
| 781 os.path.join(self.root_dir, 'src', options.deps_file) |
| 772 ).AndReturn(deps_content) | 782 ).AndReturn(deps_content) |
| 773 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), | 783 gclient_utils.FileWrite( |
| 774 entries_content) | 784 os.path.join(self.root_dir, options.entries_filename), |
| 785 entries_content) |
| 775 | 786 |
| 776 gclient.os.path.exists(os.path.join(self.root_dir, 'src', '.git') | 787 gclient.os.path.exists(os.path.join(self.root_dir, 'src', '.git') |
| 777 ).AndReturn(False) | 788 ).AndReturn(False) |
| 778 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', | 789 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', |
| 779 '.git') | 790 '.git') |
| 780 ).AndReturn(False) | 791 ).AndReturn(False) |
| 781 gclient.os.path.exists(os.path.join(self.root_dir, 'src/third_party/cygwin', | 792 gclient.os.path.exists(os.path.join(self.root_dir, 'src/third_party/cygwin', |
| 782 '.git') | 793 '.git') |
| 783 ).AndReturn(False) | 794 ).AndReturn(False) |
| 784 gclient.os.path.exists(os.path.join(self.root_dir, | 795 gclient.os.path.exists(os.path.join(self.root_dir, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 }""" | 857 }""" |
| 847 | 858 |
| 848 options = self.Options() | 859 options = self.Options() |
| 849 options.revisions = [ 'foo/third_party/WebKit@42', | 860 options.revisions = [ 'foo/third_party/WebKit@42', |
| 850 'foo/third_party/WebKit@43' ] | 861 'foo/third_party/WebKit@43' ] |
| 851 client = self._gclient_gclient(self.root_dir, options) | 862 client = self._gclient_gclient(self.root_dir, options) |
| 852 client.SetConfig(gclient_config) | 863 client.SetConfig(gclient_config) |
| 853 exception = "Conflicting revision numbers specified." | 864 exception = "Conflicting revision numbers specified." |
| 854 try: | 865 try: |
| 855 client.RunOnDeps('update', self.args) | 866 client.RunOnDeps('update', self.args) |
| 856 except gclient.Error, e: | 867 except gclient_utils.Error, e: |
| 857 self.assertEquals(e.args[0], exception) | 868 self.assertEquals(e.args[0], exception) |
| 858 else: | 869 else: |
| 859 self.fail('%s not raised' % exception) | 870 self.fail('%s not raised' % exception) |
| 860 | 871 |
| 861 def testRunOnDepsSuccessVars(self): | 872 def testRunOnDepsSuccessVars(self): |
| 862 # Fake .gclient file. | 873 # Fake .gclient file. |
| 863 name = 'testRunOnDepsSuccessVars_solution_name' | 874 name = 'testRunOnDepsSuccessVars_solution_name' |
| 864 gclient_config = """solutions = [ { | 875 gclient_config = """solutions = [ { |
| 865 'name': '%s', | 876 'name': '%s', |
| 866 'url': '%s', | 877 'url': '%s', |
| (...skipping 13 matching lines...) Expand all Loading... |
| 880 entries_content = ( | 891 entries_content = ( |
| 881 "entries = \\\n" | 892 "entries = \\\n" |
| 882 "{ 'foo/third_party/WebKit': '%s',\n" | 893 "{ 'foo/third_party/WebKit': '%s',\n" |
| 883 " '%s': '%s'}\n" | 894 " '%s': '%s'}\n" |
| 884 ) % (webkit_path, name, self.url) | 895 ) % (webkit_path, name, self.url) |
| 885 | 896 |
| 886 scm_wrapper_webkit = self.mox.CreateMockAnything() | 897 scm_wrapper_webkit = self.mox.CreateMockAnything() |
| 887 scm_wrapper_src = self.mox.CreateMockAnything() | 898 scm_wrapper_src = self.mox.CreateMockAnything() |
| 888 | 899 |
| 889 options = self.Options() | 900 options = self.Options() |
| 890 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) | 901 gclient_utils.FileRead( |
| 902 os.path.join(self.root_dir, name, options.deps_file) |
| 891 ).AndReturn(deps_content) | 903 ).AndReturn(deps_content) |
| 892 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), | 904 gclient_utils.FileWrite( |
| 893 entries_content) | 905 os.path.join(self.root_dir, options.entries_filename), |
| 906 entries_content) |
| 894 | 907 |
| 895 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', | 908 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', |
| 896 '.git')).AndReturn(False) | 909 '.git')).AndReturn(False) |
| 897 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') | 910 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') |
| 898 ).AndReturn(False) | 911 ).AndReturn(False) |
| 899 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 912 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) |
| 900 ).AndReturn(False) | 913 ).AndReturn(False) |
| 901 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | 914 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( |
| 902 gclient_scm.CreateSCM) | 915 gclient_scm.CreateSCM) |
| 903 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 916 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 entries_content = ( | 951 entries_content = ( |
| 939 "entries = \\\n" | 952 "entries = \\\n" |
| 940 "{ 'foo/third_party/WebKit': '%s',\n" | 953 "{ 'foo/third_party/WebKit': '%s',\n" |
| 941 " '%s': '%s'}\n" | 954 " '%s': '%s'}\n" |
| 942 ) % (webkit_path, name, self.url) | 955 ) % (webkit_path, name, self.url) |
| 943 | 956 |
| 944 scm_wrapper_webkit = self.mox.CreateMockAnything() | 957 scm_wrapper_webkit = self.mox.CreateMockAnything() |
| 945 scm_wrapper_src = self.mox.CreateMockAnything() | 958 scm_wrapper_src = self.mox.CreateMockAnything() |
| 946 | 959 |
| 947 options = self.Options() | 960 options = self.Options() |
| 948 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) | 961 gclient_utils.FileRead( |
| 962 os.path.join(self.root_dir, name, options.deps_file) |
| 949 ).AndReturn(deps_content) | 963 ).AndReturn(deps_content) |
| 950 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), | 964 gclient_utils.FileWrite( |
| 951 entries_content) | 965 os.path.join(self.root_dir, options.entries_filename), |
| 966 entries_content) |
| 952 | 967 |
| 953 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', | 968 gclient.os.path.exists(os.path.join(self.root_dir, 'foo/third_party/WebKit', |
| 954 '.git') | 969 '.git') |
| 955 ).AndReturn(False) | 970 ).AndReturn(False) |
| 956 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') | 971 gclient.os.path.exists(os.path.join(self.root_dir, name, '.git') |
| 957 ).AndReturn(False) | 972 ).AndReturn(False) |
| 958 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 973 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) |
| 959 ).AndReturn(False) | 974 ).AndReturn(False) |
| 960 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | 975 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( |
| 961 gclient_scm.CreateSCM) | 976 gclient_scm.CreateSCM) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 983 'url': '%s', | 998 'url': '%s', |
| 984 'custom_deps': {}, | 999 'custom_deps': {}, |
| 985 'custom_vars': {}, | 1000 'custom_vars': {}, |
| 986 }, ]""" % (name, self.url) | 1001 }, ]""" % (name, self.url) |
| 987 # Fake DEPS file. | 1002 # Fake DEPS file. |
| 988 deps_content = """deps = { | 1003 deps_content = """deps = { |
| 989 'foo/third_party/WebKit': Var('webkit') + 'WebKit', | 1004 'foo/third_party/WebKit': Var('webkit') + 'WebKit', |
| 990 }""" | 1005 }""" |
| 991 | 1006 |
| 992 options = self.Options() | 1007 options = self.Options() |
| 993 gclient.FileRead(os.path.join(self.root_dir, name, options.deps_file) | 1008 gclient_utils.FileRead( |
| 1009 os.path.join(self.root_dir, name, options.deps_file) |
| 994 ).AndReturn(deps_content) | 1010 ).AndReturn(deps_content) |
| 995 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | 1011 gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( |
| 996 gclient_scm.CreateSCM) | 1012 gclient_scm.CreateSCM) |
| 997 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 1013 gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) |
| 998 | 1014 |
| 999 self.mox.ReplayAll() | 1015 self.mox.ReplayAll() |
| 1000 client = self._gclient_gclient(self.root_dir, options) | 1016 client = self._gclient_gclient(self.root_dir, options) |
| 1001 client.SetConfig(gclient_config) | 1017 client.SetConfig(gclient_config) |
| 1002 exception = "Var is not defined: webkit" | 1018 exception = "Var is not defined: webkit" |
| 1003 try: | 1019 try: |
| 1004 client.RunOnDeps('update', self.args) | 1020 client.RunOnDeps('update', self.args) |
| 1005 except gclient.Error, e: | 1021 except gclient_utils.Error, e: |
| 1006 self.assertEquals(e.args[0], exception) | 1022 self.assertEquals(e.args[0], exception) |
| 1007 else: | 1023 else: |
| 1008 self.fail('%s not raised' % exception) | 1024 self.fail('%s not raised' % exception) |
| 1009 | 1025 |
| 1010 def testRunOnDepsFailureInvalidCommand(self): | 1026 def testRunOnDepsFailureInvalidCommand(self): |
| 1011 options = self.Options() | 1027 options = self.Options() |
| 1012 | 1028 |
| 1013 self.mox.ReplayAll() | 1029 self.mox.ReplayAll() |
| 1014 client = self._gclient_gclient(self.root_dir, options) | 1030 client = self._gclient_gclient(self.root_dir, options) |
| 1015 exception = "'foo' is an unsupported command" | 1031 exception = "'foo' is an unsupported command" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 """ | 1172 """ |
| 1157 gclient_scm.CaptureSVN = CaptureSVNMock | 1173 gclient_scm.CaptureSVN = CaptureSVNMock |
| 1158 info = gclient_scm.CaptureSVNStatus(None) | 1174 info = gclient_scm.CaptureSVNStatus(None) |
| 1159 self.assertEquals(info, []) | 1175 self.assertEquals(info, []) |
| 1160 | 1176 |
| 1161 | 1177 |
| 1162 if __name__ == '__main__': | 1178 if __name__ == '__main__': |
| 1163 unittest.main() | 1179 unittest.main() |
| 1164 | 1180 |
| 1165 # vim: ts=2:sw=2:tw=80:et: | 1181 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |