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

Unified Diff: unittests/package_setup_test.py

Issue 1570333002: 'recipes.py isolate' command to build an isolate of the current package's toolchain (Closed) Base URL: git@github.com:luci/recipes-py.git@master
Patch Set: Review comments Created 4 years, 11 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
« recipes.py ('K') | « unittests/errors_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: unittests/package_setup_test.py
diff --git a/unittests/errors_test.py b/unittests/package_setup_test.py
similarity index 70%
rename from unittests/errors_test.py
rename to unittests/package_setup_test.py
index 6051abdf395c88422b1b236cbe046e4c6c8ed6aa..30df63753b1da731c8bd66edebfcd77bf540ff55 100755
--- a/unittests/errors_test.py
+++ b/unittests/package_setup_test.py
@@ -3,7 +3,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import json
import os
+import re
import shutil
import subprocess
import tempfile
@@ -45,12 +47,21 @@ deps {
with open(os.path.join(module_root, 'api.py'), 'w') as fh:
fh.write(api_contents)
- @property
- def recipes_cmd(self):
- return [
+ def make_file(self, relpath, contents):
+ dirname = os.path.join(self._root, os.path.dirname(relpath))
+ if dirname and not os.path.exists(dirname):
+ os.makedirs(dirname)
+ with open(os.path.join(self._root, relpath), 'w') as fh:
+ fh.write(contents)
+
+ def recipes_cmd(self, package_override=True):
+ cmd = [
os.path.join(ROOT_DIR, 'recipes.py'),
'--package', self._recipes_cfg,
- '-O', 'recipe_engine=%s' % ROOT_DIR]
+ ]
+ if package_override:
+ cmd += ['-O', 'recipe_engine=%s' % ROOT_DIR]
+ return cmd
def __enter__(self):
return self
@@ -58,10 +69,10 @@ deps {
def __exit__(self, *_):
shutil.rmtree(self._root)
-class ErrorsTest(unittest.TestCase):
- def _test_cmd(self, repo, cmd, asserts, retcode=0):
+class PackageSetupTest(unittest.TestCase):
+ def _test_cmd(self, repo, cmd, asserts, retcode=0, package_override=True):
subp = subprocess.Popen(
- repo.recipes_cmd + cmd,
+ repo.recipes_cmd(package_override=package_override) + cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = subp.communicate()
@@ -75,7 +86,7 @@ class ErrorsTest(unittest.TestCase):
DEPS = ['aint_no_thang']
""")
subp = subprocess.Popen(
- repo.recipes_cmd + ['run', 'foo'],
+ repo.recipes_cmd() + ['run', 'foo'],
stdout=subprocess.PIPE)
stdout, _ = subp.communicate()
self.assertRegexpMatches(stdout,
@@ -87,7 +98,7 @@ DEPS = ['aint_no_thang']
repo.make_recipe('foo', 'DEPS = ["le_module"]')
repo.make_module('le_module', 'DEPS = ["love"]', '')
subp = subprocess.Popen(
- repo.recipes_cmd + ['run', 'foo'],
+ repo.recipes_cmd() + ['run', 'foo'],
stdout=subprocess.PIPE)
stdout, _ = subp.communicate()
self.assertRegexpMatches(stdout,
@@ -99,7 +110,7 @@ DEPS = ['aint_no_thang']
def test_no_such_recipe(self):
with RecipeRepo() as repo:
subp = subprocess.Popen(
- repo.recipes_cmd + ['run', 'nooope'],
+ repo.recipes_cmd() + ['run', 'nooope'],
stdout=subprocess.PIPE)
stdout, _ = subp.communicate()
self.assertRegexpMatches(stdout, r'No such recipe: nooope')
@@ -185,5 +196,48 @@ def GenTests(api):
stdout + stderr, 'Unconsumed'),
retcode=1)
+ def test_isolate(self):
+ def check_isolate_form(stdout, stderr):
+ spec = json.loads(stdout)
+ self.assertEqual(set(spec.keys()), set(['variables']))
M-A Ruel 2016/01/16 00:42:39 remove .keys(), not needed
luqui 2016/01/16 03:55:30 Done.
+ self.assertEqual(set(spec['variables']),
+ set(['command', 'files']))
M-A Ruel 2016/01/16 00:42:39 {'command', 'files'}
luqui 2016/01/16 03:55:29 no kidding? I didn't know about that
+ files = list(spec['variables']['files'])
M-A Ruel 2016/01/16 00:42:39 why convert to a list first?
luqui 2016/01/16 03:55:30 Ah, leftover from when I was modifying files (whic
+ self.assertTrue(not any( i.endswith('.pyc') for i in files ))
M-A Ruel 2016/01/16 00:42:39 no space between ( and i why not assertNotIn?
luqui 2016/01/16 03:55:30 Done.
+
+ engine_files, nonengine_files = _partition(
+ files, lambda i: re.match(r'\.recipe_deps/recipe_engine/.*', i))
+ self.assertTrue(engine_files)
+
+ self.assertEqual(
+ set(nonengine_files),
+ set(['infra/config/recipes.cfg',
M-A Ruel 2016/01/16 00:42:39 {}
luqui 2016/01/16 03:55:30 Done.
+ 'recipes.py',
+ 'recipes.extra',
+ 'recipes/some_recipe.py',
+ 'recipe_modules/some_module/__init__.py',
+ 'recipe_modules/some_module/api.py',
+ 'supporting/file.txt']))
+
+ self.assertEqual(
+ spec['variables']['command'],
+ ['python', '.recipe_deps/recipe_engine/recipes.py',
+ '--package', 'infra/config/recipes.cfg',
+ '--no-fetch'])
+
+ with RecipeRepo() as repo:
+ repo.make_recipe('some_recipe', '')
+ repo.make_module('some_module', '', '')
+ repo.make_file(os.path.join('supporting', 'file.txt'), 'yay')
+ repo.make_file(os.path.join('unsupporting', 'file.txt'), 'nay')
+ repo.make_file(os.path.join('recipes.extra'), 'supporting')
+ self._test_cmd(repo,
+ ['isolate'], asserts=check_isolate_form, package_override=False)
+
M-A Ruel 2016/01/16 00:42:39 2 lines
luqui 2016/01/16 03:55:30 Done.
+def _partition(items, pred):
+ return ([ item for item in items if pred(item) ],
M-A Ruel 2016/01/16 00:42:39 I'd use i instead of items, it'd fit one line and
luqui 2016/01/16 03:55:30 Done.
+ [ item for item in items if not pred(item) ])
+
+
if __name__ == '__main__':
unittest.main()
« recipes.py ('K') | « unittests/errors_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698