Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 |
| 11 from __future__ import with_statement | 11 from __future__ import with_statement |
| 12 import Queue | 12 import Queue |
| 13 import logging | 13 import logging |
| 14 import os | 14 import os |
| 15 import shutil | |
| 15 import sys | 16 import sys |
| 17 from tempfile import mkdtemp | |
| 16 import unittest | 18 import unittest |
| 17 | 19 |
| 18 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 20 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 19 | 21 |
| 20 import gclient | 22 import gclient |
| 21 import gclient_utils | 23 import gclient_utils |
| 22 from testing_support import trial_dir | 24 from testing_support import trial_dir |
| 23 | 25 |
| 24 | 26 |
| 25 def write(filename, content): | 27 def write(filename, content): |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, | 241 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, |
| 240 'DEPS', True), | 242 'DEPS', True), |
| 241 ], | 243 ], |
| 242 []) | 244 []) |
| 243 # Make sure __str__() works fine. | 245 # Make sure __str__() works fine. |
| 244 # pylint: disable=W0212 | 246 # pylint: disable=W0212 |
| 245 obj.dependencies[0]._file_list.append('foo') | 247 obj.dependencies[0]._file_list.append('foo') |
| 246 str_obj = str(obj) | 248 str_obj = str(obj) |
| 247 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) | 249 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) |
| 248 | 250 |
| 251 def testHooks(self): | |
|
M-A Ruel
2012/03/12 23:52:06
Use self.root_dir, trial_dir.TestCase already mana
szager
2012/03/13 00:00:18
Done.
| |
| 252 topdir = mkdtemp() | |
| 253 | |
| 254 gclient_fn = os.path.join(topdir, '.gclient') | |
| 255 fh = open(gclient_fn, 'w') | |
| 256 print >> fh, 'solutions = [{"name":"top","url":"svn://svn.top.com/top"}]' | |
| 257 fh.close() | |
| 258 subdir_fn = os.path.join(topdir, 'top') | |
| 259 os.mkdir(subdir_fn) | |
| 260 deps_fn = os.path.join(subdir_fn, 'DEPS') | |
| 261 fh = open(deps_fn, 'w') | |
| 262 hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}] | |
| 263 print >> fh, 'hooks = %s' % repr(hooks) | |
| 264 fh.close() | |
| 265 | |
| 266 fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w') | |
| 267 print >> fh, 'bogus content' | |
| 268 fh.close() | |
| 269 | |
| 270 os.chdir(topdir) | |
| 271 | |
| 272 parser = gclient.Parser() | |
| 273 options, _ = parser.parse_args([]) | |
| 274 options.force = True | |
| 275 client = gclient.GClient.LoadCurrentConfig(options) | |
| 276 work_queue = gclient_utils.ExecutionQueue(options.jobs, None) | |
| 277 for s in client.dependencies: | |
| 278 work_queue.enqueue(s) | |
| 279 work_queue.flush({}, None, [], options=options) | |
| 280 self.assertEqual(client.GetHooks(options), [x['action'] for x in hooks]) | |
| 281 | |
| 282 shutil.rmtree(topdir) | |
| 283 | |
| 249 | 284 |
| 250 if __name__ == '__main__': | 285 if __name__ == '__main__': |
| 251 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 286 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
| 252 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 287 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
| 253 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 288 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
| 254 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 289 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
| 255 logging.basicConfig( | 290 logging.basicConfig( |
| 256 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 291 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
| 257 min(sys.argv.count('-v'), 3)], | 292 min(sys.argv.count('-v'), 3)], |
| 258 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 293 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
| 259 '%(lineno)d) %(message)s') | 294 '%(lineno)d) %(message)s') |
| 260 unittest.main() | 295 unittest.main() |
| OLD | NEW |