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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 """Verifies that dependencies are processed in the right order. | 79 """Verifies that dependencies are processed in the right order. |
80 | 80 |
81 e.g. if there is a dependency 'src' and another 'src/third_party/bar', that | 81 e.g. if there is a dependency 'src' and another 'src/third_party/bar', that |
82 bar isn't fetched until 'src' is done. | 82 bar isn't fetched until 'src' is done. |
83 Also test that a From() dependency should not be processed when it is listed | 83 Also test that a From() dependency should not be processed when it is listed |
84 as a requirement. | 84 as a requirement. |
85 | 85 |
86 Args: | 86 Args: |
87 |jobs| is the number of parallel jobs simulated. | 87 |jobs| is the number of parallel jobs simulated. |
88 """ | 88 """ |
89 parser = gclient.OptionParser() | 89 parser = gclient.Parser() |
90 options, args = parser.parse_args(['--jobs', jobs]) | 90 options, args = parser.parse_args(['--jobs', jobs]) |
91 write( | 91 write( |
92 '.gclient', | 92 '.gclient', |
93 'solutions = [\n' | 93 'solutions = [\n' |
94 ' { "name": "foo", "url": "svn://example.com/foo" },\n' | 94 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
95 ' { "name": "bar", "url": "svn://example.com/bar" },\n' | 95 ' { "name": "bar", "url": "svn://example.com/bar" },\n' |
96 ' { "name": "bar/empty", "url": "svn://example.com/bar_empty" },\n' | 96 ' { "name": "bar/empty", "url": "svn://example.com/bar_empty" },\n' |
97 ']') | 97 ']') |
98 write( | 98 write( |
99 os.path.join('foo', 'DEPS'), | 99 os.path.join('foo', 'DEPS'), |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, 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.OptionParser() | 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, 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, None, 'DEPS', True), | 224 obj, 'bar', 'url', None, None, None, None, None, 'DEPS', True), |
225 ], | 225 ], |
226 []) | 226 []) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}] | 258 hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}] |
259 print >> fh, 'hooks = %s' % repr(hooks) | 259 print >> fh, 'hooks = %s' % repr(hooks) |
260 fh.close() | 260 fh.close() |
261 | 261 |
262 fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w') | 262 fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w') |
263 print >> fh, 'bogus content' | 263 print >> fh, 'bogus content' |
264 fh.close() | 264 fh.close() |
265 | 265 |
266 os.chdir(topdir) | 266 os.chdir(topdir) |
267 | 267 |
268 parser = gclient.OptionParser() | 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): | 278 def testCustomHooks(self): |
(...skipping 28 matching lines...) Expand all Loading... |
307 {'name': 'skip', 'pattern':'.', 'action':['response2', 'yes', 'sir']}) | 307 {'name': 'skip', 'pattern':'.', 'action':['response2', 'yes', 'sir']}) |
308 print >> fh, 'hooks = %s' % repr(sub_hooks) | 308 print >> fh, 'hooks = %s' % repr(sub_hooks) |
309 fh.close() | 309 fh.close() |
310 | 310 |
311 fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w') | 311 fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w') |
312 print >> fh, 'bogus content' | 312 print >> fh, 'bogus content' |
313 fh.close() | 313 fh.close() |
314 | 314 |
315 os.chdir(topdir) | 315 os.chdir(topdir) |
316 | 316 |
317 parser = gclient.OptionParser() | 317 parser = gclient.Parser() |
318 options, _ = parser.parse_args([]) | 318 options, _ = parser.parse_args([]) |
319 options.force = True | 319 options.force = True |
320 client = gclient.GClient.LoadCurrentConfig(options) | 320 client = gclient.GClient.LoadCurrentConfig(options) |
321 work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False) | 321 work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False) |
322 for s in client.dependencies: | 322 for s in client.dependencies: |
323 work_queue.enqueue(s) | 323 work_queue.enqueue(s) |
324 work_queue.flush({}, None, [], options=options) | 324 work_queue.flush({}, None, [], options=options) |
325 self.assertEqual(client.GetHooks(options), | 325 self.assertEqual(client.GetHooks(options), |
326 [x['action'] for x in hooks + extra_hooks + sub_hooks]) | 326 [x['action'] for x in hooks + extra_hooks + sub_hooks]) |
327 | 327 |
(...skipping 15 matching lines...) Expand all Loading... |
343 write( | 343 write( |
344 os.path.join('foo', 'DEPS'), | 344 os.path.join('foo', 'DEPS'), |
345 'deps = {\n' | 345 'deps = {\n' |
346 ' "foo/dir1": "/dir1",' | 346 ' "foo/dir1": "/dir1",' |
347 '}\n' | 347 '}\n' |
348 'deps_os = {\n' | 348 'deps_os = {\n' |
349 ' "unix": { "foo/dir2": "/dir2", },\n' | 349 ' "unix": { "foo/dir2": "/dir2", },\n' |
350 ' "baz": { "foo/dir3": "/dir3", },\n' | 350 ' "baz": { "foo/dir3": "/dir3", },\n' |
351 '}') | 351 '}') |
352 | 352 |
353 parser = gclient.OptionParser() | 353 parser = gclient.Parser() |
354 options, _ = parser.parse_args(['--jobs', '1']) | 354 options, _ = parser.parse_args(['--jobs', '1']) |
355 options.deps_os = "unix" | 355 options.deps_os = "unix" |
356 | 356 |
357 obj = gclient.GClient.LoadCurrentConfig(options) | 357 obj = gclient.GClient.LoadCurrentConfig(options) |
358 self.assertEqual(['baz', 'unix'], sorted(obj.enforced_os)) | 358 self.assertEqual(['baz', 'unix'], sorted(obj.enforced_os)) |
359 | 359 |
360 def testTargetOsWithTargetOsOnly(self): | 360 def testTargetOsWithTargetOsOnly(self): |
361 """Verifies that specifying a target_os and target_os_only pulls in only | 361 """Verifies that specifying a target_os and target_os_only pulls in only |
362 the relevant dependencies. | 362 the relevant dependencies. |
363 | 363 |
(...skipping 14 matching lines...) Expand all Loading... |
378 write( | 378 write( |
379 os.path.join('foo', 'DEPS'), | 379 os.path.join('foo', 'DEPS'), |
380 'deps = {\n' | 380 'deps = {\n' |
381 ' "foo/dir1": "/dir1",' | 381 ' "foo/dir1": "/dir1",' |
382 '}\n' | 382 '}\n' |
383 'deps_os = {\n' | 383 'deps_os = {\n' |
384 ' "unix": { "foo/dir2": "/dir2", },\n' | 384 ' "unix": { "foo/dir2": "/dir2", },\n' |
385 ' "baz": { "foo/dir3": "/dir3", },\n' | 385 ' "baz": { "foo/dir3": "/dir3", },\n' |
386 '}') | 386 '}') |
387 | 387 |
388 parser = gclient.OptionParser() | 388 parser = gclient.Parser() |
389 options, _ = parser.parse_args(['--jobs', '1']) | 389 options, _ = parser.parse_args(['--jobs', '1']) |
390 options.deps_os = "unix" | 390 options.deps_os = "unix" |
391 | 391 |
392 obj = gclient.GClient.LoadCurrentConfig(options) | 392 obj = gclient.GClient.LoadCurrentConfig(options) |
393 self.assertEqual(['baz'], sorted(obj.enforced_os)) | 393 self.assertEqual(['baz'], sorted(obj.enforced_os)) |
394 | 394 |
395 def testTargetOsOnlyWithoutTargetOs(self): | 395 def testTargetOsOnlyWithoutTargetOs(self): |
396 """Verifies that specifying a target_os_only without target_os_only raises | 396 """Verifies that specifying a target_os_only without target_os_only raises |
397 an exception. | 397 an exception. |
398 """ | 398 """ |
399 | 399 |
400 write( | 400 write( |
401 '.gclient', | 401 '.gclient', |
402 'solutions = [\n' | 402 'solutions = [\n' |
403 ' { "name": "foo",\n' | 403 ' { "name": "foo",\n' |
404 ' "url": "svn://example.com/foo",\n' | 404 ' "url": "svn://example.com/foo",\n' |
405 ' }]\n' | 405 ' }]\n' |
406 'target_os_only = True') | 406 'target_os_only = True') |
407 write( | 407 write( |
408 os.path.join('foo', 'DEPS'), | 408 os.path.join('foo', 'DEPS'), |
409 'deps = {\n' | 409 'deps = {\n' |
410 ' "foo/dir1": "/dir1",' | 410 ' "foo/dir1": "/dir1",' |
411 '}\n' | 411 '}\n' |
412 'deps_os = {\n' | 412 'deps_os = {\n' |
413 ' "unix": { "foo/dir2": "/dir2", },\n' | 413 ' "unix": { "foo/dir2": "/dir2", },\n' |
414 '}') | 414 '}') |
415 | 415 |
416 parser = gclient.OptionParser() | 416 parser = gclient.Parser() |
417 options, _ = parser.parse_args(['--jobs', '1']) | 417 options, _ = parser.parse_args(['--jobs', '1']) |
418 options.deps_os = "unix" | 418 options.deps_os = "unix" |
419 | 419 |
420 exception_raised = False | 420 exception_raised = False |
421 try: | 421 try: |
422 gclient.GClient.LoadCurrentConfig(options) | 422 gclient.GClient.LoadCurrentConfig(options) |
423 except gclient_utils.Error: | 423 except gclient_utils.Error: |
424 exception_raised = True | 424 exception_raised = True |
425 self.assertTrue(exception_raised) | 425 self.assertTrue(exception_raised) |
426 | 426 |
(...skipping 24 matching lines...) Expand all Loading... |
451 ' "jaz": { "foo/jaz": "/jaz", },\n' | 451 ' "jaz": { "foo/jaz": "/jaz", },\n' |
452 '}') | 452 '}') |
453 write( | 453 write( |
454 os.path.join('bar', 'DEPS'), | 454 os.path.join('bar', 'DEPS'), |
455 'deps_os = {\n' | 455 'deps_os = {\n' |
456 ' "unix": { "bar/unix": "/unix", },\n' | 456 ' "unix": { "bar/unix": "/unix", },\n' |
457 ' "baz": { "bar/baz": "/baz", },\n' | 457 ' "baz": { "bar/baz": "/baz", },\n' |
458 ' "jaz": { "bar/jaz": "/jaz", },\n' | 458 ' "jaz": { "bar/jaz": "/jaz", },\n' |
459 '}') | 459 '}') |
460 | 460 |
461 parser = gclient.OptionParser() | 461 parser = gclient.Parser() |
462 options, _ = parser.parse_args(['--jobs', '1']) | 462 options, _ = parser.parse_args(['--jobs', '1']) |
463 options.deps_os = 'unix' | 463 options.deps_os = 'unix' |
464 | 464 |
465 obj = gclient.GClient.LoadCurrentConfig(options) | 465 obj = gclient.GClient.LoadCurrentConfig(options) |
466 obj.RunOnDeps('None', []) | 466 obj.RunOnDeps('None', []) |
467 self.assertEqual(['unix'], sorted(obj.enforced_os)) | 467 self.assertEqual(['unix'], sorted(obj.enforced_os)) |
468 self.assertEquals( | 468 self.assertEquals( |
469 [ | 469 [ |
470 'svn://example.com/bar', | 470 'svn://example.com/bar', |
471 'svn://example.com/bar/unix', | 471 'svn://example.com/bar/unix', |
(...skipping 20 matching lines...) Expand all Loading... |
492 ' "foo/src": "/src",\n' # This path is to be overridden by similar path | 492 ' "foo/src": "/src",\n' # This path is to be overridden by similar path |
493 # in deps_os['unix']. | 493 # in deps_os['unix']. |
494 '}\n' | 494 '}\n' |
495 'deps_os = {\n' | 495 'deps_os = {\n' |
496 ' "unix": { "foo/unix": "/unix",' | 496 ' "unix": { "foo/unix": "/unix",' |
497 ' "foo/src": "/src_unix"},\n' | 497 ' "foo/src": "/src_unix"},\n' |
498 ' "baz": { "foo/baz": "/baz", },\n' | 498 ' "baz": { "foo/baz": "/baz", },\n' |
499 ' "jaz": { "foo/jaz": "/jaz", },\n' | 499 ' "jaz": { "foo/jaz": "/jaz", },\n' |
500 '}') | 500 '}') |
501 | 501 |
502 parser = gclient.OptionParser() | 502 parser = gclient.Parser() |
503 options, _ = parser.parse_args(['--jobs', '1']) | 503 options, _ = parser.parse_args(['--jobs', '1']) |
504 options.deps_os = 'unix' | 504 options.deps_os = 'unix' |
505 | 505 |
506 obj = gclient.GClient.LoadCurrentConfig(options) | 506 obj = gclient.GClient.LoadCurrentConfig(options) |
507 obj.RunOnDeps('None', []) | 507 obj.RunOnDeps('None', []) |
508 self.assertEqual(['unix'], sorted(obj.enforced_os)) | 508 self.assertEqual(['unix'], sorted(obj.enforced_os)) |
509 self.assertEquals( | 509 self.assertEquals( |
510 [ | 510 [ |
511 'svn://example.com/foo', | 511 'svn://example.com/foo', |
512 'svn://example.com/foo/baz', | 512 'svn://example.com/foo/baz', |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 os.path.join('baz', 'DEPS'), | 545 os.path.join('baz', 'DEPS'), |
546 'deps = {\n' | 546 'deps = {\n' |
547 ' "fizz": "/fizz",\n' | 547 ' "fizz": "/fizz",\n' |
548 '}') | 548 '}') |
549 write( | 549 write( |
550 os.path.join('fizz', 'DEPS'), | 550 os.path.join('fizz', 'DEPS'), |
551 'deps = {\n' | 551 'deps = {\n' |
552 ' "fuzz": "/fuzz",\n' | 552 ' "fuzz": "/fuzz",\n' |
553 '}') | 553 '}') |
554 | 554 |
555 options, _ = gclient.OptionParser().parse_args([]) | 555 options, _ = gclient.Parser().parse_args([]) |
556 obj = gclient.GClient.LoadCurrentConfig(options) | 556 obj = gclient.GClient.LoadCurrentConfig(options) |
557 obj.RunOnDeps('None', []) | 557 obj.RunOnDeps('None', []) |
558 self.assertEquals( | 558 self.assertEquals( |
559 [ | 559 [ |
560 'svn://example.com/foo', | 560 'svn://example.com/foo', |
561 'svn://example.com/bar', | 561 'svn://example.com/bar', |
562 'svn://example.com/foo/bar', | 562 'svn://example.com/foo/bar', |
563 'svn://example.com/foo/bar/baz', | 563 'svn://example.com/foo/bar/baz', |
564 'svn://example.com/foo/bar/baz/fizz', | 564 'svn://example.com/foo/bar/baz/fizz', |
565 ], | 565 ], |
566 self._get_processed()) | 566 self._get_processed()) |
567 | 567 |
568 | 568 |
569 if __name__ == '__main__': | 569 if __name__ == '__main__': |
570 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 570 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
571 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 571 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
572 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 572 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
573 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 573 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
574 logging.basicConfig( | 574 logging.basicConfig( |
575 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 575 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
576 min(sys.argv.count('-v'), 3)], | 576 min(sys.argv.count('-v'), 3)], |
577 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 577 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
578 '%(lineno)d) %(message)s') | 578 '%(lineno)d) %(message)s') |
579 unittest.main() | 579 unittest.main() |
OLD | NEW |