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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 ' "baz": { "foo/dir3": "/dir3", },\n' | 300 ' "baz": { "foo/dir3": "/dir3", },\n' |
301 '}') | 301 '}') |
302 | 302 |
303 parser = gclient.Parser() | 303 parser = gclient.Parser() |
304 options, _ = parser.parse_args(['--jobs', '1']) | 304 options, _ = parser.parse_args(['--jobs', '1']) |
305 options.deps_os = "unix" | 305 options.deps_os = "unix" |
306 | 306 |
307 obj = gclient.GClient.LoadCurrentConfig(options) | 307 obj = gclient.GClient.LoadCurrentConfig(options) |
308 self.assertEqual(['baz', 'unix'], sorted(obj.enforced_os)) | 308 self.assertEqual(['baz', 'unix'], sorted(obj.enforced_os)) |
309 | 309 |
| 310 def testTargetOsWithTargetOsOnly(self): |
| 311 """Verifies that specifying a target_os and target_os_only pulls in only |
| 312 the relevant dependencies. |
| 313 |
| 314 The target_os variable allows specifying the name of an additional OS which |
| 315 should be considered when selecting dependencies from a DEPS' deps_os. With |
| 316 target_os_only also set, the _enforced_os tuple will be set to only the |
| 317 target_os value. |
| 318 """ |
| 319 |
| 320 write( |
| 321 '.gclient', |
| 322 'solutions = [\n' |
| 323 ' { "name": "foo",\n' |
| 324 ' "url": "svn://example.com/foo",\n' |
| 325 ' }]\n' |
| 326 'target_os = ["baz"]\n' |
| 327 'target_os_only = True') |
| 328 write( |
| 329 os.path.join('foo', 'DEPS'), |
| 330 'deps = {\n' |
| 331 ' "foo/dir1": "/dir1",' |
| 332 '}\n' |
| 333 'deps_os = {\n' |
| 334 ' "unix": { "foo/dir2": "/dir2", },\n' |
| 335 ' "baz": { "foo/dir3": "/dir3", },\n' |
| 336 '}') |
| 337 |
| 338 parser = gclient.Parser() |
| 339 options, _ = parser.parse_args(['--jobs', '1']) |
| 340 options.deps_os = "unix" |
| 341 |
| 342 obj = gclient.GClient.LoadCurrentConfig(options) |
| 343 self.assertEqual(['baz'], sorted(obj.enforced_os)) |
| 344 |
| 345 def testTargetOsOnlyWithoutTargetOs(self): |
| 346 """Verifies that specifying a target_os_only without target_os_only raises |
| 347 an exception. |
| 348 """ |
| 349 |
| 350 write( |
| 351 '.gclient', |
| 352 'solutions = [\n' |
| 353 ' { "name": "foo",\n' |
| 354 ' "url": "svn://example.com/foo",\n' |
| 355 ' }]\n' |
| 356 'target_os_only = True') |
| 357 write( |
| 358 os.path.join('foo', 'DEPS'), |
| 359 'deps = {\n' |
| 360 ' "foo/dir1": "/dir1",' |
| 361 '}\n' |
| 362 'deps_os = {\n' |
| 363 ' "unix": { "foo/dir2": "/dir2", },\n' |
| 364 '}') |
| 365 |
| 366 parser = gclient.Parser() |
| 367 options, _ = parser.parse_args(['--jobs', '1']) |
| 368 options.deps_os = "unix" |
| 369 |
| 370 exception_raised = False |
| 371 try: |
| 372 gclient.GClient.LoadCurrentConfig(options) |
| 373 except gclient_utils.Error: |
| 374 exception_raised = True |
| 375 self.assertTrue(exception_raised) |
| 376 |
310 def testTargetOsInDepsFile(self): | 377 def testTargetOsInDepsFile(self): |
311 """Verifies that specifying a target_os value in a DEPS file pulls in all | 378 """Verifies that specifying a target_os value in a DEPS file pulls in all |
312 relevant dependencies. | 379 relevant dependencies. |
313 | 380 |
314 The target_os variable in a DEPS file allows specifying the name of an | 381 The target_os variable in a DEPS file allows specifying the name of an |
315 additional OS which should be considered when selecting dependencies from a | 382 additional OS which should be considered when selecting dependencies from a |
316 DEPS' deps_os. The value will be appended to the _enforced_os tuple. | 383 DEPS' deps_os. The value will be appended to the _enforced_os tuple. |
317 """ | 384 """ |
318 | 385 |
319 write( | 386 write( |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 480 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) |
414 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 481 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) |
415 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 482 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) |
416 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 483 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) |
417 logging.basicConfig( | 484 logging.basicConfig( |
418 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 485 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
419 min(sys.argv.count('-v'), 3)], | 486 min(sys.argv.count('-v'), 3)], |
420 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 487 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' |
421 '%(lineno)d) %(message)s') | 488 '%(lineno)d) %(message)s') |
422 unittest.main() | 489 unittest.main() |
OLD | NEW |