Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 import StringIO | 24 import StringIO |
| 25 import unittest | 25 import unittest |
| 26 | 26 |
| 27 import gclient | 27 import gclient |
| 28 import gclient_scm | 28 import gclient_scm |
| 29 import gclient_utils | 29 import gclient_utils |
| 30 import super_mox | 30 import super_mox |
| 31 from super_mox import mox | 31 from super_mox import mox |
| 32 | 32 |
| 33 | 33 |
| 34 class IsOneOf(mox.Comparator): | |
| 35 def __init__(self, keys): | |
| 36 self._keys = keys | |
| 37 | |
| 38 def equals(self, rhs): | |
| 39 return rhs in self._keys | |
| 40 | |
| 41 def __repr__(self): | |
| 42 return '<sequence or map containing \'%s\'>' % str(self._keys) | |
|
Mandeep Singh Baines
2009/10/09 22:28:35
An alternative might be to strip white-space and t
| |
| 43 | |
| 44 | |
| 34 class BaseTestCase(super_mox.SuperMoxTestBase): | 45 class BaseTestCase(super_mox.SuperMoxTestBase): |
| 35 def setUp(self): | 46 def setUp(self): |
| 36 super_mox.SuperMoxTestBase.setUp(self) | 47 super_mox.SuperMoxTestBase.setUp(self) |
| 37 | 48 |
| 38 # Like unittest's assertRaises, but checks for Gclient.Error. | 49 # Like unittest's assertRaises, but checks for Gclient.Error. |
| 39 def assertRaisesError(self, msg, fn, *args, **kwargs): | 50 def assertRaisesError(self, msg, fn, *args, **kwargs): |
| 40 try: | 51 try: |
| 41 fn(*args, **kwargs) | 52 fn(*args, **kwargs) |
| 42 except gclient.Error, e: | 53 except gclient.Error, e: |
| 43 self.assertEquals(e.args[0], msg) | 54 self.assertEquals(e.args[0], msg) |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 def testRunOnDepsNoDeps(self): | 397 def testRunOnDepsNoDeps(self): |
| 387 solution_name = 'testRunOnDepsNoDeps_solution_name' | 398 solution_name = 'testRunOnDepsNoDeps_solution_name' |
| 388 gclient_config = ( | 399 gclient_config = ( |
| 389 "solutions = [ {\n" | 400 "solutions = [ {\n" |
| 390 " 'name': '%s',\n" | 401 " 'name': '%s',\n" |
| 391 " 'url': '%s',\n" | 402 " 'url': '%s',\n" |
| 392 " 'custom_deps': {},\n" | 403 " 'custom_deps': {},\n" |
| 393 "} ]\n" | 404 "} ]\n" |
| 394 ) % (solution_name, self.url) | 405 ) % (solution_name, self.url) |
| 395 | 406 |
| 396 entries_content = ( | 407 # pprint.pformat() is non-deterministic in this case!! |
| 408 entries_content1 = ( | |
| 397 "entries = \\\n" | 409 "entries = \\\n" |
| 398 "{ '%s': '%s'}\n" | 410 "{ '%s': '%s'}\n" |
| 399 ) % (solution_name, self.url) | 411 ) % (solution_name, self.url) |
| 412 entries_content2 = ( | |
| 413 "entries = \\\n" | |
| 414 "{'%s': '%s'}\n" | |
| 415 ) % (solution_name, self.url) | |
| 400 | 416 |
| 401 options = self.Options() | 417 options = self.Options() |
| 402 | 418 |
| 403 checkout_path = os.path.join(self.root_dir, solution_name) | 419 checkout_path = os.path.join(self.root_dir, solution_name) |
| 404 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False) | 420 gclient.os.path.exists(os.path.join(checkout_path, '.git')).AndReturn(False) |
| 405 # Expect a check for the entries file and we say there is not one. | 421 # Expect a check for the entries file and we say there is not one. |
| 406 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) | 422 gclient.os.path.exists(os.path.join(self.root_dir, options.entries_filename) |
| 407 ).AndReturn(False) | 423 ).AndReturn(False) |
| 408 | 424 |
| 409 # An scm will be requested for the solution. | 425 # An scm will be requested for the solution. |
| 410 scm_wrapper_sol = self.mox.CreateMockAnything() | 426 scm_wrapper_sol = self.mox.CreateMockAnything() |
| 411 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name | 427 gclient_scm.CreateSCM(self.url, self.root_dir, solution_name |
| 412 ).AndReturn(scm_wrapper_sol) | 428 ).AndReturn(scm_wrapper_sol) |
| 413 # Then an update will be performed. | 429 # Then an update will be performed. |
| 414 scm_wrapper_sol.RunCommand('update', options, self.args, []) | 430 scm_wrapper_sol.RunCommand('update', options, self.args, []) |
| 415 # Then an attempt will be made to read its DEPS file. | 431 # Then an attempt will be made to read its DEPS file. |
| 416 gclient.FileRead(os.path.join(self.root_dir, | 432 gclient.FileRead(os.path.join(self.root_dir, |
| 417 solution_name, | 433 solution_name, |
| 418 options.deps_file)).AndRaise(IOError(2, 'No DEPS file')) | 434 options.deps_file)).AndRaise(IOError(2, 'No DEPS file')) |
| 419 | 435 |
| 420 # After everything is done, an attempt is made to write an entries | 436 # After everything is done, an attempt is made to write an entries |
| 421 # file. | 437 # file. |
| 422 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), | 438 gclient.FileWrite(os.path.join(self.root_dir, options.entries_filename), |
| 423 entries_content) | 439 IsOneOf((entries_content1, entries_content2))) |
| 424 | 440 |
| 425 self.mox.ReplayAll() | 441 self.mox.ReplayAll() |
| 426 client = self._gclient_gclient(self.root_dir, options) | 442 client = self._gclient_gclient(self.root_dir, options) |
| 427 client.SetConfig(gclient_config) | 443 client.SetConfig(gclient_config) |
| 428 client.RunOnDeps('update', self.args) | 444 client.RunOnDeps('update', self.args) |
| 429 | 445 |
| 430 def testRunOnDepsRelativePaths(self): | 446 def testRunOnDepsRelativePaths(self): |
| 431 solution_name = 'testRunOnDepsRelativePaths_solution_name' | 447 solution_name = 'testRunOnDepsRelativePaths_solution_name' |
| 432 gclient_config = ( | 448 gclient_config = ( |
| 433 "solutions = [ {\n" | 449 "solutions = [ {\n" |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1139 """ | 1155 """ |
| 1140 gclient_scm.CaptureSVN = CaptureSVNMock | 1156 gclient_scm.CaptureSVN = CaptureSVNMock |
| 1141 info = gclient_scm.CaptureSVNStatus(None) | 1157 info = gclient_scm.CaptureSVNStatus(None) |
| 1142 self.assertEquals(info, []) | 1158 self.assertEquals(info, []) |
| 1143 | 1159 |
| 1144 | 1160 |
| 1145 if __name__ == '__main__': | 1161 if __name__ == '__main__': |
| 1146 unittest.main() | 1162 unittest.main() |
| 1147 | 1163 |
| 1148 # vim: ts=2:sw=2:tw=80:et: | 1164 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |