diff options
-rw-r--r-- | tests/frontend/progress.py | 139 | ||||
-rw-r--r-- | tests/frontend/project/files/sub-project/files/deps.bst | 1 | ||||
-rw-r--r-- | tests/frontend/project/files/sub2-project/elements/import-sub.bst | 4 | ||||
-rw-r--r-- | tests/frontend/project/files/sub2-project/files/etc-files/etc/animal.conf | 1 | ||||
-rw-r--r-- | tests/frontend/project/files/sub2-project/project.conf | 4 | ||||
-rw-r--r-- | tests/frontend/show.py | 44 |
6 files changed, 149 insertions, 44 deletions
diff --git a/tests/frontend/progress.py b/tests/frontend/progress.py new file mode 100644 index 000000000..e3b127f3b --- /dev/null +++ b/tests/frontend/progress.py @@ -0,0 +1,139 @@ +# Pylint doesn't play well with fixtures and dependency injection from pytest +# pylint: disable=redefined-outer-name + +import os +import pytest + +from buildstream.testing import cli # pylint: disable=unused-import +from buildstream import _yaml +from buildstream._exceptions import ErrorDomain, LoadErrorReason + +from tests.testutils import generate_junction + +# Project directory +DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), ) + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project')) +def test_show_progress_tally(cli, datafiles): + # Check that the progress reporting messages give correct tallies + project = str(datafiles) + result = cli.run(project=project, args=['show', 'compose-all.bst']) + result.assert_success() + assert " 3 subtasks processed" in result.stderr + assert "3 of 3 subtasks processed" in result.stderr + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project')) +def test_junction_tally(cli, tmpdir, datafiles): + # Check that the progress reporting messages count elements in junctions + project = str(datafiles) + subproject_path = os.path.join(project, 'files', 'sub-project') + junction_path = os.path.join(project, 'elements', 'junction.bst') + element_path = os.path.join(project, 'elements', 'junction-dep.bst') + + # Create a repo to hold the subproject and generate a junction element for it + generate_junction(tmpdir, subproject_path, junction_path, store_ref=True) + + # Create a stack element to depend on a cross junction element + # + element = { + 'kind': 'stack', + 'depends': [{ + 'junction': 'junction.bst', + 'filename': 'import-etc.bst' + }] + } + _yaml.roundtrip_dump(element, element_path) + + result = cli.run(project=project, + silent=True, + args=['source', 'fetch', 'junction.bst']) + result.assert_success() + + # Assert the correct progress tallies are in the logging + result = cli.run(project=project, args=['show', 'junction-dep.bst']) + assert " 2 subtasks processed" in result.stderr + assert "2 of 2 subtasks processed" in result.stderr + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project')) +def test_nested_junction_tally(cli, tmpdir, datafiles): + # Check that the progress reporting messages count elements in + # junctions of junctions + project = str(datafiles) + sub1_path = os.path.join(project, 'files', 'sub-project') + sub2_path = os.path.join(project, 'files', 'sub2-project') + # A junction element which pulls sub1 into sub2 + sub1_element = os.path.join(project, 'files', 'sub2-project', 'elements', 'sub-junction.bst') + # A junction element which pulls sub2 into the main project + sub2_element = os.path.join(project, 'elements', 'junction.bst') + element_path = os.path.join(project, 'elements', 'junction-dep.bst') + + generate_junction(tmpdir / "sub-project", sub1_path, sub1_element, store_ref=True) + generate_junction(tmpdir / "sub2-project", sub2_path, sub2_element, store_ref=True) + + # Create a stack element to depend on a cross junction element + # + element = { + 'kind': 'stack', + 'depends': [{ + 'junction': 'junction.bst', + 'filename': 'import-sub.bst' + }] + } + _yaml.roundtrip_dump(element, element_path) + + result = cli.run(project=project, + silent=True, + args=['source', 'fetch', 'junction.bst']) + result.assert_success() + + # Assert the correct progress tallies are in the logging + result = cli.run(project=project, args=['show', 'junction-dep.bst']) + assert " 3 subtasks processed" in result.stderr + assert "3 of 3 subtasks processed" in result.stderr + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project')) +def test_junction_dep_tally(cli, tmpdir, datafiles): + # Check that the progress reporting messages count elements in junctions + project = str(datafiles) + subproject_path = os.path.join(project, 'files', 'sub-project') + junction_path = os.path.join(project, 'elements', 'junction.bst') + element_path = os.path.join(project, 'elements', 'junction-dep.bst') + + # Create a repo to hold the subproject and generate a junction element for it + generate_junction(tmpdir, subproject_path, junction_path, store_ref=True) + + # Add dependencies to the junction (not allowed, but let's do it + # anyway) + with open(junction_path, 'a') as f: + deps = { + 'depends': [ + 'manual.bst' + ] + } + _yaml.roundtrip_dump(deps, f) + + # Create a stack element to depend on a cross junction element + # + element = { + 'kind': 'stack', + 'depends': [{ + 'junction': 'junction.bst', + 'filename': 'import-etc.bst' + }] + } + _yaml.roundtrip_dump(element, element_path) + + result = cli.run(project=project, + silent=True, + args=['source', 'fetch', 'junction-dep.bst']) + + # Since we aren't allowed to specify any dependencies on a + # junction, we should fail + result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_JUNCTION) + + # We don't get a final tally in this case + assert "subtasks processed" not in result.stderr diff --git a/tests/frontend/project/files/sub-project/files/deps.bst b/tests/frontend/project/files/sub-project/files/deps.bst new file mode 100644 index 000000000..abd99305d --- /dev/null +++ b/tests/frontend/project/files/sub-project/files/deps.bst @@ -0,0 +1 @@ +- import-etc.bst diff --git a/tests/frontend/project/files/sub2-project/elements/import-sub.bst b/tests/frontend/project/files/sub2-project/elements/import-sub.bst new file mode 100644 index 000000000..ded8fcb23 --- /dev/null +++ b/tests/frontend/project/files/sub2-project/elements/import-sub.bst @@ -0,0 +1,4 @@ +kind: stack +depends: + - junction: 'sub-junction.bst' + filename: 'import-etc.bst' diff --git a/tests/frontend/project/files/sub2-project/files/etc-files/etc/animal.conf b/tests/frontend/project/files/sub2-project/files/etc-files/etc/animal.conf new file mode 100644 index 000000000..db8c36cba --- /dev/null +++ b/tests/frontend/project/files/sub2-project/files/etc-files/etc/animal.conf @@ -0,0 +1 @@ +animal=Pony diff --git a/tests/frontend/project/files/sub2-project/project.conf b/tests/frontend/project/files/sub2-project/project.conf new file mode 100644 index 000000000..bbb8414a3 --- /dev/null +++ b/tests/frontend/project/files/sub2-project/project.conf @@ -0,0 +1,4 @@ +# Project config for frontend build test +name: subtest + +element-path: elements diff --git a/tests/frontend/show.py b/tests/frontend/show.py index 0d444a925..bc51d2967 100644 --- a/tests/frontend/show.py +++ b/tests/frontend/show.py @@ -40,16 +40,6 @@ def test_show(cli, datafiles, target, fmt, expected): .format(expected, result.output)) -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project')) -def test_show_progress_tally(cli, datafiles): - # Check that the progress reporting messages give correct tallies - project = str(datafiles) - result = cli.run(project=project, args=['show', 'compose-all.bst']) - result.assert_success() - assert " 3 subtasks processed" in result.stderr - assert "3 of 3 subtasks processed" in result.stderr - - @pytest.mark.datafiles(os.path.join( os.path.dirname(os.path.realpath(__file__)), "invalid_element_path", @@ -397,40 +387,6 @@ def test_fetched_junction(cli, tmpdir, datafiles, element_name, workspaced): assert 'junction.bst:import-etc.bst-buildable' in results -@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project')) -def test_junction_tally(cli, tmpdir, datafiles): - # Check that the progress reporting messages count elements in junctions - project = str(datafiles) - subproject_path = os.path.join(project, 'files', 'sub-project') - junction_path = os.path.join(project, 'elements', 'junction.bst') - element_path = os.path.join(project, 'elements', 'junction-dep.bst') - - # Create a repo to hold the subproject and generate a junction element for it - generate_junction(tmpdir, subproject_path, junction_path, store_ref=True) - - # Create a stack element to depend on a cross junction element - # - element = { - 'kind': 'stack', - 'depends': [ - { - 'junction': 'junction.bst', - 'filename': 'import-etc.bst' - } - ] - } - _yaml.roundtrip_dump(element, element_path) - - result = cli.run(project=project, silent=True, args=[ - 'source', 'fetch', 'junction.bst']) - result.assert_success() - - # Assert the correct progress tallies are in the logging - result = cli.run(project=project, args=['show', 'junction-dep.bst']) - assert " 2 subtasks processed" in result.stderr - assert "2 of 2 subtasks processed" in result.stderr - - ############################################################### # Testing recursion depth # ############################################################### |