diff options
author | Chandan Singh <csingh43@bloomberg.net> | 2018-07-30 19:41:57 +0100 |
---|---|---|
committer | Chandan Singh <csingh43@bloomberg.net> | 2018-08-15 19:23:04 +0100 |
commit | a7a8265090eaba5cb99fec7ad9acbadb84e998de (patch) | |
tree | 4c50fcebe239766250e978a1eefd26c269555679 /tests/sources | |
parent | 9d2442b2794d7a531f50b3f1f9a0c6e4236bd9be (diff) | |
download | buildstream-a7a8265090eaba5cb99fec7ad9acbadb84e998de.tar.gz |
Add pip source plugin
`pip` source plugin can stage python packages that are either specified
directly in the element definition or picked up from `requirements.txt`
from previous sources. In order to support the latter use-case
(which is also the primary motivation for this plugin), this plugin
requires access to previous sources and hence is an example of a
Source Transform source.
Also, bump `BST_FORMAT_VERSION` as this patch adds a new core plugin.
Diffstat (limited to 'tests/sources')
-rw-r--r-- | tests/sources/pip.py | 47 | ||||
-rw-r--r-- | tests/sources/pip/first-source-pip/target.bst | 6 | ||||
-rw-r--r-- | tests/sources/pip/no-packages/file | 1 | ||||
-rw-r--r-- | tests/sources/pip/no-packages/target.bst | 6 | ||||
-rw-r--r-- | tests/sources/pip/no-ref/file | 1 | ||||
-rw-r--r-- | tests/sources/pip/no-ref/target.bst | 8 |
6 files changed, 69 insertions, 0 deletions
diff --git a/tests/sources/pip.py b/tests/sources/pip.py new file mode 100644 index 000000000..8b4c213dc --- /dev/null +++ b/tests/sources/pip.py @@ -0,0 +1,47 @@ +import os +import pytest + +from buildstream._exceptions import ErrorDomain +from buildstream import _yaml +from tests.testutils import cli + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'pip', +) + + +def generate_project(project_dir, tmpdir): + project_file = os.path.join(project_dir, "project.conf") + _yaml.dump({'name': 'foo'}, project_file) + + +# Test that without ref, consistency is set appropriately. +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'no-ref')) +def test_no_ref(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + generate_project(project, tmpdir) + assert cli.get_element_state(project, 'target.bst') == 'no reference' + + +# Test that pip is not allowed to be the first source +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'first-source-pip')) +def test_first_source(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + generate_project(project, tmpdir) + result = cli.run(project=project, args=[ + 'show', 'target.bst' + ]) + result.assert_main_error(ErrorDomain.ELEMENT, None) + + +# Test that error is raised when neither packges nor requirements files +# have been specified +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'no-packages')) +def test_no_packages(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + generate_project(project, tmpdir) + result = cli.run(project=project, args=[ + 'show', 'target.bst' + ]) + result.assert_main_error(ErrorDomain.SOURCE, None) diff --git a/tests/sources/pip/first-source-pip/target.bst b/tests/sources/pip/first-source-pip/target.bst new file mode 100644 index 000000000..e5f20ab0b --- /dev/null +++ b/tests/sources/pip/first-source-pip/target.bst @@ -0,0 +1,6 @@ +kind: import +description: pip should not be allowed to be the first source +sources: +- kind: pip + packages: + - flake8 diff --git a/tests/sources/pip/no-packages/file b/tests/sources/pip/no-packages/file new file mode 100644 index 000000000..980a0d5f1 --- /dev/null +++ b/tests/sources/pip/no-packages/file @@ -0,0 +1 @@ +Hello World! diff --git a/tests/sources/pip/no-packages/target.bst b/tests/sources/pip/no-packages/target.bst new file mode 100644 index 000000000..0d8b948c4 --- /dev/null +++ b/tests/sources/pip/no-packages/target.bst @@ -0,0 +1,6 @@ +kind: import +description: The kind of this element is irrelevant. +sources: +- kind: local + path: file +- kind: pip diff --git a/tests/sources/pip/no-ref/file b/tests/sources/pip/no-ref/file new file mode 100644 index 000000000..980a0d5f1 --- /dev/null +++ b/tests/sources/pip/no-ref/file @@ -0,0 +1 @@ +Hello World! diff --git a/tests/sources/pip/no-ref/target.bst b/tests/sources/pip/no-ref/target.bst new file mode 100644 index 000000000..ec450b7ef --- /dev/null +++ b/tests/sources/pip/no-ref/target.bst @@ -0,0 +1,8 @@ +kind: import +description: The kind of this element is irrelevant. +sources: +- kind: local + path: file +- kind: pip + packages: + - flake8 |