Skip to content
Snippets Groups Projects
Commit 87c4fb2a authored by Chandan Singh's avatar Chandan Singh
Browse files

Add tests for pip source plugin

parent 13c13eca
No related branches found
No related tags found
Loading
Pipeline #26911958 failed
Showing
with 143 additions and 0 deletions
File moved
import os
import pytest
from buildstream import _yaml
from tests.testutils import cli_integration as cli
from tests.testutils.integration import assert_contains
pytestmark = pytest.mark.integration
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"project"
)
@pytest.mark.datafiles(DATA_DIR)
def test_pip_source(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
checkout = os.path.join(cli.directory, 'checkout')
element_path = os.path.join(project, 'elements')
element_name = 'pip/hello.bst'
element = {
'kind': 'import',
'sources': [
{
'kind': 'local',
'path': 'files/pip-source'
},
{
'kind': 'pip',
'python-exe': 'python3',
'index-url': 'file://{}'.format(os.path.realpath(os.path.join(project, 'files', 'pypi-repo'))),
'requirements-files': ['myreqs.txt'],
'packages': ['app2']
}
]
}
os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
_yaml.dump(element, os.path.join(element_path, element_name))
result = cli.run(project=project, args=['track', element_name])
assert result.exit_code == 0
result = cli.run(project=project, args=['build', element_name])
assert result.exit_code == 0
result = cli.run(project=project, args=['checkout', element_name, checkout])
assert result.exit_code == 0
assert_contains(checkout, ['/bin', '/bin/app1', '/bin/app2'])
app1
File added
<html>
<head>
<title>Links for app1</title>
</head>
<body>
<a href='App1-0.1.tar.gz'>App1-0.1.tar.gz</a><br />
</body>
</html>
File added
<html>
<head>
<title>Links for app1</title>
</head>
<body>
<a href='App2-0.1.tar.gz'>App2-0.1.tar.gz</a><br />
</body>
</html>
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)
kind: import
description: pip should not be allowed to be the first source
sources:
- kind: pip
python-exe: python3
packages:
- flake8
Hello World!
kind: import
description: The kind of this element is irrelevant.
sources:
- kind: local
path: file
- kind: pip
python-exe: python3
Hello World!
kind: import
description: The kind of this element is irrelevant.
sources:
- kind: local
path: file
- kind: pip
python-exe: python3
packages:
- flake8
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment