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

Side by Side Diff: unittests/package_test.py

Issue 2785503002: Revert of [package.proto] convert deps from list to map. (Closed)
Patch Set: 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 from recipe_engine import package
15 16
16 from recipe_engine import fetch
17 from recipe_engine import package
18 17
19 TEST_AUTHOR = 'foo@example.com' 18 TEST_AUTHOR = 'foo@example.com'
20 19
21 20
22 class MockIOThings(object): 21 class MockIOThings(object):
23 def setUp(self): 22 def setUp(self):
24 super(MockIOThings, self).setUp() 23 super(MockIOThings, self).setUp()
25 24
26 self.mock_os_patcher = mock.patch('recipe_engine.package.os') 25 self.mock_os_patcher = mock.patch('recipe_engine.package.os')
27 self.mock_os = self.mock_os_patcher.start() 26 self.mock_os = self.mock_os_patcher.start()
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 def write(self, buf): 375 def write(self, buf):
377 pass 376 pass
378 377
379 378
380 class TestPackageSpec(MockIOThings, unittest.TestCase): 379 class TestPackageSpec(MockIOThings, unittest.TestCase):
381 def setUp(self): 380 def setUp(self):
382 super(TestPackageSpec, self).setUp() 381 super(TestPackageSpec, self).setUp()
383 382
384 self.proto_text = '\n'.join([ 383 self.proto_text = '\n'.join([
385 '{', 384 '{',
386 ' "api_version": 2,',
387 ' "deps": {',
388 ' "bar": {',
389 ' "branch": "superbar",',
390 ' "revision": "deadd00d",',
391 ' "url": "https://repo.com/bar.git"',
392 ' },',
393 ' "foo": {',
394 ' "branch": "master",',
395 ' "revision": "cafebeef",',
396 ' "url": "https://repo.com/foo.git"',
397 ' }',
398 ' },',
399 ' "project_id": "super_main_package",',
400 ' "recipes_path": "path/to/recipes"',
401 '}',
402 ])
403 self.proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg',
404 self.proto_text)
405 self.context = package.PackageContext.from_proto_file(
406 'repo/root', self.proto_file, allow_fetch=False)
407
408 def test_dump_load_inverses(self):
409 # Doubles as a test for equality reflexivity.
410 package_spec = package.PackageSpec.load_proto(self.proto_file)
411 self.assertEqual(self.proto_file.to_raw(package_spec.dump()),
412 self.proto_text)
413 self.assertEqual(package.PackageSpec.load_proto(self.proto_file),
414 package_spec)
415
416 def test_dump_round_trips(self):
417 proto_text = """
418 {"api_version": 1}
419 """.lstrip()
420 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text)
421 package_spec = package.PackageSpec.load_proto(proto_file)
422 self.assertEqual(proto_file.to_raw(package_spec.dump()),
423 '{\n "api_version": 1\n}')
424
425 def test_no_version(self):
426 proto_text = """{
427 "project_id": "foo",
428 "recipes_path": "path/to/recipes"
429 }
430 """
431 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text)
432
433 with self.assertRaises(AssertionError):
434 package.PackageSpec.load_proto(proto_file)
435
436 def test_old_deps(self):
437 proto_text = '\n'.join([
438 '{',
439 ' "api_version": 1,', 385 ' "api_version": 1,',
440 ' "deps": [', 386 ' "deps": [',
441 ' {', 387 ' {',
442 ' "branch": "superbar",', 388 ' "branch": "superbar",',
443 ' "project_id": "bar",', 389 ' "project_id": "bar",',
444 ' "revision": "deadd00d",', 390 ' "revision": "deadd00d",',
445 ' "url": "https://repo.com/bar.git"', 391 ' "url": "https://repo.com/bar.git"',
446 ' },', 392 ' },',
447 ' {', 393 ' {',
448 ' "branch": "master",', 394 ' "branch": "master",',
449 ' "project_id": "foo",', 395 ' "project_id": "foo",',
450 ' "revision": "cafebeef",', 396 ' "revision": "cafebeef",',
451 ' "url": "https://repo.com/foo.git"', 397 ' "url": "https://repo.com/foo.git"',
452 ' }', 398 ' }',
453 ' ],', 399 ' ],',
454 ' "project_id": "super_main_package",', 400 ' "project_id": "super_main_package",',
455 ' "recipes_path": "path/to/recipes"', 401 ' "recipes_path": "path/to/recipes"',
456 '}', 402 '}',
457 ]) 403 ])
404 self.proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg',
405 self.proto_text)
406 self.context = package.PackageContext.from_proto_file(
407 'repo/root', self.proto_file, allow_fetch=False)
408
409 def test_dump_load_inverses(self):
410 # Doubles as a test for equality reflexivity.
411 package_spec = package.PackageSpec.load_proto(self.proto_file)
412 self.assertEqual(self.proto_file.to_raw(package_spec.dump()),
413 self.proto_text)
414 self.assertEqual(package.PackageSpec.load_proto(self.proto_file),
415 package_spec)
416
417 def test_dump_round_trips(self):
418 proto_text = """
419 {"api_version": 1}
420 """.lstrip()
421 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text)
422 package_spec = package.PackageSpec.load_proto(proto_file)
423 self.assertEqual(proto_file.to_raw(package_spec.dump()),
424 '{\n "api_version": 1\n}')
425
426 def test_no_version(self):
427 proto_text = """{
428 "project_id": "foo",
429 "recipes_path": "path/to/recipes"
430 }
431 """
458 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text) 432 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text)
459 433
460 spec = package.PackageSpec.load_proto(proto_file) 434 with self.assertRaises(AssertionError):
461 self.assertEqual(spec.deps['foo'], package.GitRepoSpec( 435 package.PackageSpec.load_proto(proto_file)
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 436
472 def test_unsupported_version(self): 437 def test_unsupported_version(self):
473 proto_text = """{ 438 proto_text = """{
474 "api_version": 99999999, 439 "api_version": 99999999,
475 "project_id": "fizzbar", 440 "project_id": "fizzbar",
476 "recipes_path": "path/to/recipes" 441 "recipes_path": "path/to/recipes"
477 }""" 442 }"""
478 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text) 443 proto_file = MockProtoFile('repo/root/infra/config/recipes.cfg', proto_text)
479 444
480 with self.assertRaises(AssertionError): 445 with self.assertRaises(AssertionError):
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 self.assertFalse(checkout.called) 487 self.assertFalse(checkout.called)
523 488
524 489
525 def load_tests(_loader, tests, _ignore): 490 def load_tests(_loader, tests, _ignore):
526 tests.addTests(doctest.DocTestSuite(package)) 491 tests.addTests(doctest.DocTestSuite(package))
527 return tests 492 return tests
528 493
529 494
530 if __name__ == '__main__': 495 if __name__ == '__main__':
531 result = unittest.main() 496 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