| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for gclient.py.""" | 6 """Unit tests for gclient.py.""" |
| 7 | 7 |
| 8 # Fixes include path. | 8 # Fixes include path. |
| 9 from super_mox import mox, IsOneOf, SuperMoxTestBase | 9 from super_mox import mox, SuperMoxTestBase |
| 10 | 10 |
| 11 import gclient | 11 import gclient |
| 12 | 12 |
| 13 | 13 |
| 14 class BaseTestCase(SuperMoxTestBase): | 14 class BaseTestCase(SuperMoxTestBase): |
| 15 # Like unittest's assertRaises, but checks for Gclient.Error. | 15 # Like unittest's assertRaises, but checks for Gclient.Error. |
| 16 def assertRaisesError(self, msg, fn, *args, **kwargs): | 16 def assertRaisesError(self, msg, fn, *args, **kwargs): |
| 17 try: | 17 try: |
| 18 fn(*args, **kwargs) | 18 fn(*args, **kwargs) |
| 19 except gclient.gclient_utils.Error, e: | 19 except gclient.gclient_utils.Error, e: |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 solution_name = 'testRunOnDepsNoDeps_solution_name' | 357 solution_name = 'testRunOnDepsNoDeps_solution_name' |
| 358 gclient_config = ( | 358 gclient_config = ( |
| 359 "solutions = [ {\n" | 359 "solutions = [ {\n" |
| 360 " 'name': '%s',\n" | 360 " 'name': '%s',\n" |
| 361 " 'url': '%s',\n" | 361 " 'url': '%s',\n" |
| 362 " 'custom_deps': {},\n" | 362 " 'custom_deps': {},\n" |
| 363 "} ]\n" | 363 "} ]\n" |
| 364 ) % (solution_name, self.url) | 364 ) % (solution_name, self.url) |
| 365 | 365 |
| 366 # pprint.pformat() is non-deterministic in this case!! | 366 # pprint.pformat() is non-deterministic in this case!! |
| 367 entries_content1 = ( | 367 entries_content = ( |
| 368 "entries = \\\n" | 368 "entries = \\\n" |
| 369 "{ '%s': '%s'}\n" | 369 "{ '%s': '%s'}\n" |
| 370 ) % (solution_name, self.url) | 370 ) % (solution_name, self.url) |
| 371 entries_content2 = ( | |
| 372 "entries = \\\n" | |
| 373 "{'%s': '%s'}\n" | |
| 374 ) % (solution_name, self.url) | |
| 375 | 371 |
| 376 options = self.Options() | 372 options = self.Options() |
| 377 | 373 |
| 378 checkout_path = gclient.os.path.join(self.root_dir, solution_name) | 374 checkout_path = gclient.os.path.join(self.root_dir, solution_name) |
| 379 gclient.os.path.exists(gclient.os.path.join(checkout_path, '.git') | 375 gclient.os.path.exists(gclient.os.path.join(checkout_path, '.git') |
| 380 ).AndReturn(False) | 376 ).AndReturn(False) |
| 381 # Expect a check for the entries file and we say there is not one. | 377 # Expect a check for the entries file and we say there is not one. |
| 382 gclient.os.path.exists( | 378 gclient.os.path.exists( |
| 383 gclient.os.path.join(self.root_dir, options.entries_filename) | 379 gclient.os.path.join(self.root_dir, options.entries_filename) |
| 384 ).AndReturn(False) | 380 ).AndReturn(False) |
| 385 | 381 |
| 386 # An scm will be requested for the solution. | 382 # An scm will be requested for the solution. |
| 387 scm_wrapper_sol = self.mox.CreateMockAnything() | 383 scm_wrapper_sol = self.mox.CreateMockAnything() |
| 388 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, solution_name | 384 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, solution_name |
| 389 ).AndReturn(scm_wrapper_sol) | 385 ).AndReturn(scm_wrapper_sol) |
| 390 # Then an update will be performed. | 386 # Then an update will be performed. |
| 391 scm_wrapper_sol.RunCommand('update', options, self.args, []) | 387 scm_wrapper_sol.RunCommand('update', options, self.args, []) |
| 392 # Then an attempt will be made to read its DEPS file. | 388 # Then an attempt will be made to read its DEPS file. |
| 393 gclient.gclient_utils.FileRead( | 389 gclient.gclient_utils.FileRead( |
| 394 gclient.os.path.join(self.root_dir, solution_name, options.deps_file) | 390 gclient.os.path.join(self.root_dir, solution_name, options.deps_file) |
| 395 ).AndRaise(IOError(2, 'No DEPS file')) | 391 ).AndRaise(IOError(2, 'No DEPS file')) |
| 396 | 392 |
| 397 # After everything is done, an attempt is made to write an entries | 393 # After everything is done, an attempt is made to write an entries |
| 398 # file. | 394 # file. |
| 399 gclient.gclient_utils.FileWrite( | 395 gclient.gclient_utils.FileWrite( |
| 400 gclient.os.path.join(self.root_dir, options.entries_filename), | 396 gclient.os.path.join(self.root_dir, options.entries_filename), |
| 401 IsOneOf((entries_content1, entries_content2))) | 397 entries_content) |
| 402 | 398 |
| 403 self.mox.ReplayAll() | 399 self.mox.ReplayAll() |
| 404 client = self._gclient_gclient(self.root_dir, options) | 400 client = self._gclient_gclient(self.root_dir, options) |
| 405 client.SetConfig(gclient_config) | 401 client.SetConfig(gclient_config) |
| 406 client.RunOnDeps('update', self.args) | 402 client.RunOnDeps('update', self.args) |
| 407 | 403 |
| 408 def testRunOnDepsRelativePaths(self): | 404 def testRunOnDepsRelativePaths(self): |
| 409 solution_name = 'testRunOnDepsRelativePaths_solution_name' | 405 solution_name = 'testRunOnDepsRelativePaths_solution_name' |
| 410 gclient_config = ( | 406 gclient_config = ( |
| 411 "solutions = [ {\n" | 407 "solutions = [ {\n" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 def testRunOnDepsSuccess(self): | 646 def testRunOnDepsSuccess(self): |
| 651 # Fake .gclient file. | 647 # Fake .gclient file. |
| 652 name = 'testRunOnDepsSuccess_solution_name' | 648 name = 'testRunOnDepsSuccess_solution_name' |
| 653 gclient_config = """solutions = [ { | 649 gclient_config = """solutions = [ { |
| 654 'name': '%s', | 650 'name': '%s', |
| 655 'url': '%s', | 651 'url': '%s', |
| 656 'custom_deps': {}, | 652 'custom_deps': {}, |
| 657 }, ]""" % (name, self.url) | 653 }, ]""" % (name, self.url) |
| 658 | 654 |
| 659 # pprint.pformat() is non-deterministic in this case!! | 655 # pprint.pformat() is non-deterministic in this case!! |
| 660 entries_content1 = ( | 656 entries_content = ( |
| 661 "entries = \\\n" | 657 "entries = \\\n" |
| 662 "{ '%s': '%s'}\n" | 658 "{ '%s': '%s'}\n" |
| 663 ) % (name, self.url) | 659 ) % (name, self.url) |
| 664 entries_content2 = ( | |
| 665 "entries = \\\n" | |
| 666 "{'%s': '%s'}\n" | |
| 667 ) % (name, self.url) | |
| 668 | |
| 669 | 660 |
| 670 options = self.Options() | 661 options = self.Options() |
| 671 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git') | 662 gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git') |
| 672 ).AndReturn(False) | 663 ).AndReturn(False) |
| 673 gclient.os.path.exists( | 664 gclient.os.path.exists( |
| 674 gclient.os.path.join(self.root_dir, options.entries_filename) | 665 gclient.os.path.join(self.root_dir, options.entries_filename) |
| 675 ).AndReturn(False) | 666 ).AndReturn(False) |
| 676 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( | 667 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn( |
| 677 gclient.gclient_scm.CreateSCM) | 668 gclient.gclient_scm.CreateSCM) |
| 678 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) | 669 gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) |
| 679 gclient.gclient_utils.FileRead( | 670 gclient.gclient_utils.FileRead( |
| 680 gclient.os.path.join(self.root_dir, name, options.deps_file) | 671 gclient.os.path.join(self.root_dir, name, options.deps_file) |
| 681 ).AndReturn("Boo = 'a'") | 672 ).AndReturn("Boo = 'a'") |
| 682 gclient.gclient_utils.FileWrite( | 673 gclient.gclient_utils.FileWrite( |
| 683 gclient.os.path.join(self.root_dir, options.entries_filename), | 674 gclient.os.path.join(self.root_dir, options.entries_filename), |
| 684 IsOneOf((entries_content1, entries_content2))) | 675 entries_content) |
| 685 | 676 |
| 686 self.mox.ReplayAll() | 677 self.mox.ReplayAll() |
| 687 client = self._gclient_gclient(self.root_dir, options) | 678 client = self._gclient_gclient(self.root_dir, options) |
| 688 client.SetConfig(gclient_config) | 679 client.SetConfig(gclient_config) |
| 689 client.RunOnDeps('update', self.args) | 680 client.RunOnDeps('update', self.args) |
| 690 | 681 |
| 691 def testRunOnDepsRevisions(self): | 682 def testRunOnDepsRevisions(self): |
| 692 def OptIsRev(options, rev): | 683 def OptIsRev(options, rev): |
| 693 if not options.revision == str(rev): | 684 if not options.revision == str(rev): |
| 694 print("options.revision = %s" % options.revision) | 685 print("options.revision = %s" % options.revision) |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 gclient.os.path.join(self.root_dir, options.entries_filename) | 1049 gclient.os.path.join(self.root_dir, options.entries_filename) |
| 1059 ).AndReturn(False) | 1050 ).AndReturn(False) |
| 1060 | 1051 |
| 1061 # This is where gclient tries to do the initial checkout. | 1052 # This is where gclient tries to do the initial checkout. |
| 1062 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, target).AndReturn( | 1053 gclient.gclient_scm.CreateSCM(self.url, self.root_dir, target).AndReturn( |
| 1063 gclient.gclient_scm.CreateSCM) | 1054 gclient.gclient_scm.CreateSCM) |
| 1064 gclient.gclient_scm.CreateSCM.RunCommand('updatesingle', options, | 1055 gclient.gclient_scm.CreateSCM.RunCommand('updatesingle', options, |
| 1065 self.args + ["DEPS"], []) | 1056 self.args + ["DEPS"], []) |
| 1066 gclient.gclient_utils.FileWrite( | 1057 gclient.gclient_utils.FileWrite( |
| 1067 gclient.os.path.join(self.root_dir, options.entries_filename), | 1058 gclient.os.path.join(self.root_dir, options.entries_filename), |
| 1068 "entries = \\\n{'%s': '%s'}\n" % (name, self.url)) | 1059 "entries = \\\n{ '%s': '%s'}\n" % (name, self.url)) |
| 1069 | 1060 |
| 1070 self.mox.ReplayAll() | 1061 self.mox.ReplayAll() |
| 1071 client = self._gclient_gclient(self.root_dir, options) | 1062 client = self._gclient_gclient(self.root_dir, options) |
| 1072 client.SetConfig(gclient_config) | 1063 client.SetConfig(gclient_config) |
| 1073 client.RunOnDeps('update', self.args) | 1064 client.RunOnDeps('update', self.args) |
| 1074 | 1065 |
| 1075 def test_PrintRevInfo(self): | 1066 def test_PrintRevInfo(self): |
| 1076 # TODO(aharper): no test yet for revinfo, lock it down once we've verified | 1067 # TODO(aharper): no test yet for revinfo, lock it down once we've verified |
| 1077 # implementation for Pulse plugin | 1068 # implementation for Pulse plugin |
| 1078 pass | 1069 pass |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1090 pass | 1081 pass |
| 1091 def test_VarImpl(self): | 1082 def test_VarImpl(self): |
| 1092 pass | 1083 pass |
| 1093 | 1084 |
| 1094 | 1085 |
| 1095 if __name__ == '__main__': | 1086 if __name__ == '__main__': |
| 1096 import unittest | 1087 import unittest |
| 1097 unittest.main() | 1088 unittest.main() |
| 1098 | 1089 |
| 1099 # vim: ts=2:sw=2:tw=80:et: | 1090 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |