Chromium Code Reviews| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 items.append(self.processed.get_nowait()) | 203 items.append(self.processed.get_nowait()) |
| 204 except Queue.Empty: | 204 except Queue.Empty: |
| 205 pass | 205 pass |
| 206 return items | 206 return items |
| 207 | 207 |
| 208 def testAutofix(self): | 208 def testAutofix(self): |
| 209 # Invalid urls causes pain when specifying requirements. Make sure it's | 209 # Invalid urls causes pain when specifying requirements. Make sure it's |
| 210 # auto-fixed. | 210 # auto-fixed. |
| 211 d = gclient.Dependency( | 211 d = gclient.Dependency( |
| 212 None, 'name', 'proto://host/path/@revision', None, None, None, | 212 None, 'name', 'proto://host/path/@revision', None, None, None, |
| 213 None, '', True) | 213 None, '', None, True) |
| 214 self.assertEquals('proto://host/path@revision', d.url) | 214 self.assertEquals('proto://host/path@revision', d.url) |
| 215 | 215 |
| 216 def testStr(self): | 216 def testStr(self): |
| 217 parser = gclient.Parser() | 217 parser = gclient.Parser() |
| 218 options, _ = parser.parse_args([]) | 218 options, _ = parser.parse_args([]) |
| 219 obj = gclient.GClient('foo', options) | 219 obj = gclient.GClient('foo', options) |
| 220 obj.add_dependencies_and_close( | 220 obj.add_dependencies_and_close( |
| 221 [ | 221 [ |
| 222 gclient.Dependency( | 222 gclient.Dependency( |
| 223 obj, 'foo', 'url', None, None, None, None, 'DEPS', True), | 223 obj, 'foo', 'url', None, None, None, None, 'DEPS', None, True), |
| 224 gclient.Dependency( | 224 gclient.Dependency( |
| 225 obj, 'bar', 'url', None, None, None, None, 'DEPS', True), | 225 obj, 'bar', 'url', None, None, None, None, 'DEPS', None, True), |
| 226 ], | 226 ], |
| 227 []) | 227 []) |
| 228 obj.dependencies[0].add_dependencies_and_close( | 228 obj.dependencies[0].add_dependencies_and_close( |
| 229 [ | 229 [ |
| 230 gclient.Dependency( | 230 gclient.Dependency( |
| 231 obj.dependencies[0], 'foo/dir1', 'url', None, None, None, None, | 231 obj.dependencies[0], 'foo/dir1', 'url', None, None, None, None, |
| 232 'DEPS', True), | 232 'DEPS', None, True), |
| 233 gclient.Dependency( | 233 gclient.Dependency( |
| 234 obj.dependencies[0], 'foo/dir2', | 234 obj.dependencies[0], 'foo/dir2', |
| 235 gclient.GClientKeywords.FromImpl('bar'), None, None, None, None, | 235 gclient.GClientKeywords.FromImpl('bar'), None, None, None, None, |
| 236 'DEPS', True), | 236 'DEPS', None, True), |
| 237 gclient.Dependency( | 237 gclient.Dependency( |
| 238 obj.dependencies[0], 'foo/dir3', | 238 obj.dependencies[0], 'foo/dir3', |
| 239 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, | 239 gclient.GClientKeywords.FileImpl('url'), None, None, None, None, |
| 240 'DEPS', True), | 240 'DEPS', None, True), |
| 241 ], | 241 ], |
| 242 []) | 242 []) |
| 243 # Make sure __str__() works fine. | 243 # Make sure __str__() works fine. |
| 244 # pylint: disable=W0212 | 244 # pylint: disable=W0212 |
| 245 obj.dependencies[0]._file_list.append('foo') | 245 obj.dependencies[0]._file_list.append('foo') |
| 246 str_obj = str(obj) | 246 str_obj = str(obj) |
| 247 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) | 247 self.assertEquals(471, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) |
| 248 | 248 |
| 249 def testHooks(self): | 249 def testHooks(self): |
| 250 topdir = self.root_dir | 250 topdir = self.root_dir |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 269 parser = gclient.Parser() | 269 parser = gclient.Parser() |
| 270 options, _ = parser.parse_args([]) | 270 options, _ = parser.parse_args([]) |
| 271 options.force = True | 271 options.force = True |
| 272 client = gclient.GClient.LoadCurrentConfig(options) | 272 client = gclient.GClient.LoadCurrentConfig(options) |
| 273 work_queue = gclient_utils.ExecutionQueue(options.jobs, None) | 273 work_queue = gclient_utils.ExecutionQueue(options.jobs, None) |
| 274 for s in client.dependencies: | 274 for s in client.dependencies: |
| 275 work_queue.enqueue(s) | 275 work_queue.enqueue(s) |
| 276 work_queue.flush({}, None, [], options=options) | 276 work_queue.flush({}, None, [], options=options) |
| 277 self.assertEqual(client.GetHooks(options), [x['action'] for x in hooks]) | 277 self.assertEqual(client.GetHooks(options), [x['action'] for x in hooks]) |
| 278 | 278 |
| 279 def testTargetOS(self): | |
| 280 """Verifies that specifying a target_os pulls in all relevant dependencies. | |
| 281 | |
| 282 The target_os variable allows specifying the name of an additional OS which | |
| 283 should be considered when selecting dependencies from a DEPS' deps_os. The | |
| 284 value will be appended to the enforced_os tuple. | |
| 285 """ | |
| 286 | |
| 287 write( | |
| 288 '.gclient', | |
| 289 'solutions = [\n' | |
|
John Grabowski
2012/04/19 05:29:04
"""
for multi-line strings in python,
prefer tripl
Peter Beverloo
2012/04/19 06:11:03
Only following the file's convention :-). I have u
| |
| 290 ' { "name": "foo",\n' | |
| 291 ' "url": "svn://example.com/foo",\n' | |
| 292 ' "target_os": "baz",\n' | |
| 293 ' }\n' | |
| 294 ']') | |
| 295 write( | |
| 296 os.path.join('foo', 'DEPS'), | |
| 297 'deps = {\n' | |
| 298 ' "foo/dir1": "/dir1",' | |
| 299 '}\n' | |
| 300 'deps_os = {\n' | |
| 301 ' "unix": { "foo/dir2": "/dir2", },\n' | |
| 302 ' "baz": { "foo/dir3": "/dir3", },\n' | |
| 303 '}') | |
| 304 | |
| 305 parser = gclient.Parser() | |
| 306 options, args = parser.parse_args(['--jobs', '1']) | |
| 307 options.deps_os = "unix" | |
| 308 | |
| 309 obj = gclient.GClient.LoadCurrentConfig(options) | |
| 310 obj.RunOnDeps('None', args) | |
| 311 | |
| 312 self.assertEqual(4, len(self._get_processed())) | |
|
John Grabowski
2012/04/19 05:29:04
I don't understand this. 1 dep, plus 1 for unix,
Peter Beverloo
2012/04/19 06:11:03
svn://example.com/foo is also being processed (top
| |
| 313 | |
| 279 | 314 |
| 280 if __name__ == '__main__': | 315 if __name__ == '__main__': |
| 281 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 316 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
| 282 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 317 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
| 283 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 318 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
| 284 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 319 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
| 285 logging.basicConfig( | 320 logging.basicConfig( |
| 286 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 321 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
| 287 min(sys.argv.count('-v'), 3)], | 322 min(sys.argv.count('-v'), 3)], |
| 288 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 323 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
| 289 '%(lineno)d) %(message)s') | 324 '%(lineno)d) %(message)s') |
| 290 unittest.main() | 325 unittest.main() |
| OLD | NEW |