Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(788)

Side by Side Diff: unittests/package_test.py

Issue 2779683005: [package.proto] convert deps from list to map. (Closed)
Patch Set: fixit Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « recipe_engine/package_pb2.py ('k') | unittests/repo_test_util.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The LUCI Authors. All rights reserved. 2 # Copyright 2015 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 import copy 6 import copy
7 import doctest 7 import doctest
8 import os 8 import os
9 import subprocess 9 import subprocess
10 import unittest 10 import unittest
11 11
12 import repo_test_util 12 import repo_test_util
13 13
14 import mock 14 import mock
15
16 from recipe_engine import fetch
15 from recipe_engine import package 17 from recipe_engine import package
16 18
17
18 TEST_AUTHOR = 'foo@example.com' 19 TEST_AUTHOR = 'foo@example.com'
19 20
20 21
21 class MockIOThings(object): 22 class MockIOThings(object):
22 def setUp(self): 23 def setUp(self):
23 super(MockIOThings, self).setUp() 24 super(MockIOThings, self).setUp()
24 25
25 self.mock_os_patcher = mock.patch('recipe_engine.package.os') 26 self.mock_os_patcher = mock.patch('recipe_engine.package.os')
26 self.mock_os = self.mock_os_patcher.start() 27 self.mock_os = self.mock_os_patcher.start()
27 self.mock_os.path.join = os.path.join 28 self.mock_os.path.join = os.path.join
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 def write(self, buf): 376 def write(self, buf):
376 pass 377 pass
377 378
378 379
379 class TestPackageSpec(MockIOThings, unittest.TestCase): 380 class TestPackageSpec(MockIOThings, unittest.TestCase):
380 def setUp(self): 381 def setUp(self):
381 super(TestPackageSpec, self).setUp() 382 super(TestPackageSpec, self).setUp()
382 383
383 self.proto_text = '\n'.join([ 384 self.proto_text = '\n'.join([
384 '{', 385 '{',
385 ' "api_version": 1,', 386 ' "api_version": 2,',
386 ' "deps": [', 387 ' "deps": {',
387 ' {', 388 ' "bar": {',
388 ' "branch": "superbar",', 389 ' "branch": "superbar",',
389 ' "project_id": "bar",',
390 ' "revision": "deadd00d",', 390 ' "revision": "deadd00d",',
391 ' "url": "https://repo.com/bar.git"', 391 ' "url": "https://repo.com/bar.git"',
392 ' },', 392 ' },',
393 ' {', 393 ' "foo": {',
394 ' "branch": "master",', 394 ' "branch": "master",',
395 ' "project_id": "foo",',
396 ' "revision": "cafebeef",', 395 ' "revision": "cafebeef",',
397 ' "url": "https://repo.com/foo.git"', 396 ' "url": "https://repo.com/foo.git"',
398 ' }', 397 ' }',
399 ' ],', 398 ' },',
400 ' "project_id": "super_main_package",', 399 ' "project_id": "super_main_package",',
401 ' "recipes_path": "path/to/recipes"', 400 ' "recipes_path": "path/to/recipes"',
402 '}', 401 '}',
403 ]) 402 ])
404 self.proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', 403 self.proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg',
405 self.proto_text) 404 self.proto_text)
406 self.context = package.PackageContext.from_proto_file( 405 self.context = package.PackageContext.from_proto_file(
407 'repo/root', self.proto_file, allow_fetch=False) 406 'repo/root', self.proto_file, allow_fetch=False)
408 407
409 def test_dump_load_inverses(self): 408 def test_dump_load_inverses(self):
(...skipping 17 matching lines...) Expand all
427 proto_text = """{ 426 proto_text = """{
428 "project_id": "foo", 427 "project_id": "foo",
429 "recipes_path": "path/to/recipes" 428 "recipes_path": "path/to/recipes"
430 } 429 }
431 """ 430 """
432 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text) 431 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text)
433 432
434 with self.assertRaises(AssertionError): 433 with self.assertRaises(AssertionError):
435 package.PackageSpec.load_proto(proto_file) 434 package.PackageSpec.load_proto(proto_file)
436 435
436 def test_old_deps(self):
437 proto_text = '\n'.join([
438 '{',
439 ' "api_version": 1,',
440 ' "deps": [',
441 ' {',
442 ' "branch": "superbar",',
443 ' "project_id": "bar",',
444 ' "revision": "deadd00d",',
445 ' "url": "https://repo.com/bar.git"',
446 ' },',
447 ' {',
448 ' "branch": "master",',
449 ' "project_id": "foo",',
450 ' "revision": "cafebeef",',
451 ' "url": "https://repo.com/foo.git"',
452 ' }',
453 ' ],',
454 ' "project_id": "super_main_package",',
455 ' "recipes_path": "path/to/recipes"',
456 '}',
457 ])
458 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text)
459
460 spec = package.PackageSpec.load_proto(proto_file)
461 self.assertEqual(spec.deps['foo'], package.GitRepoSpec(
462 'foo',
463 'https://repo.com/foo.git',
464 'master',
465 'cafebeef',
466 '',
467 fetch.GitBackend()
468 ))
469 self.assertEqual(proto_file.to_raw(spec.dump()), proto_text)
470
471
437 def test_unsupported_version(self): 472 def test_unsupported_version(self):
438 proto_text = """{ 473 proto_text = """{
439 "api_version": 99999999, 474 "api_version": 99999999,
440 "project_id": "fizzbar", 475 "project_id": "fizzbar",
441 "recipes_path": "path/to/recipes" 476 "recipes_path": "path/to/recipes"
442 }""" 477 }"""
443 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text) 478 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text)
444 479
445 with self.assertRaises(AssertionError): 480 with self.assertRaises(AssertionError):
446 package.PackageSpec.load_proto(proto_file) 481 package.PackageSpec.load_proto(proto_file)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 self.assertFalse(checkout.called) 522 self.assertFalse(checkout.called)
488 523
489 524
490 def load_tests(_loader, tests, _ignore): 525 def load_tests(_loader, tests, _ignore):
491 tests.addTests(doctest.DocTestSuite(package)) 526 tests.addTests(doctest.DocTestSuite(package))
492 return tests 527 return tests
493 528
494 529
495 if __name__ == '__main__': 530 if __name__ == '__main__':
496 result = unittest.main() 531 result = unittest.main()
OLDNEW
« no previous file with comments | « recipe_engine/package_pb2.py ('k') | unittests/repo_test_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698