diff options
author | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-11-08 14:49:24 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2017-11-10 09:44:20 +0000 |
commit | 25f6bec66a742cf96e45ed4f2e16bbcde972174b (patch) | |
tree | 21c5c6f1dc41b851c88e3c6c1b7338f8239447f9 /tests | |
parent | 794e73cb4469c30bd830b333597a6932da1254f1 (diff) | |
download | buildstream-25f6bec66a742cf96e45ed4f2e16bbcde972174b.tar.gz |
load.py: Migrate to new test style
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pipeline/load.py | 153 | ||||
-rw-r--r-- | tests/testutils/runcli.py | 26 |
2 files changed, 90 insertions, 89 deletions
diff --git a/tests/pipeline/load.py b/tests/pipeline/load.py index 7adcd0f1e..9cd2fea62 100644 --- a/tests/pipeline/load.py +++ b/tests/pipeline/load.py @@ -1,5 +1,6 @@ import os import pytest +from tests.testutils.runcli import cli from buildstream import Scope from buildstream._context import Context @@ -7,8 +8,6 @@ from buildstream._project import Project from buildstream._pipeline import Pipeline from buildstream._platform import Platform -from tests.testutils.site import HAVE_ROOT - DATA_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'load', @@ -26,143 +25,119 @@ def create_pipeline(tmpdir, basedir, target): return Pipeline(context, project, [target]) -@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'simple')) -def test_load_simple(datafiles, tmpdir): - +def test_load_simple(cli, datafiles, tmpdir): basedir = os.path.join(datafiles.dirname, datafiles.basename) - pipeline = create_pipeline(tmpdir, basedir, 'simple.bst') - - assert(pipeline.targets[0].get_kind() == "autotools") + result = cli.get_element_config(basedir, 'simple.bst') - assert(isinstance(pipeline.targets[0].commands['configure-commands'], list)) - command_list = pipeline.targets[0].commands['configure-commands'] - assert(len(command_list) == 1) - assert(command_list[0] == 'pony') + assert(result['configure-commands'][0] == 'pony') ############################################################### # Testing Element.dependencies() iteration # ############################################################### -@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate')) -def test_iterate_scope_all(datafiles, tmpdir): - +def test_iterate_scope_all(cli, datafiles, tmpdir): basedir = os.path.join(datafiles.dirname, datafiles.basename) - pipeline = create_pipeline(tmpdir, basedir, 'target.bst') - - assert(pipeline.targets[0].get_kind() == "autotools") + elements = ['target.bst'] - assert(isinstance(pipeline.targets[0].commands['configure-commands'], list)) - command_list = pipeline.targets[0].commands['configure-commands'] - assert(len(command_list) == 1) - assert(command_list[0] == 'pony') + element_list = cli.get_pipeline(basedir, elements, scope='all') - element_list = pipeline.targets[0].dependencies(Scope.ALL) - element_list = list(element_list) assert(len(element_list) == 7) - assert(element_list[0].name == "build-build.bst") - assert(element_list[1].name == "run-build.bst") - assert(element_list[2].name == "build.bst") - assert(element_list[3].name == "dep-one.bst") - assert(element_list[4].name == "run.bst") - assert(element_list[5].name == "dep-two.bst") - assert(element_list[6].name == "target.bst") + assert(element_list[0] == "build-build.bst") + assert(element_list[1] == "run-build.bst") + assert(element_list[2] == "build.bst") + assert(element_list[3] == "dep-one.bst") + assert(element_list[4] == "run.bst") + assert(element_list[5] == "dep-two.bst") + assert(element_list[6] == "target.bst") -@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate')) -def test_iterate_scope_run(datafiles, tmpdir): - +def test_iterate_scope_run(cli, datafiles, tmpdir): basedir = os.path.join(datafiles.dirname, datafiles.basename) - pipeline = create_pipeline(tmpdir, basedir, 'target.bst') + elements = ['target.bst'] - assert(pipeline.targets[0].get_kind() == "autotools") + element_list = cli.get_pipeline(basedir, elements, scope='run') - assert(isinstance(pipeline.targets[0].commands['configure-commands'], list)) - command_list = pipeline.targets[0].commands['configure-commands'] - assert(len(command_list) == 1) - assert(command_list[0] == 'pony') - - element_list = pipeline.targets[0].dependencies(Scope.RUN) - element_list = list(element_list) assert(len(element_list) == 4) - assert(element_list[0].name == "dep-one.bst") - assert(element_list[1].name == "run.bst") - assert(element_list[2].name == "dep-two.bst") - assert(element_list[3].name == "target.bst") + assert(element_list[0] == "dep-one.bst") + assert(element_list[1] == "run.bst") + assert(element_list[2] == "dep-two.bst") + assert(element_list[3] == "target.bst") -@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate')) -def test_iterate_scope_build(datafiles, tmpdir): - +def test_iterate_scope_build(cli, datafiles, tmpdir): basedir = os.path.join(datafiles.dirname, datafiles.basename) - pipeline = create_pipeline(tmpdir, basedir, 'target.bst') - - assert(pipeline.targets[0].get_kind() == "autotools") + elements = ['target.bst'] - assert(isinstance(pipeline.targets[0].commands['configure-commands'], list)) - command_list = pipeline.targets[0].commands['configure-commands'] - assert(len(command_list) == 1) - assert(command_list[0] == 'pony') - - element_list = pipeline.targets[0].dependencies(Scope.BUILD) - element_list = list(element_list) + element_list = cli.get_pipeline(basedir, elements, scope='build') assert(len(element_list) == 3) - assert(element_list[0].name == "dep-one.bst") - assert(element_list[1].name == "run.bst") - assert(element_list[2].name == "dep-two.bst") + assert(element_list[0] == "dep-one.bst") + assert(element_list[1] == "run.bst") + assert(element_list[2] == "dep-two.bst") -@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate')) -def test_iterate_scope_build_of_child(datafiles, tmpdir): - +def test_iterate_scope_build_of_child(cli, datafiles, tmpdir): basedir = os.path.join(datafiles.dirname, datafiles.basename) - pipeline = create_pipeline(tmpdir, basedir, 'target.bst') + elements = ['target.bst'] - assert(pipeline.targets[0].get_kind() == "autotools") - - assert(isinstance(pipeline.targets[0].commands['configure-commands'], list)) - command_list = pipeline.targets[0].commands['configure-commands'] - assert(len(command_list) == 1) - assert(command_list[0] == 'pony') + element_list = cli.get_pipeline(basedir, elements, scope='build') # First pass, lets check dep-two - element_list = pipeline.targets[0].dependencies(Scope.BUILD) - element_list = list(element_list) element = element_list[2] # Pass two, let's look at these - element_list = element.dependencies(Scope.BUILD) - element_list = list(element_list) + element_list = cli.get_pipeline(basedir, [element], scope='build') assert(len(element_list) == 2) - assert(element_list[0].name == "run-build.bst") - assert(element_list[1].name == "build.bst") + assert(element_list[0] == "run-build.bst") + assert(element_list[1] == "build.bst") + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate')) +def test_iterate_no_recurse(cli, datafiles, tmpdir): + basedir = os.path.join(datafiles.dirname, datafiles.basename) + elements = ['target.bst'] + + # We abuse the 'plan' scope here to ensure that we call + # element.dependencies() with recurse=False - currently, no `bst + # show` option does this directly. + element_list = cli.get_pipeline(basedir, elements, scope='plan') + + assert(len(element_list) == 7) + + assert(element_list[0] == 'build-build.bst') + assert(element_list[1] in ['build.bst', 'run-build.bst']) + assert(element_list[2] in ['build.bst', 'run-build.bst']) + assert(element_list[3] in ['dep-one.bst', 'run.bst', 'dep-two.bst']) + assert(element_list[4] in ['dep-one.bst', 'run.bst', 'dep-two.bst']) + assert(element_list[5] in ['dep-one.bst', 'run.bst', 'dep-two.bst']) + assert(element_list[6] == 'target.bst') ############################################################### # Testing element removal # ############################################################### -@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'remove')) -def test_remove_elements(datafiles, tmpdir): - +def test_remove_elements(cli, datafiles, tmpdir): basedir = os.path.join(datafiles.dirname, datafiles.basename) - pipeline = create_pipeline(tmpdir, basedir, 'build.bst') + elements = ['build.bst'] + except_ = ['second-level-1.bst'] - # Remove second-level-2 and check that the correct dependencies + # Except second-level-2 and check that the correct dependencies # are removed. - element_list = pipeline.targets[0].dependencies(Scope.ALL) - element_list = pipeline.remove_elements(element_list, ['second-level-1.bst']) + element_list = cli.get_pipeline(basedir, elements, except_=except_, scope='all') - assert(set(e.name for e in element_list) == - set(['build.bst', 'third-level-2.bst', 'fourth-level-2.bst', - 'first-level-1.bst', 'first-level-2.bst'])) + assert(element_list[0] == 'fourth-level-2.bst') + assert(element_list[1] == 'third-level-2.bst') + assert(element_list[2] == 'first-level-1.bst') + assert(element_list[3] == 'first-level-2.bst') + assert(element_list[4] == 'build.bst') diff --git a/tests/testutils/runcli.py b/tests/testutils/runcli.py index 0336d8fd5..7cd98ee2e 100644 --- a/tests/testutils/runcli.py +++ b/tests/testutils/runcli.py @@ -1,8 +1,10 @@ import os import sys +import itertools import traceback from contextlib import contextmanager, ExitStack from click.testing import CliRunner +from ruamel import yaml import pytest # Import the main cli entrypoint @@ -131,6 +133,30 @@ class Cli(): assert result.exit_code == 0 return result.output.strip() + # Get the decoded config of an element. + # + def get_element_config(self, project, element_name): + result = self.run(project=project, silent=True, args=[ + 'show', + '--deps', 'none', + '--format', '%{config}', + element_name + ]) + + assert result.exit_code == 0 + return yaml.safe_load(result.output) + + # Fetch the elements that would be in the pipeline with the given + # arguments. + # + def get_pipeline(self, project, elements, except_=[], scope='plan'): + args = ['show', '--deps', scope, '--format', '%{name}'] + args += list(itertools.chain.from_iterable(zip(itertools.repeat('--except'), except_))) + + result = self.run(project=project, silent=True, args=args + elements) + assert result.exit_code == 0 + return result.output.splitlines() + # Main fixture # |