diff options
author | Benjamin Schubert <contact@benschubert.me> | 2020-05-12 12:13:05 +0000 |
---|---|---|
committer | Benjamin Schubert <contact@benschubert.me> | 2020-05-12 15:52:00 +0000 |
commit | 830e2142ff9f2688c04119df5be8efebc2649dca (patch) | |
tree | 9ffca9cc20d5f5651f6486553637e6d89b47bf4b /tests/sources | |
parent | 1ff22fb98d58f1264a2af0650e40dcaaaa99dabc (diff) | |
download | buildstream-830e2142ff9f2688c04119df5be8efebc2649dca.tar.gz |
source.py: Allow access to element's variable
This automatically expands the variables from the element into
the sources config
Diffstat (limited to 'tests/sources')
-rw-r--r-- | tests/sources/variables.py | 35 | ||||
-rw-r--r-- | tests/sources/variables/folder/file.txt | 1 | ||||
-rw-r--r-- | tests/sources/variables/project.conf | 3 | ||||
-rw-r--r-- | tests/sources/variables/target.bst | 9 | ||||
-rw-r--r-- | tests/sources/variables/unresolveable-target.bst | 6 |
5 files changed, 54 insertions, 0 deletions
diff --git a/tests/sources/variables.py b/tests/sources/variables.py new file mode 100644 index 000000000..3e9a08fd8 --- /dev/null +++ b/tests/sources/variables.py @@ -0,0 +1,35 @@ +# Pylint doesn't play well with fixtures and dependency injection from pytest +# pylint: disable=redefined-outer-name + +import os + +import pytest + +from buildstream.exceptions import ErrorDomain, LoadErrorReason +from buildstream.testing.runcli import cli # pylint: disable=unused-import + + +DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "variables") + + +@pytest.mark.datafiles(DATA_DIR) +def test_variables_are_resolved(cli, tmpdir, datafiles): + project = str(datafiles) + checkoutdir = os.path.join(str(tmpdir), "checkout") + + # Build, checkout + result = cli.run(project=project, args=["build", "target.bst"]) + result.assert_success() + result = cli.run(project=project, args=["artifact", "checkout", "target.bst", "--directory", checkoutdir]) + result.assert_success() + + # Check that the checkout contains the expected file + assert os.path.exists(os.path.join(checkoutdir, "file.txt")) + + +@pytest.mark.datafiles(DATA_DIR) +def test_handles_unresolved_variables(cli, tmpdir, datafiles): + project = str(datafiles) + + result = cli.run(project=project, args=["build", "unresolveable-target.bst"]) + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.UNRESOLVED_VARIABLE) diff --git a/tests/sources/variables/folder/file.txt b/tests/sources/variables/folder/file.txt new file mode 100644 index 000000000..a496efee8 --- /dev/null +++ b/tests/sources/variables/folder/file.txt @@ -0,0 +1 @@ +This is a text file diff --git a/tests/sources/variables/project.conf b/tests/sources/variables/project.conf new file mode 100644 index 000000000..dc34380a4 --- /dev/null +++ b/tests/sources/variables/project.conf @@ -0,0 +1,3 @@ +# Basic project +name: foo +min-version: 2.0 diff --git a/tests/sources/variables/target.bst b/tests/sources/variables/target.bst new file mode 100644 index 000000000..0b492fdf3 --- /dev/null +++ b/tests/sources/variables/target.bst @@ -0,0 +1,9 @@ +kind: import +description: This is the pony + +sources: +- kind: local + path: "%{my-folder}/file.txt" + +variables: + my-folder: folder diff --git a/tests/sources/variables/unresolveable-target.bst b/tests/sources/variables/unresolveable-target.bst new file mode 100644 index 000000000..b6ce77363 --- /dev/null +++ b/tests/sources/variables/unresolveable-target.bst @@ -0,0 +1,6 @@ +kind: import +description: This is the pony + +sources: +- kind: local + path: "%{my-folder}/file.txt" |