diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-14 17:31:26 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-14 17:32:09 +0900 |
commit | ae8543c3b93e565f166b37d9c188d400811e5455 (patch) | |
tree | 6efd339f51c4ae3422b8f24da6339e295ecc944f | |
parent | a4927ad35f9609252d9718a5867eb3ffacebbc56 (diff) | |
download | buildstream-ae8543c3b93e565f166b37d9c188d400811e5455.tar.gz |
tests/format/variables.py: Ported from old style tests
-rw-r--r-- | tests/format/variables.py | 64 | ||||
-rw-r--r-- | tests/format/variables/defaults/autotools.bst (renamed from tests/variables/defaults/autotools.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/defaults/cmake.bst (renamed from tests/variables/defaults/cmake.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/defaults/distutils.bst (renamed from tests/variables/defaults/distutils.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/defaults/makemaker.bst (renamed from tests/variables/defaults/makemaker.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/defaults/modulebuild.bst (renamed from tests/variables/defaults/modulebuild.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/defaults/project.conf (renamed from tests/variables/defaults/project.conf) | 0 | ||||
-rw-r--r-- | tests/format/variables/defaults/qmake.bst (renamed from tests/variables/defaults/qmake.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/overrides/autotools.bst (renamed from tests/variables/overrides/autotools.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/overrides/cmake.bst (renamed from tests/variables/overrides/cmake.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/overrides/distutils.bst (renamed from tests/variables/overrides/distutils.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/overrides/makemaker.bst (renamed from tests/variables/overrides/makemaker.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/overrides/modulebuild.bst (renamed from tests/variables/overrides/modulebuild.bst) | 0 | ||||
-rw-r--r-- | tests/format/variables/overrides/project.conf (renamed from tests/variables/overrides/project.conf) | 0 | ||||
-rw-r--r-- | tests/format/variables/overrides/qmake.bst (renamed from tests/variables/overrides/qmake.bst) | 0 | ||||
-rw-r--r-- | tests/variables/variables.py | 79 |
16 files changed, 64 insertions, 79 deletions
diff --git a/tests/format/variables.py b/tests/format/variables.py new file mode 100644 index 000000000..e4b6297aa --- /dev/null +++ b/tests/format/variables.py @@ -0,0 +1,64 @@ +import os +import pytest +from buildstream import _yaml +from buildstream._exceptions import ErrorDomain, LoadErrorReason +from tests.testutils.runcli import cli + + +# Project directory +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "variables" +) + + +############################################################### +# Test proper loading of some default commands from plugins # +############################################################### +@pytest.mark.parametrize("target,varname,expected", [ + ('autotools.bst', 'make-install', "make -j1 DESTDIR=\"/buildstream-install\" install"), + ('cmake.bst', 'cmake', + "cmake -B_builddir -H. -DCMAKE_INSTALL_PREFIX:PATH=\"/usr\" \\\n" + + "-DCMAKE_INSTALL_LIBDIR=lib "), + ('distutils.bst', 'python-install', + "python3 setup.py install --prefix \"/usr\" \\\n" + + "--root \"/buildstream-install\""), + ('makemaker.bst', 'configure', "perl Makefile.PL PREFIX=/buildstream-install/usr"), + ('modulebuild.bst', 'configure', "perl Build.PL --prefix \"/buildstream-install/usr\""), + ('qmake.bst', 'make-install', "make -j1 INSTALL_ROOT=\"/buildstream-install\" install"), +]) +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'defaults')) +def test_defaults(cli, datafiles, tmpdir, target, varname, expected): + project = os.path.join(datafiles.dirname, datafiles.basename) + result = cli.run(project=project, silent=True, args=[ + 'show', '--deps', 'none', '--format', '%{vars}', target + ]) + result.assert_success() + result_vars = _yaml.load_data(result.output) + assert result_vars[varname] == expected + + +################################################################ +# Test overriding of variables to produce different commands # +################################################################ +@pytest.mark.parametrize("target,varname,expected", [ + ('autotools.bst', 'make-install', "make -j1 DESTDIR=\"/custom/install/root\" install"), + ('cmake.bst', 'cmake', + "cmake -B_builddir -H. -DCMAKE_INSTALL_PREFIX:PATH=\"/opt\" \\\n" + + "-DCMAKE_INSTALL_LIBDIR=lib "), + ('distutils.bst', 'python-install', + "python3 setup.py install --prefix \"/opt\" \\\n" + + "--root \"/custom/install/root\""), + ('makemaker.bst', 'configure', "perl Makefile.PL PREFIX=/custom/install/root/opt"), + ('modulebuild.bst', 'configure', "perl Build.PL --prefix \"/custom/install/root/opt\""), + ('qmake.bst', 'make-install', "make -j1 INSTALL_ROOT=\"/custom/install/root\" install"), +]) +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'overrides')) +def test_overrides(cli, datafiles, tmpdir, target, varname, expected): + project = os.path.join(datafiles.dirname, datafiles.basename) + result = cli.run(project=project, silent=True, args=[ + 'show', '--deps', 'none', '--format', '%{vars}', target + ]) + result.assert_success() + result_vars = _yaml.load_data(result.output) + assert result_vars[varname] == expected diff --git a/tests/variables/defaults/autotools.bst b/tests/format/variables/defaults/autotools.bst index 1fdbc5cd8..1fdbc5cd8 100644 --- a/tests/variables/defaults/autotools.bst +++ b/tests/format/variables/defaults/autotools.bst diff --git a/tests/variables/defaults/cmake.bst b/tests/format/variables/defaults/cmake.bst index 4e7db662c..4e7db662c 100644 --- a/tests/variables/defaults/cmake.bst +++ b/tests/format/variables/defaults/cmake.bst diff --git a/tests/variables/defaults/distutils.bst b/tests/format/variables/defaults/distutils.bst index 2354bea39..2354bea39 100644 --- a/tests/variables/defaults/distutils.bst +++ b/tests/format/variables/defaults/distutils.bst diff --git a/tests/variables/defaults/makemaker.bst b/tests/format/variables/defaults/makemaker.bst index 2205cece1..2205cece1 100644 --- a/tests/variables/defaults/makemaker.bst +++ b/tests/format/variables/defaults/makemaker.bst diff --git a/tests/variables/defaults/modulebuild.bst b/tests/format/variables/defaults/modulebuild.bst index 5b5e9b91a..5b5e9b91a 100644 --- a/tests/variables/defaults/modulebuild.bst +++ b/tests/format/variables/defaults/modulebuild.bst diff --git a/tests/variables/defaults/project.conf b/tests/format/variables/defaults/project.conf index 2027cc27a..2027cc27a 100644 --- a/tests/variables/defaults/project.conf +++ b/tests/format/variables/defaults/project.conf diff --git a/tests/variables/defaults/qmake.bst b/tests/format/variables/defaults/qmake.bst index 53209760d..53209760d 100644 --- a/tests/variables/defaults/qmake.bst +++ b/tests/format/variables/defaults/qmake.bst diff --git a/tests/variables/overrides/autotools.bst b/tests/format/variables/overrides/autotools.bst index 35c62ce8e..35c62ce8e 100644 --- a/tests/variables/overrides/autotools.bst +++ b/tests/format/variables/overrides/autotools.bst diff --git a/tests/variables/overrides/cmake.bst b/tests/format/variables/overrides/cmake.bst index e7fadc42a..e7fadc42a 100644 --- a/tests/variables/overrides/cmake.bst +++ b/tests/format/variables/overrides/cmake.bst diff --git a/tests/variables/overrides/distutils.bst b/tests/format/variables/overrides/distutils.bst index 624f775a5..624f775a5 100644 --- a/tests/variables/overrides/distutils.bst +++ b/tests/format/variables/overrides/distutils.bst diff --git a/tests/variables/overrides/makemaker.bst b/tests/format/variables/overrides/makemaker.bst index faa5f365f..faa5f365f 100644 --- a/tests/variables/overrides/makemaker.bst +++ b/tests/format/variables/overrides/makemaker.bst diff --git a/tests/variables/overrides/modulebuild.bst b/tests/format/variables/overrides/modulebuild.bst index db50057e2..db50057e2 100644 --- a/tests/variables/overrides/modulebuild.bst +++ b/tests/format/variables/overrides/modulebuild.bst diff --git a/tests/variables/overrides/project.conf b/tests/format/variables/overrides/project.conf index 2027cc27a..2027cc27a 100644 --- a/tests/variables/overrides/project.conf +++ b/tests/format/variables/overrides/project.conf diff --git a/tests/variables/overrides/qmake.bst b/tests/format/variables/overrides/qmake.bst index 5dff2c944..5dff2c944 100644 --- a/tests/variables/overrides/qmake.bst +++ b/tests/format/variables/overrides/qmake.bst diff --git a/tests/variables/variables.py b/tests/variables/variables.py deleted file mode 100644 index 233ea5c1f..000000000 --- a/tests/variables/variables.py +++ /dev/null @@ -1,79 +0,0 @@ -import os -import pytest - -from buildstream import BuildElement -from buildstream._context import Context -from buildstream._project import Project -from buildstream._pipeline import Pipeline - -DATA_DIR = os.path.join( - os.path.dirname(os.path.realpath(__file__)), -) - - -def create_pipeline(tmpdir, basedir, target): - context = Context() - project = Project(basedir, context) - context.artifactdir = os.path.join(str(tmpdir), 'artifact') - - def dummy_handler(message, context): - pass - - context.set_message_handler(dummy_handler) - - return Pipeline(context, project, [target], []) - - -def assert_command(datafiles, tmpdir, target, command, expected): - basedir = os.path.join(datafiles.dirname, datafiles.basename) - pipeline = create_pipeline(tmpdir, basedir, target) - assert(isinstance(pipeline.targets[0], BuildElement)) - - commands = pipeline.targets[0].commands - assert(commands.get(command) is not None) - assert(len(commands[command]) > 0) - - print("Commands:\n{}".format(commands[command][0])) - print("Expected:\n{}".format(expected)) - - assert(commands[command][0] == expected) - - -############################################################### -# Test proper loading of some default commands from plugins # -############################################################### -@pytest.mark.parametrize("target,command,expected", [ - ('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/buildstream-install\" install"), - ('cmake.bst', 'configure-commands', - "cmake -B_builddir -H. -DCMAKE_INSTALL_PREFIX:PATH=\"/usr\" \\\n" + - "-DCMAKE_INSTALL_LIBDIR=lib"), - ('distutils.bst', 'install-commands', - "python3 setup.py install --prefix \"/usr\" \\\n" + - "--root \"/buildstream-install\""), - ('makemaker.bst', 'configure-commands', "perl Makefile.PL PREFIX=/buildstream-install/usr"), - ('modulebuild.bst', 'configure-commands', "perl Build.PL --prefix \"/buildstream-install/usr\""), - ('qmake.bst', 'install-commands', "make -j1 INSTALL_ROOT=\"/buildstream-install\" install"), -]) -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'defaults')) -def test_defaults(datafiles, tmpdir, target, command, expected): - assert_command(datafiles, tmpdir, target, command, expected) - - -################################################################ -# Test overriding of variables to produce different commands # -################################################################ -@pytest.mark.parametrize("target,command,expected", [ - ('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/custom/install/root\" install"), - ('cmake.bst', 'configure-commands', - "cmake -B_builddir -H. -DCMAKE_INSTALL_PREFIX:PATH=\"/opt\" \\\n" + - "-DCMAKE_INSTALL_LIBDIR=lib"), - ('distutils.bst', 'install-commands', - "python3 setup.py install --prefix \"/opt\" \\\n" + - "--root \"/custom/install/root\""), - ('makemaker.bst', 'configure-commands', "perl Makefile.PL PREFIX=/custom/install/root/opt"), - ('modulebuild.bst', 'configure-commands', "perl Build.PL --prefix \"/custom/install/root/opt\""), - ('qmake.bst', 'install-commands', "make -j1 INSTALL_ROOT=\"/custom/install/root\" install"), -]) -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'overrides')) -def test_overrides(datafiles, tmpdir, target, command, expected): - assert_command(datafiles, tmpdir, target, command, expected) |