| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 def testDependenciesJobsReverse(self): | 82 def testDependenciesJobsReverse(self): |
| 83 self._dependencies('1000', True) | 83 self._dependencies('1000', True) |
| 84 | 84 |
| 85 def _dependencies(self, jobs, reverse): | 85 def _dependencies(self, jobs, reverse): |
| 86 # Verify that dependencies are processed in the right order, e.g. if there | 86 # Verify that dependencies are processed in the right order, e.g. if there |
| 87 # is a dependency 'src' and another 'src/third_party/bar', that bar isn't | 87 # is a dependency 'src' and another 'src/third_party/bar', that bar isn't |
| 88 # fetched until 'src' is done. | 88 # fetched until 'src' is done. |
| 89 # jobs is the number of parallel jobs simulated. reverse is to reshuffle the | 89 # jobs is the number of parallel jobs simulated. reverse is to reshuffle the |
| 90 # list to see if it is still processed in order correctly. | 90 # list to see if it is still processed in order correctly. |
| 91 # Also test that a From() dependency that should not be processed is listed |
| 92 # as a requirement. |
| 91 parser = gclient.Parser() | 93 parser = gclient.Parser() |
| 92 options, args = parser.parse_args(['--jobs', jobs]) | 94 options, args = parser.parse_args(['--jobs', jobs]) |
| 93 write( | 95 write( |
| 94 '.gclient', | 96 '.gclient', |
| 95 'solutions = [\n' | 97 'solutions = [\n' |
| 96 ' { "name": "foo", "url": "svn://example.com/foo" },\n' | 98 ' { "name": "foo", "url": "svn://example.com/foo" },\n' |
| 97 ' { "name": "bar", "url": "svn://example.com/bar" },\n' | 99 ' { "name": "bar", "url": "svn://example.com/bar" },\n' |
| 98 ' { "name": "bar/empty", "url": "svn://example.com/bar_empty" },\n' | 100 ' { "name": "bar/empty", "url": "svn://example.com/bar_empty" },\n' |
| 99 ']') | 101 ']') |
| 100 write( | 102 write( |
| 101 os.path.join('foo', 'DEPS'), | 103 os.path.join('foo', 'DEPS'), |
| 102 'deps = {\n' | 104 'deps = {\n' |
| 103 ' "foo/dir1": "/dir1",\n' | 105 ' "foo/dir1": "/dir1",\n' |
| 106 # This one will depend on dir1/dir2 in bar. |
| 104 ' "foo/dir1/dir2/dir3": "/dir1/dir2/dir3",\n' | 107 ' "foo/dir1/dir2/dir3": "/dir1/dir2/dir3",\n' |
| 105 ' "foo/dir1/dir4": "/dir1/dir4",\n' | |
| 106 ' "foo/dir1/dir2/dir3/dir4": "/dir1/dir2/dir3/dir4",\n' | 108 ' "foo/dir1/dir2/dir3/dir4": "/dir1/dir2/dir3/dir4",\n' |
| 109 ' "foo/dir1/dir2/dir5/dir6":\n' |
| 110 ' From("foo/dir1/dir2/dir3/dir4", "foo/dir1/dir2"),\n' |
| 107 '}') | 111 '}') |
| 108 write( | 112 write( |
| 109 os.path.join('bar', 'DEPS'), | 113 os.path.join('bar', 'DEPS'), |
| 110 'deps = {\n' | 114 'deps = {\n' |
| 111 ' "foo/dir1/dir2": "/dir1/dir2",\n' | 115 ' "foo/dir1/dir2": "/dir1/dir2",\n' |
| 112 '}') | 116 '}') |
| 113 write( | 117 write( |
| 114 os.path.join('bar/empty', 'DEPS'), | 118 os.path.join('bar/empty', 'DEPS'), |
| 115 'deps = {\n' | 119 'deps = {\n' |
| 116 '}') | 120 '}') |
| 121 # Test From() |
| 122 write( |
| 123 os.path.join('foo/dir1/dir2/dir3/dir4', 'DEPS'), |
| 124 'deps = {\n' |
| 125 # This one should not be fetched or set as a requirement. |
| 126 ' "foo/dir1/dir2/dir5": "svn://example.com/x",\n' |
| 127 ' "foo/dir1/dir2": "/dir1/another",\n' |
| 128 '}') |
| 117 | 129 |
| 118 obj = gclient.GClient.LoadCurrentConfig(options) | 130 obj = gclient.GClient.LoadCurrentConfig(options) |
| 119 self._check_requirements(obj.dependencies[0], {}) | 131 self._check_requirements(obj.dependencies[0], {}) |
| 120 self._check_requirements(obj.dependencies[1], {}) | 132 self._check_requirements(obj.dependencies[1], {}) |
| 121 obj.RunOnDeps('None', args) | 133 obj.RunOnDeps('None', args) |
| 122 # The trick here is to manually process the list to make sure it's out of | 134 # The trick here is to manually process the list to make sure it's out of |
| 123 # order. | 135 # order. |
| 124 for i in obj.dependencies: | 136 for i in obj.dependencies: |
| 125 i.dependencies.sort(key=lambda x: x.name, reverse=reverse) | 137 i.dependencies.sort(key=lambda x: x.name, reverse=reverse) |
| 126 actual = self._get_processed() | 138 actual = self._get_processed() |
| 127 # We don't care of the ordering of these items: | 139 # We don't care of the ordering of these items: |
| 128 self.assertEquals( | 140 self.assertEquals( |
| 129 ['svn://example.com/bar', 'svn://example.com/foo'], sorted(actual[0:2])) | 141 ['svn://example.com/bar', 'svn://example.com/foo'], sorted(actual[0:2])) |
| 130 actual = actual[2:] | 142 actual = actual[2:] |
| 131 # Ordering may not be exact in case of parallel jobs. | 143 # Ordering may not be exact in case of parallel jobs. |
| 132 self.assertTrue( | 144 self.assertTrue( |
| 133 actual.index('svn://example.com/bar/dir1/dir2') > | 145 actual.index('svn://example.com/bar/dir1/dir2') > |
| 134 actual.index('svn://example.com/foo/dir1')) | 146 actual.index('svn://example.com/foo/dir1')) |
| 135 actual.remove('svn://example.com/bar/dir1/dir2') | 147 actual.remove('svn://example.com/bar/dir1/dir2') |
| 136 | 148 |
| 137 # Ordering may not be exact in case of parallel jobs. | 149 # Ordering may not be exact in case of parallel jobs. |
| 138 actual.remove('svn://example.com/bar_empty') | 150 actual.remove('svn://example.com/bar_empty') |
| 139 self.assertEquals( | 151 self.assertEquals( |
| 140 [ | 152 [ |
| 141 'svn://example.com/foo/dir1', | 153 'svn://example.com/foo/dir1', |
| 142 'svn://example.com/foo/dir1/dir4', | |
| 143 'svn://example.com/foo/dir1/dir2/dir3', | 154 'svn://example.com/foo/dir1/dir2/dir3', |
| 144 'svn://example.com/foo/dir1/dir2/dir3/dir4', | 155 'svn://example.com/foo/dir1/dir2/dir3/dir4', |
| 156 # TODO(maruel): This is probably wrong. |
| 157 'svn://example.com/foo/dir1/dir2/dir3/dir4/dir1/another', |
| 145 ], | 158 ], |
| 146 actual) | 159 actual) |
| 147 self._check_requirements( | 160 self._check_requirements( |
| 148 obj.dependencies[0], | 161 obj.dependencies[0], |
| 149 { | 162 { |
| 150 'foo/dir1': ['foo'], | 163 'foo/dir1': ['foo'], |
| 151 'foo/dir1/dir2/dir3': ['foo', 'foo/dir1', 'foo/dir1/dir2'], | 164 'foo/dir1/dir2/dir3': ['foo', 'foo/dir1', 'foo/dir1/dir2'], |
| 152 'foo/dir1/dir2/dir3/dir4': | 165 'foo/dir1/dir2/dir3/dir4': |
| 153 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3'], | 166 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3'], |
| 154 'foo/dir1/dir4': ['foo', 'foo/dir1'], | 167 'foo/dir1/dir2/dir5/dir6': |
| 168 ['foo', 'foo/dir1', 'foo/dir1/dir2', 'foo/dir1/dir2/dir3/dir4'], |
| 155 }) | 169 }) |
| 156 self._check_requirements( | 170 self._check_requirements( |
| 157 obj.dependencies[1], | 171 obj.dependencies[1], |
| 158 { | 172 { |
| 159 'foo/dir1/dir2': ['bar', 'foo', 'foo/dir1'], | 173 'foo/dir1/dir2': ['bar', 'foo', 'foo/dir1'], |
| 160 }) | 174 }) |
| 161 self._check_requirements( | 175 self._check_requirements( |
| 162 obj, | 176 obj, |
| 163 { | 177 { |
| 164 'foo': [], | 178 'foo': [], |
| (...skipping 24 matching lines...) Expand all Loading... |
| 189 None, '', True) | 203 None, '', True) |
| 190 self.assertEquals('proto://host/path@revision', d.url) | 204 self.assertEquals('proto://host/path@revision', d.url) |
| 191 | 205 |
| 192 if __name__ == '__main__': | 206 if __name__ == '__main__': |
| 193 logging.basicConfig( | 207 logging.basicConfig( |
| 194 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 208 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
| 195 min(sys.argv.count('-v'), 3)], | 209 min(sys.argv.count('-v'), 3)], |
| 196 format='%(asctime).19s %(levelname)s %(filename)s:' | 210 format='%(asctime).19s %(levelname)s %(filename)s:' |
| 197 '%(lineno)s %(message)s') | 211 '%(lineno)s %(message)s') |
| 198 unittest.main() | 212 unittest.main() |
| OLD | NEW |