diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-10-07 19:09:40 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-10-10 19:29:59 +0900 |
commit | 7c152594e563ec93b4258e45685283ce3717c0a3 (patch) | |
tree | f281a59a481800905602f65d7d5a687c16418c3a /tests/format | |
parent | 6819bb8c50126538ce8877b8f8c5fb98120001db (diff) | |
download | buildstream-7c152594e563ec93b4258e45685283ce3717c0a3.tar.gz |
tests/format/optionarch.py: Added arch option specific test cases
Diffstat (limited to 'tests/format')
-rw-r--r-- | tests/format/option-arch/element.bst | 8 | ||||
-rw-r--r-- | tests/format/option-arch/project.conf | 9 | ||||
-rw-r--r-- | tests/format/optionarch.py | 80 |
3 files changed, 97 insertions, 0 deletions
diff --git a/tests/format/option-arch/element.bst b/tests/format/option-arch/element.bst new file mode 100644 index 000000000..4da01d889 --- /dev/null +++ b/tests/format/option-arch/element.bst @@ -0,0 +1,8 @@ +kind: autotools +variables: + result: "Nothing" + (?): + - machine_arch == "arm": + result: "Army" + - machine_arch == "aarch64": + result: "Aarchy" diff --git a/tests/format/option-arch/project.conf b/tests/format/option-arch/project.conf new file mode 100644 index 000000000..a2c3ddf9a --- /dev/null +++ b/tests/format/option-arch/project.conf @@ -0,0 +1,9 @@ +name: test + +options: + machine_arch: + type: arch + description: The machine architecture + values: + - arm + - aarch64 diff --git a/tests/format/optionarch.py b/tests/format/optionarch.py new file mode 100644 index 000000000..fce689800 --- /dev/null +++ b/tests/format/optionarch.py @@ -0,0 +1,80 @@ +import os +import pytest +from contextlib import contextmanager +from buildstream import _yaml +from buildstream import LoadError, LoadErrorReason +from tests.testutils.runcli import cli + +# Project directory +DATA_DIR = os.path.dirname(os.path.realpath(__file__)) + + +# Context manager to override the reported value of `os.uname()` +@contextmanager +def override_uname_arch(name): + orig_uname = os.uname + orig_tuple = tuple(os.uname()) + override_result = (orig_tuple[0], orig_tuple[1], + orig_tuple[2], orig_tuple[3], + name) + + def override(): + return override_result + + os.uname = override + yield + os.uname = orig_uname + + +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.parametrize("uname,value,expected", [ + # Test explicitly provided arches + ('arm', 'arm', 'Army'), + ('arm', 'aarch64', 'Aarchy'), + + # Test automatically derived arches + ('arm', None, 'Army'), + ('aarch64', None, 'Aarchy'), + + # Test that explicitly provided arches dont error out + # when the `uname` reported arch is not supported + ('i386', 'arm', 'Army'), + ('x86_64', 'aarch64', 'Aarchy'), +]) +def test_conditional(cli, datafiles, uname, value, expected): + with override_uname_arch(uname): + project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch') + + bst_args = [] + if value is not None: + bst_args += ['--option', 'machine_arch', value] + + bst_args += [ + 'show', + '--deps', 'none', + '--format', '%{vars}', + 'element.bst' + ] + result = cli.run(project=project, silent=True, args=bst_args) + + assert result.exit_code == 0 + loaded = _yaml.load_data(result.output) + assert loaded['result'] == expected + + +@pytest.mark.datafiles(DATA_DIR) +def test_unsupported_arch(cli, datafiles): + + with override_uname_arch("x86_64"): + project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch') + result = cli.run(project=project, silent=True, args=[ + 'show', + '--deps', 'none', + '--format', '%{vars}', + 'element.bst' + ]) + + assert result.exit_code != 0 + assert result.exception + assert isinstance(result.exception, LoadError) + assert result.exception.reason == LoadErrorReason.INVALID_DATA |