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