| Index: unittests/package_setup_test.py
|
| diff --git a/unittests/errors_test.py b/unittests/package_setup_test.py
|
| similarity index 71%
|
| rename from unittests/errors_test.py
|
| rename to unittests/package_setup_test.py
|
| index 6051abdf395c88422b1b236cbe046e4c6c8ed6aa..3aad50f5d533645b4ab06db216c24f3d5f95aa0d 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), {'variables'})
|
| + self.assertEqual(set(spec['variables']), {'command', 'files'})
|
| + files = spec['variables']['files']
|
| + self.assertTrue(not any(i.endswith('.pyc') for i in files))
|
| +
|
| + 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),
|
| + {'infra/config/recipes.cfg',
|
| + '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)
|
| +
|
| +
|
| +def _partition(items, pred):
|
| + return ([ i for i in items if pred(i) ],
|
| + [ i for i in items if not pred(i) ])
|
| +
|
| +
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|