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

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, 5 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
« no previous file with comments | « 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 print >> fh, '{"name":"bottom","url":"svn://svn.top.com/bottom"}]'
286 fh.close()
287 subdir_fn = os.path.join(topdir, 'top')
288 os.mkdir(subdir_fn)
289 deps_fn = os.path.join(subdir_fn, 'DEPS')
290 fh = open(deps_fn, 'w')
291 hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}]
292 hooks.append({'pattern':'.', 'action':['cmd2', 'arg1', 'arg2']})
293 skip_hooks = [
294 {'name': 'skip', 'pattern':'.', 'action':['cmd3', 'arg1', 'arg2']}]
295 skip_hooks.append(
296 {'name': 'skip', 'pattern':'.', 'action':['cmd4', 'arg1', 'arg2']})
297 print >> fh, 'hooks = %s' % repr(hooks + skip_hooks)
298 fh.close()
299
300 # Make sure the custom hooks for that project don't affect the next one.
301 subdir_fn = os.path.join(topdir, 'bottom')
302 os.mkdir(subdir_fn)
303 deps_fn = os.path.join(subdir_fn, 'DEPS')
304 fh = open(deps_fn, 'w')
305 sub_hooks = [{'pattern':'.', 'action':['response1', 'yes1', 'yes2']}]
306 sub_hooks.append(
307 {'name': 'skip', 'pattern':'.', 'action':['response2', 'yes', 'sir']})
308 print >> fh, 'hooks = %s' % repr(sub_hooks)
309 fh.close()
310
311 fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w')
312 print >> fh, 'bogus content'
313 fh.close()
314
315 os.chdir(topdir)
316
317 parser = gclient.Parser()
318 options, _ = parser.parse_args([])
319 options.force = True
320 client = gclient.GClient.LoadCurrentConfig(options)
321 work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False)
322 for s in client.dependencies:
323 work_queue.enqueue(s)
324 work_queue.flush({}, None, [], options=options)
325 self.assertEqual(client.GetHooks(options),
326 [x['action'] for x in hooks + extra_hooks + sub_hooks])
327
278 def testTargetOS(self): 328 def testTargetOS(self):
279 """Verifies that specifying a target_os pulls in all relevant dependencies. 329 """Verifies that specifying a target_os pulls in all relevant dependencies.
280 330
281 The target_os variable allows specifying the name of an additional OS which 331 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 332 should be considered when selecting dependencies from a DEPS' deps_os. The
283 value will be appended to the _enforced_os tuple. 333 value will be appended to the _enforced_os tuple.
284 """ 334 """
285 335
286 write( 336 write(
287 '.gclient', 337 '.gclient',
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) 570 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
521 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) 571 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True)
522 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) 572 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr)
523 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) 573 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True)
524 logging.basicConfig( 574 logging.basicConfig(
525 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ 575 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][
526 min(sys.argv.count('-v'), 3)], 576 min(sys.argv.count('-v'), 3)],
527 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' 577 format='%(relativeCreated)4d %(levelname)5s %(module)13s('
528 '%(lineno)d) %(message)s') 578 '%(lineno)d) %(message)s')
529 unittest.main() 579 unittest.main()
OLDNEW
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698