| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 See gclient_smoketest.py for integration tests. | 8 See gclient_smoketest.py for integration tests. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 self.unit_test = unit_test | 37 self.unit_test = unit_test |
| 38 self.url = url | 38 self.url = url |
| 39 | 39 |
| 40 def RunCommand(self, command, options, args, file_list): | 40 def RunCommand(self, command, options, args, file_list): |
| 41 self.unit_test.assertEquals('None', command) | 41 self.unit_test.assertEquals('None', command) |
| 42 self.unit_test.processed.put(self.url) | 42 self.unit_test.processed.put(self.url) |
| 43 | 43 |
| 44 def FullUrlForRelativeUrl(self, url): | 44 def FullUrlForRelativeUrl(self, url): |
| 45 return self.url + url | 45 return self.url + url |
| 46 | 46 |
| 47 # pylint: disable=R0201 |
| 48 def DoesRemoteURLMatch(self): |
| 49 return True |
| 50 |
| 51 def GetActualRemoteURL(self): |
| 52 return self.url |
| 53 |
| 47 | 54 |
| 48 class GclientTest(trial_dir.TestCase): | 55 class GclientTest(trial_dir.TestCase): |
| 49 def setUp(self): | 56 def setUp(self): |
| 50 super(GclientTest, self).setUp() | 57 super(GclientTest, self).setUp() |
| 51 self.processed = Queue.Queue() | 58 self.processed = Queue.Queue() |
| 52 self.previous_dir = os.getcwd() | 59 self.previous_dir = os.getcwd() |
| 53 os.chdir(self.root_dir) | 60 os.chdir(self.root_dir) |
| 54 # Manual mocks. | 61 # Manual mocks. |
| 55 self._old_createscm = gclient.gclient_scm.CreateSCM | 62 self._old_createscm = gclient.gclient_scm.CreateSCM |
| 56 gclient.gclient_scm.CreateSCM = self._createscm | 63 gclient.gclient_scm.CreateSCM = self._createscm |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 # Make sure __str__() works fine. | 250 # Make sure __str__() works fine. |
| 244 # pylint: disable=W0212 | 251 # pylint: disable=W0212 |
| 245 obj.dependencies[0]._file_list.append('foo') | 252 obj.dependencies[0]._file_list.append('foo') |
| 246 str_obj = str(obj) | 253 str_obj = str(obj) |
| 247 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) | 254 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) |
| 248 | 255 |
| 249 def testHooks(self): | 256 def testHooks(self): |
| 250 topdir = self.root_dir | 257 topdir = self.root_dir |
| 251 gclient_fn = os.path.join(topdir, '.gclient') | 258 gclient_fn = os.path.join(topdir, '.gclient') |
| 252 fh = open(gclient_fn, 'w') | 259 fh = open(gclient_fn, 'w') |
| 253 print >> fh, 'solutions = [{"name":"top","url":"svn://svn.top.com/top"}]' | 260 print >> fh, 'solutions = [{"name":"top","url":"svn://example.com/top"}]' |
| 254 fh.close() | 261 fh.close() |
| 255 subdir_fn = os.path.join(topdir, 'top') | 262 subdir_fn = os.path.join(topdir, 'top') |
| 256 os.mkdir(subdir_fn) | 263 os.mkdir(subdir_fn) |
| 257 deps_fn = os.path.join(subdir_fn, 'DEPS') | 264 deps_fn = os.path.join(subdir_fn, 'DEPS') |
| 258 fh = open(deps_fn, 'w') | 265 fh = open(deps_fn, 'w') |
| 259 hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}] | 266 hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}] |
| 260 print >> fh, 'hooks = %s' % repr(hooks) | 267 print >> fh, 'hooks = %s' % repr(hooks) |
| 261 fh.close() | 268 fh.close() |
| 262 | 269 |
| 263 fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w') | 270 fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w') |
| (...skipping 10 matching lines...) Expand all Loading... |
| 274 for s in client.dependencies: | 281 for s in client.dependencies: |
| 275 work_queue.enqueue(s) | 282 work_queue.enqueue(s) |
| 276 work_queue.flush({}, None, [], options=options) | 283 work_queue.flush({}, None, [], options=options) |
| 277 self.assertEqual(client.GetHooks(options), [x['action'] for x in hooks]) | 284 self.assertEqual(client.GetHooks(options), [x['action'] for x in hooks]) |
| 278 | 285 |
| 279 def testCustomHooks(self): | 286 def testCustomHooks(self): |
| 280 topdir = self.root_dir | 287 topdir = self.root_dir |
| 281 gclient_fn = os.path.join(topdir, '.gclient') | 288 gclient_fn = os.path.join(topdir, '.gclient') |
| 282 fh = open(gclient_fn, 'w') | 289 fh = open(gclient_fn, 'w') |
| 283 extra_hooks = [{'name': 'append', 'pattern':'.', 'action':['supercmd']}] | 290 extra_hooks = [{'name': 'append', 'pattern':'.', 'action':['supercmd']}] |
| 284 print >> fh, ('solutions = [{"name":"top","url":"svn://svn.top.com/top",' | 291 print >> fh, ('solutions = [{"name":"top","url":"svn://example.com/top",' |
| 285 '"custom_hooks": %s},' ) % repr(extra_hooks + [{'name': 'skip'}]) | 292 '"custom_hooks": %s},' ) % repr(extra_hooks + [{'name': 'skip'}]) |
| 286 print >> fh, '{"name":"bottom","url":"svn://svn.top.com/bottom"}]' | 293 print >> fh, '{"name":"bottom","url":"svn://example.com/bottom"}]' |
| 287 fh.close() | 294 fh.close() |
| 288 subdir_fn = os.path.join(topdir, 'top') | 295 subdir_fn = os.path.join(topdir, 'top') |
| 289 os.mkdir(subdir_fn) | 296 os.mkdir(subdir_fn) |
| 290 deps_fn = os.path.join(subdir_fn, 'DEPS') | 297 deps_fn = os.path.join(subdir_fn, 'DEPS') |
| 291 fh = open(deps_fn, 'w') | 298 fh = open(deps_fn, 'w') |
| 292 hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}] | 299 hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}] |
| 293 hooks.append({'pattern':'.', 'action':['cmd2', 'arg1', 'arg2']}) | 300 hooks.append({'pattern':'.', 'action':['cmd2', 'arg1', 'arg2']}) |
| 294 skip_hooks = [ | 301 skip_hooks = [ |
| 295 {'name': 'skip', 'pattern':'.', 'action':['cmd3', 'arg1', 'arg2']}] | 302 {'name': 'skip', 'pattern':'.', 'action':['cmd3', 'arg1', 'arg2']}] |
| 296 skip_hooks.append( | 303 skip_hooks.append( |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 656 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
| 650 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 657 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
| 651 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 658 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
| 652 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 659 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
| 653 logging.basicConfig( | 660 logging.basicConfig( |
| 654 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 661 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
| 655 min(sys.argv.count('-v'), 3)], | 662 min(sys.argv.count('-v'), 3)], |
| 656 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 663 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
| 657 '%(lineno)d) %(message)s') | 664 '%(lineno)d) %(message)s') |
| 658 unittest.main() | 665 unittest.main() |
| OLD | NEW |