Commit 8d676a84 authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

tests: Migrate dependencies test to tests/format

This used to be an internal test, converted this to use the `cli` fixture.
parent f712aaa5
Loading
Loading
Loading
Loading
+133 −0
Original line number Diff line number Diff line
import os
import pytest

from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils import cli

DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    'dependencies',
)


@pytest.mark.datafiles(DATA_DIR)
def test_two_files(cli, datafiles):
    project = str(datafiles)

    elements = cli.get_pipeline(project, ['target.bst'])
    assert elements == ['firstdep.bst', 'target.bst']


@pytest.mark.datafiles(DATA_DIR)
def test_shared_dependency(cli, datafiles):
    project = str(datafiles)

    elements = cli.get_pipeline(project, ['shareddeptarget.bst'])
    assert elements == ['firstdep.bst', 'shareddep.bst', 'shareddeptarget.bst']


@pytest.mark.datafiles(DATA_DIR)
def test_dependency_dict(cli, datafiles):
    project = str(datafiles)
    elements = cli.get_pipeline(project, ['target-depdict.bst'])
    assert elements == ['firstdep.bst', 'target-depdict.bst']


@pytest.mark.datafiles(DATA_DIR)
def test_invalid_dependency_declaration(cli, datafiles):
    project = str(datafiles)
    result = cli.run(project=project, args=['show', 'invaliddep.bst'])
    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)


@pytest.mark.datafiles(DATA_DIR)
def test_invalid_dependency_type(cli, datafiles):
    project = str(datafiles)
    result = cli.run(project=project, args=['show', 'invaliddeptype.bst'])
    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)


@pytest.mark.datafiles(DATA_DIR)
def test_circular_dependency(cli, datafiles):
    project = str(datafiles)
    result = cli.run(project=project, args=['show', 'circulartarget.bst'])
    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.CIRCULAR_DEPENDENCY)


@pytest.mark.datafiles(DATA_DIR)
def test_build_dependency(cli, datafiles):
    project = str(datafiles)

    elements = cli.get_pipeline(project, ['builddep.bst'], scope='run')
    assert elements == ['builddep.bst']

    elements = cli.get_pipeline(project, ['builddep.bst'], scope='build')
    assert elements == ['firstdep.bst']


@pytest.mark.datafiles(DATA_DIR)
def test_runtime_dependency(cli, datafiles):
    project = str(datafiles)
    elements = cli.get_pipeline(project, ['runtimedep.bst'], scope='build')

    # FIXME: The empty line should probably never happen here when there are no results.
    assert elements == ['']
    elements = cli.get_pipeline(project, ['runtimedep.bst'], scope='run')
    assert elements == ['firstdep.bst', 'runtimedep.bst']


@pytest.mark.datafiles(DATA_DIR)
def test_all_dependency(cli, datafiles):
    project = str(datafiles)

    elements = cli.get_pipeline(project, ['alldep.bst'], scope='build')
    assert elements == ['firstdep.bst']

    elements = cli.get_pipeline(project, ['alldep.bst'], scope='run')
    assert elements == ['firstdep.bst', 'alldep.bst']


@pytest.mark.datafiles(DATA_DIR)
def test_list_build_dependency(cli, datafiles):
    project = str(datafiles)

    # Check that the pipeline includes the build dependency
    deps = cli.get_pipeline(project, ['builddep-list.bst'], scope="build")
    assert "firstdep.bst" in deps


@pytest.mark.datafiles(DATA_DIR)
def test_list_runtime_dependency(cli, datafiles):
    project = str(datafiles)

    # Check that the pipeline includes the runtime dependency
    deps = cli.get_pipeline(project, ['runtimedep-list.bst'], scope="run")
    assert "firstdep.bst" in deps


@pytest.mark.datafiles(DATA_DIR)
def test_list_dependencies_combined(cli, datafiles):
    project = str(datafiles)

    # Check that runtime deps get combined
    rundeps = cli.get_pipeline(project, ['list-combine.bst'], scope="run")
    assert "firstdep.bst" not in rundeps
    assert "seconddep.bst" in rundeps
    assert "thirddep.bst" in rundeps

    # Check that build deps get combined
    builddeps = cli.get_pipeline(project, ['list-combine.bst'], scope="build")
    assert "firstdep.bst" in builddeps
    assert "seconddep.bst" not in builddeps
    assert "thirddep.bst" in builddeps


@pytest.mark.datafiles(DATA_DIR)
def test_list_overlap(cli, datafiles):
    project = str(datafiles)

    # Check that dependencies get merged
    rundeps = cli.get_pipeline(project, ['list-overlap.bst'], scope="run")
    assert "firstdep.bst" in rundeps
    builddeps = cli.get_pipeline(project, ['list-overlap.bst'], scope="build")
    assert "firstdep.bst" in builddeps
+2 −2
Original line number Diff line number Diff line
kind: pony
kind: manual
description: This element has a dependency with type 'all'
depends:
  - filename: elements/firstdep.bst
  - filename: firstdep.bst
    type: all
+1 −1
Original line number Diff line number Diff line
kind: stack
description: This element has a build-only dependency specified via build-depends
build-depends:
  - elements/firstdep.bst
  - firstdep.bst
+2 −2
Original line number Diff line number Diff line
kind: pony
kind: manual
description: This element has a build-only dependency
depends:
  - filename: elements/firstdep.bst
  - filename: firstdep.bst
    type: build
+2 −2
Original line number Diff line number Diff line
kind: pony
kind: manual
description: Depend on another dep which depends on the target
depends:
- elements/circular-seconddep.bst
- circular-seconddep.bst
Loading