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

Unified Diff: third_party/recipe_engine/unittests/package_test.py

Issue 1241323004: Cross-repo recipe package system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: third_party/recipe_engine/unittests/package_test.py
diff --git a/third_party/recipe_engine/unittests/package_test.py b/third_party/recipe_engine/unittests/package_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..e7c08ffe13207fcb370cee7481957536e4f4373c
--- /dev/null
+++ b/third_party/recipe_engine/unittests/package_test.py
@@ -0,0 +1,143 @@
+#!/usr/bin/env python
+
+import doctest
+import os
+import sys
+import unittest
+
+RECIPE_ENGINE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+THIRD_PARTY = os.path.dirname(RECIPE_ENGINE)
+sys.path.insert(0, os.path.join(THIRD_PARTY, 'mock-1.0.1'))
+sys.path.insert(0, THIRD_PARTY)
+
+import mock
+from recipe_engine import package
+
+class MockIOThings(object):
+ def setUp(self):
+ self.mock_os_patcher = mock.patch('recipe_engine.package.os')
+ self.mock_os = self.mock_os_patcher.start()
+ self.mock_os.path.join = os.path.join
+
+ self.mock_subprocess_patcher = mock.patch(
+ 'recipe_engine.package.subprocess')
+ self.mock_subprocess = self.mock_subprocess_patcher.start()
+
+ def tearDown(self):
+ self.mock_subprocess_patcher.stop()
+ self.mock_os_patcher.stop()
+
+
+class TestGitRepoSpec(MockIOThings, unittest.TestCase):
+ REPO_URL = 'https://funny.recipes/repo.git'
+ def setUp(self):
+ super(TestGitRepoSpec, self).setUp()
+
+ self.repo_spec = package.GitRepoSpec(
+ 'funny_recipes',
+ self.REPO_URL,
+ 'master',
+ 'deadbeef',
+ 'path/to/recipes',
+ )
+ self.context = package.PackageContext.from_pyl_path(
+ os.path.join('path', 'to', 'package.pyl'))
+
+ def test_checkout_nonexistant_package_dir(self):
+ self.mock_os.path.exists.return_value = False
+ self.mock_os.path.isdir.return_value = False
+
+ self.repo_spec.checkout(self.context)
+
+ self.mock_subprocess.check_call.assert_any_call(
+ ['git', 'clone', self.REPO_URL,
+ os.path.join(self.context.package_dir, 'funny_recipes')])
+ self.mock_subprocess.check_call.assert_any_call(
+ ['git', 'checkout', '-q', 'deadbeef'])
+
+ @mock.patch('recipe_engine.package.logging')
+ def test_checkout_dont_mess_with_this(self, mock_logging):
+ self.mock_os.path.exists.wraps = lambda path: (
+ path == os.path.join(self.context.package_dir, '.dont_mess_with_this'))
+ self.repo_spec.checkout(self.context)
+ self.mock_subprocess.check_call.assert_has_calls([])
+ self.assertRegexpMatches(mock_logging.warn.call_args[0][0],
+ r'\.dont_mess_with_this')
+
+
+class TestPackageSpec(MockIOThings, unittest.TestCase):
+ def setUp(self):
+ super(TestPackageSpec, self).setUp()
+
+ self.package_pyl = {
+ 'api_version': 0,
+ 'id': 'super_main_package',
+ 'deps': {
+ 'foo': {
+ 'repo': 'https://repo.com/foo.git',
+ 'branch': 'master',
+ 'revision': 'cafebeef',
+ 'path': 'foos/recipes',
+ },
+ 'bar': {
+ 'repo': 'https://repo.com/bar.git',
+ 'branch': 'superbar',
+ 'revision': 'deadd00d',
+ 'path': 'bars/recipes',
+ },
+ },
+ }
+ self.context = package.PackageContext.from_pyl_path(
+ os.path.join('path', 'to', 'package.pyl'))
+
+ def test_dump_load_inverses(self):
+ # Doubles as a test for equality reflexivity.
+ package_spec = package.PackageSpec.load(self.package_pyl)
+ self.assertEqual(package_spec.dump(), self.package_pyl)
+ self.assertEqual(package.PackageSpec.load(self.package_pyl), package_spec)
+
+ def test_updates_merged(self):
+ package_spec = package.PackageSpec.load(self.package_pyl)
+ package_spec.deps['foo']._raw_updates = mock.Mock(return_value='\n'.join([
+ "2015-07-02T16:41:46+00:00 aaaaaa",
+ "2015-07-05T13:38:26+00:00 bbbbbb",
+ "2015-07-07T15:52:20-07:00 cccccc",
+ ]))
+ package_spec.deps['bar']._raw_updates = mock.Mock(return_value='\n'.join([
+ "2015-07-01T17:09:06+00:00 dddddd",
+ "2015-07-03T10:12:30+00:00 eeeeee",
+ "2015-07-06T21:16:36-07:00 ffffff",
+ ]))
+ updates = package_spec.updates(self.context)
+ self.assertEqual(
+ [ (spec.deps['foo'].revision, spec.deps['bar'].revision)
+ for _date, spec in updates ],
+ [ ('cafebeef', 'dddddd'),
+ ('aaaaaa', 'dddddd'),
+ ('aaaaaa', 'eeeeee'),
+ ('bbbbbb', 'eeeeee'),
+ ('bbbbbb', 'ffffff'),
+ ('cccccc', 'ffffff') ])
+
+ def test_no_version(self):
+ with self.assertRaises(Exception):
+ package.PackageSpec.load({
+ 'id': 'foo',
+ 'deps': {},
+ })
+
+ def test_unsupported_version(self):
+ with self.assertRaises(Exception):
+ package.PackageSpec.load({
+ 'api_version': 1,
+ 'id': 'fizzbar',
+ 'deps': {},
+ })
+
+def load_tests(loader, tests, ignore):
+ tests.addTests(doctest.DocTestSuite(package))
+ return tests
+
+
+if __name__ == '__main__':
+ result = unittest.main()
« scripts/slave/recipe_package.pyl ('K') | « third_party/recipe_engine/unittests/multi_repo_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698