Skip to content
Snippets Groups Projects
Commit a080b6c7 authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

tests/loader/junctions.py: Use Result checking APIs instead of manually

Better to use the same API everywhere for thecking CLI results.
parent 32a101f6
No related branches found
No related tags found
Loading
......@@ -3,7 +3,7 @@ import pytest
import shutil
from buildstream import _yaml, ElementError
from buildstream._exceptions import LoadError, LoadErrorReason
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils import cli, create_repo
from tests.testutils.site import HAVE_GIT
......@@ -38,9 +38,9 @@ def test_simple_build(cli, tmpdir, datafiles):
# Build, checkout
result = cli.run(project=project, args=['build', 'target.bst'])
assert result.exit_code == 0
result.assert_success()
result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
assert result.exit_code == 0
result.assert_success()
# Check that the checkout contains the expected files from both projects
assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))
......@@ -54,7 +54,7 @@ def test_build_of_same_junction_used_twice(cli, tmpdir, datafiles):
# Check we can build a project that contains the same junction
# that is used twice, but named differently
result = cli.run(project=project, args=['build', 'target.bst'])
assert result.exit_code == 0
result.assert_success()
@pytest.mark.datafiles(DATA_DIR)
......@@ -69,9 +69,9 @@ def test_nested_simple(cli, tmpdir, datafiles):
# Build, checkout
result = cli.run(project=project, args=['build', 'target.bst'])
assert result.exit_code == 0
result.assert_success()
result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
assert result.exit_code == 0
result.assert_success()
# Check that the checkout contains the expected files from all subprojects
assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))
......@@ -93,9 +93,9 @@ def test_nested_double(cli, tmpdir, datafiles):
# Build, checkout
result = cli.run(project=project, args=['build', 'target.bst'])
assert result.exit_code == 0
result.assert_success()
result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
assert result.exit_code == 0
result.assert_success()
# Check that the checkout contains the expected files from all subprojects
assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))
......@@ -115,10 +115,7 @@ def test_nested_conflict(cli, datafiles):
copy_subprojects(project, datafiles, ['foo', 'bar'])
result = cli.run(project=project, args=['build', 'target.bst'])
assert result.exit_code != 0
assert result.exception
assert isinstance(result.exception, LoadError)
assert result.exception.reason == LoadErrorReason.CONFLICTING_JUNCTION
result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.CONFLICTING_JUNCTION)
@pytest.mark.datafiles(DATA_DIR)
......@@ -126,10 +123,7 @@ def test_invalid_missing(cli, datafiles):
project = os.path.join(str(datafiles), 'invalid')
result = cli.run(project=project, args=['build', 'missing.bst'])
assert result.exit_code != 0
assert result.exception
assert isinstance(result.exception, LoadError)
assert result.exception.reason == LoadErrorReason.MISSING_FILE
result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE)
@pytest.mark.datafiles(DATA_DIR)
......@@ -138,10 +132,7 @@ def test_invalid_with_deps(cli, datafiles):
copy_subprojects(project, datafiles, ['base'])
result = cli.run(project=project, args=['build', 'junction-with-deps.bst'])
assert result.exit_code != 0
assert result.exception
assert isinstance(result.exception, ElementError)
assert result.exception.reason == 'element-forbidden-depends'
result.assert_main_error(ErrorDomain.ELEMENT, 'element-forbidden-depends')
@pytest.mark.datafiles(DATA_DIR)
......@@ -150,10 +141,7 @@ def test_invalid_junction_dep(cli, datafiles):
copy_subprojects(project, datafiles, ['base'])
result = cli.run(project=project, args=['build', 'junction-dep.bst'])
assert result.exit_code != 0
assert result.exception
assert isinstance(result.exception, LoadError)
assert result.exception.reason == LoadErrorReason.INVALID_DATA
result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
......@@ -165,9 +153,9 @@ def test_options_default(cli, tmpdir, datafiles):
# Build, checkout
result = cli.run(project=project, args=['build', 'target.bst'])
assert result.exit_code == 0
result.assert_success()
result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
assert result.exit_code == 0
result.assert_success()
assert(os.path.exists(os.path.join(checkoutdir, 'pony.txt')))
assert(not os.path.exists(os.path.join(checkoutdir, 'horsy.txt')))
......@@ -182,9 +170,9 @@ def test_options(cli, tmpdir, datafiles):
# Build, checkout
result = cli.run(project=project, args=['build', 'target.bst'])
assert result.exit_code == 0
result.assert_success()
result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
assert result.exit_code == 0
result.assert_success()
assert(not os.path.exists(os.path.join(checkoutdir, 'pony.txt')))
assert(os.path.exists(os.path.join(checkoutdir, 'horsy.txt')))
......@@ -199,9 +187,9 @@ def test_options_inherit(cli, tmpdir, datafiles):
# Build, checkout
result = cli.run(project=project, args=['build', 'target.bst'])
assert result.exit_code == 0
result.assert_success()
result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
assert result.exit_code == 0
result.assert_success()
assert(not os.path.exists(os.path.join(checkoutdir, 'pony.txt')))
assert(os.path.exists(os.path.join(checkoutdir, 'horsy.txt')))
......@@ -228,14 +216,11 @@ def test_git_show(cli, tmpdir, datafiles):
# Verify that bst show does not implicitly fetch subproject
result = cli.run(project=project, args=['show', 'target.bst'])
assert result.exit_code != 0
assert result.exception
assert isinstance(result.exception, LoadError)
assert result.exception.reason == LoadErrorReason.SUBPROJECT_FETCH_NEEDED
result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_FETCH_NEEDED)
# Explicitly fetch subproject
result = cli.run(project=project, args=['source', 'fetch', 'base.bst'])
assert result.exit_code == 0
result.assert_success()
# Check that bst show succeeds now and the pipeline includes the subproject element
element_list = cli.get_pipeline(project, ['target.bst'])
......@@ -263,9 +248,9 @@ def test_git_build(cli, tmpdir, datafiles):
# Build (with implicit fetch of subproject), checkout
result = cli.run(project=project, args=['build', 'target.bst'])
assert result.exit_code == 0
result.assert_success()
result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
assert result.exit_code == 0
result.assert_success()
# Check that the checkout contains the expected files from both projects
assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))
......@@ -304,9 +289,9 @@ def test_build_git_cross_junction_names(cli, tmpdir, datafiles):
# Build (with implicit fetch of subproject), checkout
result = cli.run(project=project, args=['build', 'base.bst:target.bst'])
assert result.exit_code == 0
result.assert_success()
result = cli.run(project=project, args=['checkout', 'base.bst:target.bst', checkoutdir])
assert result.exit_code == 0
result.assert_success()
# Check that the checkout contains the expected files from both projects
assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))
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