| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 items.append(self.processed.get_nowait()) | 213 items.append(self.processed.get_nowait()) |
| 214 except Queue.Empty: | 214 except Queue.Empty: |
| 215 pass | 215 pass |
| 216 return items | 216 return items |
| 217 | 217 |
| 218 def testAutofix(self): | 218 def testAutofix(self): |
| 219 # Invalid urls causes pain when specifying requirements. Make sure it's | 219 # Invalid urls causes pain when specifying requirements. Make sure it's |
| 220 # auto-fixed. | 220 # auto-fixed. |
| 221 d = gclient.Dependency( | 221 d = gclient.Dependency( |
| 222 None, 'name', 'proto://host/path/@revision', None, None, None, None, | 222 None, 'name', 'proto://host/path/@revision', None, None, None, None, |
| 223 None, '', True) | 223 None, '', True, False) |
| 224 self.assertEquals('proto://host/path@revision', d.url) | 224 self.assertEquals('proto://host/path@revision', d.url) |
| 225 | 225 |
| 226 def testStr(self): | 226 def testStr(self): |
| 227 parser = gclient.OptionParser() | 227 parser = gclient.OptionParser() |
| 228 options, _ = parser.parse_args([]) | 228 options, _ = parser.parse_args([]) |
| 229 obj = gclient.GClient('foo', options) | 229 obj = gclient.GClient('foo', options) |
| 230 obj.add_dependencies_and_close( | 230 obj.add_dependencies_and_close( |
| 231 [ | 231 [ |
| 232 gclient.Dependency( | 232 gclient.Dependency( |
| 233 obj, 'foo', 'url', None, None, None, None, None, 'DEPS', True), | 233 obj, 'foo', 'url', None, None, None, None, None, 'DEPS', True, False), |
| 234 gclient.Dependency( | 234 gclient.Dependency( |
| 235 obj, 'bar', 'url', None, None, None, None, None, 'DEPS', True), | 235 obj, 'bar', 'url', None, None, None, None, None, 'DEPS', True, False), |
| 236 ], | 236 ], |
| 237 []) | 237 []) |
| 238 obj.dependencies[0].add_dependencies_and_close( | 238 obj.dependencies[0].add_dependencies_and_close( |
| 239 [ | 239 [ |
| 240 gclient.Dependency( | 240 gclient.Dependency( |
| 241 obj.dependencies[0], 'foo/dir1', 'url', None, None, None, None, | 241 obj.dependencies[0], 'foo/dir1', 'url', None, None, None, None, |
| 242 None, 'DEPS', True), | 242 None, 'DEPS', True, False), |
| 243 gclient.Dependency( | 243 gclient.Dependency( |
| 244 obj.dependencies[0], 'foo/dir2', | 244 obj.dependencies[0], 'foo/dir2', |
| 245 gclient.GClientKeywords.FromImpl('bar'), None, None, None, None, | 245 gclient.GClientKeywords.FromImpl('bar'), None, None, None, None, |
| 246 None, 'DEPS', True), | 246 None, 'DEPS', True, False), |
| 247 gclient.Dependency( | 247 gclient.Dependency( |
| 248 obj.dependencies[0], 'foo/dir3', | 248 obj.dependencies[0], 'foo/dir3', |
| 249 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, | 249 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, |
| 250 None, 'DEPS', True), | 250 None, 'DEPS', True, False), |
| 251 ], | 251 ], |
| 252 []) | 252 []) |
| 253 # Make sure __str__() works fine. | 253 # Make sure __str__() works fine. |
| 254 # pylint: disable=W0212 | 254 # pylint: disable=W0212 |
| 255 obj.dependencies[0]._file_list.append('foo') | 255 obj.dependencies[0]._file_list.append('foo') |
| 256 str_obj = str(obj) | 256 str_obj = str(obj) |
| 257 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) | 257 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) |
| 258 | 258 |
| 259 def testHooks(self): | 259 def testHooks(self): |
| 260 topdir = self.root_dir | 260 topdir = self.root_dir |
| 261 gclient_fn = os.path.join(topdir, '.gclient') | 261 gclient_fn = os.path.join(topdir, '.gclient') |
| 262 fh = open(gclient_fn, 'w') | 262 fh = open(gclient_fn, 'w') |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 orig_deps = copy.deepcopy(deps) | 560 orig_deps = copy.deepcopy(deps) |
| 561 result = gclient.Dependency.MergeWithOsDeps(deps, deps_os, target_os_list) | 561 result = gclient.Dependency.MergeWithOsDeps(deps, deps_os, target_os_list) |
| 562 self.assertEqual(result, expected_deps) | 562 self.assertEqual(result, expected_deps) |
| 563 self.assertEqual(deps, orig_deps) | 563 self.assertEqual(deps, orig_deps) |
| 564 | 564 |
| 565 | 565 |
| 566 def testLateOverride(self): | 566 def testLateOverride(self): |
| 567 """Verifies expected behavior of LateOverride.""" | 567 """Verifies expected behavior of LateOverride.""" |
| 568 url = "git@github.com:dart-lang/spark.git" | 568 url = "git@github.com:dart-lang/spark.git" |
| 569 d = gclient.Dependency(None, 'name', 'url', | 569 d = gclient.Dependency(None, 'name', 'url', |
| 570 None, None, None, None, None, '', True) | 570 None, None, None, None, None, '', True, False) |
| 571 late_url = d.LateOverride(url) | 571 late_url = d.LateOverride(url) |
| 572 self.assertEquals(url, late_url) | 572 self.assertEquals(url, late_url) |
| 573 | 573 |
| 574 def testDepsOsOverrideDepsInDepsFile(self): | 574 def testDepsOsOverrideDepsInDepsFile(self): |
| 575 """Verifies that a 'deps_os' path can override a 'deps' path. Also | 575 """Verifies that a 'deps_os' path can override a 'deps' path. Also |
| 576 see testUpdateWithOsDeps above. | 576 see testUpdateWithOsDeps above. |
| 577 """ | 577 """ |
| 578 | 578 |
| 579 write( | 579 write( |
| 580 '.gclient', | 580 '.gclient', |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 ' { "name": "foo", "url": "svn://example.com/foo" },\n' | 732 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
| 733 ']') | 733 ']') |
| 734 write( | 734 write( |
| 735 os.path.join('foo', 'DEPS'), | 735 os.path.join('foo', 'DEPS'), |
| 736 'use_relative_paths = True\n' | 736 'use_relative_paths = True\n' |
| 737 'deps = {\n' | 737 'deps = {\n' |
| 738 ' "bar": "/bar",\n' | 738 ' "bar": "/bar",\n' |
| 739 '}\n' | 739 '}\n' |
| 740 'recursedeps = ["bar"]') | 740 'recursedeps = ["bar"]') |
| 741 write( | 741 write( |
| 742 os.path.join('bar', 'DEPS'), | 742 os.path.join('foo/bar', 'DEPS'), |
| 743 'deps = {\n' | 743 'deps = {\n' |
| 744 ' "baz": "/baz",\n' | 744 ' "baz": "/baz",\n' |
| 745 '}') | 745 '}') |
| 746 write( |
| 747 os.path.join('baz', 'DEPS'), |
| 748 'deps = {\n' |
| 749 ' "fizz": "/fizz",\n' |
| 750 '}') |
| 751 |
| 752 options, _ = gclient.OptionParser().parse_args([]) |
| 753 obj = gclient.GClient.LoadCurrentConfig(options) |
| 754 obj.RunOnDeps('None', []) |
| 755 self.assertEquals( |
| 756 [ |
| 757 ('foo', 'svn://example.com/foo'), |
| 758 ('foo/bar', 'svn://example.com/foo/bar'), |
| 759 ('foo/baz', 'svn://example.com/foo/bar/baz'), |
| 760 ], |
| 761 self._get_processed()) |
| 762 |
| 763 def testRelativeRecursion(self): |
| 764 """Verifies that nested use_relative_paths is always respected.""" |
| 765 write( |
| 766 '.gclient', |
| 767 'solutions = [\n' |
| 768 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
| 769 ']') |
| 770 write( |
| 771 os.path.join('foo', 'DEPS'), |
| 772 'use_relative_paths = True\n' |
| 773 'deps = {\n' |
| 774 ' "bar": "/bar",\n' |
| 775 '}\n' |
| 776 'recursedeps = ["bar"]') |
| 777 write( |
| 778 os.path.join('foo/bar', 'DEPS'), |
| 779 'use_relative_paths = True\n' |
| 780 'deps = {\n' |
| 781 ' "baz": "/baz",\n' |
| 782 '}') |
| 746 write( | 783 write( |
| 747 os.path.join('baz', 'DEPS'), | 784 os.path.join('baz', 'DEPS'), |
| 748 'deps = {\n' | 785 'deps = {\n' |
| 749 ' "fizz": "/fizz",\n' | 786 ' "fizz": "/fizz",\n' |
| 750 '}') | 787 '}') |
| 751 | 788 |
| 752 options, _ = gclient.OptionParser().parse_args([]) | 789 options, _ = gclient.OptionParser().parse_args([]) |
| 753 obj = gclient.GClient.LoadCurrentConfig(options) | 790 obj = gclient.GClient.LoadCurrentConfig(options) |
| 754 obj.RunOnDeps('None', []) | 791 obj.RunOnDeps('None', []) |
| 755 self.assertEquals( | 792 self.assertEquals( |
| 756 [ | 793 [ |
| 757 ('foo', 'svn://example.com/foo'), | 794 ('foo', 'svn://example.com/foo'), |
| 758 ('foo/bar', 'svn://example.com/foo/bar'), | 795 ('foo/bar', 'svn://example.com/foo/bar'), |
| 759 # TODO(agable): Figure out why baz isn't included here. The | 796 ('foo/bar/baz', 'svn://example.com/foo/bar/baz'), |
| 760 # recursedeps = ["bar"] in foo's DEPS means that we should be | |
| 761 # fetching the entries in bar's DEPS file, which includes baz. | |
| 762 ], | 797 ], |
| 763 self._get_processed()) | 798 self._get_processed()) |
| 764 | 799 |
| 765 def testRecursionOverridesRecursedeps(self): | 800 def testRecursionOverridesRecursedeps(self): |
| 766 """Verifies gclient respects |recursion| over |recursedeps|. | 801 """Verifies gclient respects |recursion| over |recursedeps|. |
| 767 | 802 |
| 768 |recursion| is set in a top-level DEPS file. That value is meant | 803 |recursion| is set in a top-level DEPS file. That value is meant |
| 769 to affect how many subdeps are parsed via recursion. | 804 to affect how many subdeps are parsed via recursion. |
| 770 | 805 |
| 771 |recursedeps| is set in each DEPS file to control whether or not | 806 |recursedeps| is set in each DEPS file to control whether or not |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 1105 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
| 1071 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 1106 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
| 1072 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 1107 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
| 1073 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 1108 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
| 1074 logging.basicConfig( | 1109 logging.basicConfig( |
| 1075 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 1110 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
| 1076 min(sys.argv.count('-v'), 3)], | 1111 min(sys.argv.count('-v'), 3)], |
| 1077 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 1112 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
| 1078 '%(lineno)d) %(message)s') | 1113 '%(lineno)d) %(message)s') |
| 1079 unittest.main() | 1114 unittest.main() |
| OLD | NEW |