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 |
11 import Queue | 11 import Queue |
| 12 import copy |
12 import logging | 13 import logging |
13 import os | 14 import os |
14 import sys | 15 import sys |
15 import unittest | 16 import unittest |
16 | 17 |
17 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 18 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
18 | 19 |
19 import gclient | 20 import gclient |
20 import gclient_utils | 21 import gclient_utils |
21 from testing_support import trial_dir | 22 from testing_support import trial_dir |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 self.assertEquals( | 469 self.assertEquals( |
469 [ | 470 [ |
470 'svn://example.com/bar', | 471 'svn://example.com/bar', |
471 'svn://example.com/bar/unix', | 472 'svn://example.com/bar/unix', |
472 'svn://example.com/foo', | 473 'svn://example.com/foo', |
473 'svn://example.com/foo/baz', | 474 'svn://example.com/foo/baz', |
474 'svn://example.com/foo/unix', | 475 'svn://example.com/foo/unix', |
475 ], | 476 ], |
476 sorted(self._get_processed())) | 477 sorted(self._get_processed())) |
477 | 478 |
| 479 def testUpdateWithOsDeps(self): |
| 480 """Verifies that complicated deps_os constructs result in the |
| 481 correct data also with multple operating systems. Also see |
| 482 testDepsOsOverrideDepsInDepsFile.""" |
| 483 |
| 484 test_data = [ |
| 485 # Tuples of deps, deps_os, os_list and expected_deps. |
| 486 ( |
| 487 # OS doesn't need module. |
| 488 {'foo': 'default_foo'}, |
| 489 {'os1': { 'foo': None } }, |
| 490 ['os1'], |
| 491 {'foo': None} |
| 492 ), |
| 493 ( |
| 494 # OS wants a different version of module. |
| 495 {'foo': 'default_foo'}, |
| 496 {'os1': { 'foo': 'os1_foo'} }, |
| 497 ['os1'], |
| 498 {'foo': 'os1_foo'} |
| 499 ), |
| 500 ( |
| 501 # OS with no overrides at all. |
| 502 {'foo': 'default_foo'}, |
| 503 {'os1': { 'foo': None } }, |
| 504 ['os2'], |
| 505 {'foo': 'default_foo'} |
| 506 ), |
| 507 ( |
| 508 # One OS doesn't need module, one OS wants the default. |
| 509 {'foo': 'default_foo'}, |
| 510 {'os1': { 'foo': None }, |
| 511 'os2': {}}, |
| 512 ['os1', 'os2'], |
| 513 {'foo': 'default_foo'} |
| 514 ), |
| 515 ( |
| 516 # One OS doesn't need module, another OS wants a special version. |
| 517 {'foo': 'default_foo'}, |
| 518 {'os1': { 'foo': None }, |
| 519 'os2': { 'foo': 'os2_foo'}}, |
| 520 ['os1', 'os2'], |
| 521 {'foo': 'os2_foo'} |
| 522 ), |
| 523 ( |
| 524 # One OS wants to add a module. |
| 525 {'foo': 'default_foo'}, |
| 526 {'os1': { 'bar': 'os1_bar' }}, |
| 527 ['os1'], |
| 528 {'foo': 'default_foo', |
| 529 'bar': 'os1_bar'} |
| 530 ), |
| 531 ( |
| 532 # One OS wants to add a module. One doesn't care. |
| 533 {'foo': 'default_foo'}, |
| 534 {'os1': { 'bar': 'os1_bar' }}, |
| 535 ['os1', 'os2'], |
| 536 {'foo': 'default_foo', |
| 537 'bar': 'os1_bar'} |
| 538 ), |
| 539 ( |
| 540 # Two OSes want to add a module with the same definition. |
| 541 {'foo': 'default_foo'}, |
| 542 {'os1': { 'bar': 'os12_bar' }, |
| 543 'os2': { 'bar': 'os12_bar' }}, |
| 544 ['os1', 'os2'], |
| 545 {'foo': 'default_foo', |
| 546 'bar': 'os12_bar'} |
| 547 ), |
| 548 ] |
| 549 for deps, deps_os, target_os_list, expected_deps in test_data: |
| 550 orig_deps = copy.deepcopy(deps) |
| 551 result = gclient.Dependency.MergeWithOsDeps(deps, deps_os, target_os_list) |
| 552 self.assertEqual(result, expected_deps) |
| 553 self.assertEqual(deps, orig_deps) |
| 554 |
478 def testDepsOsOverrideDepsInDepsFile(self): | 555 def testDepsOsOverrideDepsInDepsFile(self): |
479 """Verifies that a 'deps_os' path can override a 'deps' path. | 556 """Verifies that a 'deps_os' path can override a 'deps' path. Also |
| 557 see testUpdateWithOsDeps above. |
480 """ | 558 """ |
481 | 559 |
482 write( | 560 write( |
483 '.gclient', | 561 '.gclient', |
484 'solutions = [\n' | 562 'solutions = [\n' |
485 ' { "name": "foo",\n' | 563 ' { "name": "foo",\n' |
486 ' "url": "svn://example.com/foo",\n' | 564 ' "url": "svn://example.com/foo",\n' |
487 ' },]\n') | 565 ' },]\n') |
488 write( | 566 write( |
489 os.path.join('foo', 'DEPS'), | 567 os.path.join('foo', 'DEPS'), |
490 'target_os = ["baz"]\n' | 568 'target_os = ["baz"]\n' |
491 'deps = {\n' | 569 'deps = {\n' |
492 ' "foo/src": "/src",\n' # This path is to be overridden by similar path | 570 ' "foo/src": "/src",\n' # This path is to be overridden by similar path |
493 # in deps_os['unix']. | 571 # in deps_os['unix']. |
494 '}\n' | 572 '}\n' |
495 'deps_os = {\n' | 573 'deps_os = {\n' |
496 ' "unix": { "foo/unix": "/unix",' | 574 ' "unix": { "foo/unix": "/unix",' |
497 ' "foo/src": "/src_unix"},\n' | 575 ' "foo/src": "/src_unix"},\n' |
498 ' "baz": { "foo/baz": "/baz", },\n' | 576 ' "baz": { "foo/baz": "/baz",\n' |
| 577 ' "foo/src": None},\n' |
499 ' "jaz": { "foo/jaz": "/jaz", },\n' | 578 ' "jaz": { "foo/jaz": "/jaz", },\n' |
500 '}') | 579 '}') |
501 | 580 |
502 parser = gclient.OptionParser() | 581 parser = gclient.OptionParser() |
503 options, _ = parser.parse_args(['--jobs', '1']) | 582 options, _ = parser.parse_args(['--jobs', '1']) |
504 options.deps_os = 'unix' | 583 options.deps_os = 'unix' |
505 | 584 |
506 obj = gclient.GClient.LoadCurrentConfig(options) | 585 obj = gclient.GClient.LoadCurrentConfig(options) |
507 obj.RunOnDeps('None', []) | 586 obj.RunOnDeps('None', []) |
508 self.assertEqual(['unix'], sorted(obj.enforced_os)) | 587 self.assertEqual(['unix'], sorted(obj.enforced_os)) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 649 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
571 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 650 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
572 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 651 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
573 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 652 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
574 logging.basicConfig( | 653 logging.basicConfig( |
575 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 654 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
576 min(sys.argv.count('-v'), 3)], | 655 min(sys.argv.count('-v'), 3)], |
577 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 656 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
578 '%(lineno)d) %(message)s') | 657 '%(lineno)d) %(message)s') |
579 unittest.main() | 658 unittest.main() |
OLD | NEW |