Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/gclient_test.py

Issue 17742004: Add custom hooks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« gclient.py ('K') | « gclient.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 while True: 201 while True:
202 items.append(self.processed.get_nowait()) 202 items.append(self.processed.get_nowait())
203 except Queue.Empty: 203 except Queue.Empty:
204 pass 204 pass
205 return items 205 return items
206 206
207 def testAutofix(self): 207 def testAutofix(self):
208 # Invalid urls causes pain when specifying requirements. Make sure it's 208 # Invalid urls causes pain when specifying requirements. Make sure it's
209 # auto-fixed. 209 # auto-fixed.
210 d = gclient.Dependency( 210 d = gclient.Dependency(
211 None, 'name', 'proto://host/path/@revision', None, None, None, 211 None, 'name', 'proto://host/path/@revision', None, None, None, None,
212 None, '', True) 212 None, '', True)
213 self.assertEquals('proto://host/path@revision', d.url) 213 self.assertEquals('proto://host/path@revision', d.url)
214 214
215 def testStr(self): 215 def testStr(self):
216 parser = gclient.Parser() 216 parser = gclient.Parser()
217 options, _ = parser.parse_args([]) 217 options, _ = parser.parse_args([])
218 obj = gclient.GClient('foo', options) 218 obj = gclient.GClient('foo', options)
219 obj.add_dependencies_and_close( 219 obj.add_dependencies_and_close(
220 [ 220 [
221 gclient.Dependency( 221 gclient.Dependency(
222 obj, 'foo', 'url', None, None, None, None, 'DEPS', True), 222 obj, 'foo', 'url', None, None, None, None, None, 'DEPS', True),
223 gclient.Dependency( 223 gclient.Dependency(
224 obj, 'bar', 'url', None, None, None, None, 'DEPS', True), 224 obj, 'bar', 'url', None, None, None, None, None, 'DEPS', True),
225 ], 225 ],
226 []) 226 [])
227 obj.dependencies[0].add_dependencies_and_close( 227 obj.dependencies[0].add_dependencies_and_close(
228 [ 228 [
229 gclient.Dependency( 229 gclient.Dependency(
230 obj.dependencies[0], 'foo/dir1', 'url', None, None, None, None, 230 obj.dependencies[0], 'foo/dir1', 'url', None, None, None, None,
231 'DEPS', True), 231 None, 'DEPS', True),
232 gclient.Dependency( 232 gclient.Dependency(
233 obj.dependencies[0], 'foo/dir2', 233 obj.dependencies[0], 'foo/dir2',
234 gclient.GClientKeywords.FromImpl('bar'), None, None, None, None, 234 gclient.GClientKeywords.FromImpl('bar'), None, None, None, None,
235 'DEPS', True), 235 None, 'DEPS', True),
236 gclient.Dependency( 236 gclient.Dependency(
237 obj.dependencies[0], 'foo/dir3', 237 obj.dependencies[0], 'foo/dir3',
238 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, 238 gclient.GClientKeywords.FileImpl('url'), None, None, None, None,
239 'DEPS', True), 239 None, 'DEPS', True),
240 ], 240 ],
241 []) 241 [])
242 # Make sure __str__() works fine. 242 # Make sure __str__() works fine.
243 # pylint: disable=W0212 243 # pylint: disable=W0212
244 obj.dependencies[0]._file_list.append('foo') 244 obj.dependencies[0]._file_list.append('foo')
245 str_obj = str(obj) 245 str_obj = str(obj)
246 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) 246 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj))
247 247
248 def testHooks(self): 248 def testHooks(self):
249 topdir = self.root_dir 249 topdir = self.root_dir
(...skipping 18 matching lines...) Expand all
268 parser = gclient.Parser() 268 parser = gclient.Parser()
269 options, _ = parser.parse_args([]) 269 options, _ = parser.parse_args([])
270 options.force = True 270 options.force = True
271 client = gclient.GClient.LoadCurrentConfig(options) 271 client = gclient.GClient.LoadCurrentConfig(options)
272 work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False) 272 work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False)
273 for s in client.dependencies: 273 for s in client.dependencies:
274 work_queue.enqueue(s) 274 work_queue.enqueue(s)
275 work_queue.flush({}, None, [], options=options) 275 work_queue.flush({}, None, [], options=options)
276 self.assertEqual(client.GetHooks(options), [x['action'] for x in hooks]) 276 self.assertEqual(client.GetHooks(options), [x['action'] for x in hooks])
277 277
278 def testCustomHooks(self):
279 topdir = self.root_dir
280 gclient_fn = os.path.join(topdir, '.gclient')
281 fh = open(gclient_fn, 'w')
282 extra_hooks = [{'name': 'append', 'pattern':'.', 'action':['supercmd']}]
283 print >> fh, ('solutions = [{"name":"top","url":"svn://svn.top.com/top",'
284 '"custom_hooks": %s}]' ) % repr(extra_hooks + [{'name': 'skip'}])
285 fh.close()
286 subdir_fn = os.path.join(topdir, 'top')
287 os.mkdir(subdir_fn)
288 deps_fn = os.path.join(subdir_fn, 'DEPS')
289 fh = open(deps_fn, 'w')
290 hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}]
291 hooks.append({'pattern':'.', 'action':['cmd2', 'arg1', 'arg2']})
292 skip_hooks = [
293 {'name': 'skip', 'pattern':'.', 'action':['cmd3', 'arg1', 'arg2']}]
294 skip_hooks.append(
295 {'name': 'skip', 'pattern':'.', 'action':['cmd4', 'arg1', 'arg2']})
296 print >> fh, 'hooks = %s' % repr(hooks + skip_hooks)
297 fh.close()
298
299 fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w')
300 print >> fh, 'bogus content'
301 fh.close()
302
303 os.chdir(topdir)
304
305 parser = gclient.Parser()
306 options, _ = parser.parse_args([])
307 options.force = True
308 client = gclient.GClient.LoadCurrentConfig(options)
309 work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False)
310 for s in client.dependencies:
311 work_queue.enqueue(s)
312 work_queue.flush({}, None, [], options=options)
313 self.assertEqual(client.GetHooks(options),
314 [x['action'] for x in hooks + extra_hooks])
315
278 def testTargetOS(self): 316 def testTargetOS(self):
279 """Verifies that specifying a target_os pulls in all relevant dependencies. 317 """Verifies that specifying a target_os pulls in all relevant dependencies.
280 318
281 The target_os variable allows specifying the name of an additional OS which 319 The target_os variable allows specifying the name of an additional OS which
282 should be considered when selecting dependencies from a DEPS' deps_os. The 320 should be considered when selecting dependencies from a DEPS' deps_os. The
283 value will be appended to the _enforced_os tuple. 321 value will be appended to the _enforced_os tuple.
284 """ 322 """
285 323
286 write( 324 write(
287 '.gclient', 325 '.gclient',
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) 558 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
521 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) 559 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True)
522 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) 560 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr)
523 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) 561 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True)
524 logging.basicConfig( 562 logging.basicConfig(
525 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ 563 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][
526 min(sys.argv.count('-v'), 3)], 564 min(sys.argv.count('-v'), 3)],
527 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' 565 format='%(relativeCreated)4d %(levelname)5s %(module)13s('
528 '%(lineno)d) %(message)s') 566 '%(lineno)d) %(message)s')
529 unittest.main() 567 unittest.main()
OLDNEW
« gclient.py ('K') | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698