This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/optional-project
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 2e533b3d8c58aa2100cb456ffaceb472416b097e
Author: Tristan van Berkom <[email protected]>
AuthorDate: Thu Jan 14 16:20:34 2021 +0900

    tests/frontend/artifact_list_contents.py: Test listing artifact content 
without a project
---
 tests/frontend/artifact_list_contents.py | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/tests/frontend/artifact_list_contents.py 
b/tests/frontend/artifact_list_contents.py
index 6110d83..5003755 100644
--- a/tests/frontend/artifact_list_contents.py
+++ b/tests/frontend/artifact_list_contents.py
@@ -22,6 +22,7 @@ import os
 import pytest
 
 from buildstream.testing import cli  # pylint: disable=unused-import
+from buildstream.exceptions import ErrorDomain
 
 
 # Project directory
@@ -30,7 +31,8 @@ DATA_DIR = 
os.path.join(os.path.dirname(os.path.realpath(__file__)), "project",)
 
 @pytest.mark.datafiles(DATA_DIR)
 @pytest.mark.parametrize("target", ["element-name", "artifact-name"])
-def test_artifact_list_exact_contents(cli, datafiles, target):
[email protected]("with_project", [True, False], ids=["with-project", 
"without-project"])
+def test_artifact_list_exact_contents(cli, datafiles, target, with_project):
     project = str(datafiles)
 
     # Get the cache key of our test element
@@ -38,7 +40,7 @@ def test_artifact_list_exact_contents(cli, datafiles, target):
 
     # Ensure we have an artifact to read
     result = cli.run(project=project, args=["build", "import-bin.bst"])
-    assert result.exit_code == 0
+    result.assert_success()
 
     if target == "element-name":
         arg = "import-bin.bst"
@@ -46,14 +48,22 @@ def test_artifact_list_exact_contents(cli, datafiles, 
target):
         key = cli.get_element_key(project, "import-bin.bst")
         arg = "test/import-bin/" + key
 
+    # Delete the project.conf if we're going to try this without a project
+    if not with_project:
+        os.remove(os.path.join(project, "project.conf"))
+
     # List the contents via the key
     result = cli.run(project=project, args=["artifact", "list-contents", arg])
-    assert result.exit_code == 0
 
-    expected_output_template = 
"{target}:\n\tusr\n\tusr/bin\n\tusr/bin/hello\n\n"
-    expected_output = expected_output_template.format(target=arg)
+    # Expect to fail if we try to list by element name and there is no project
+    if target == "element-name" and not with_project:
+        result.assert_main_error(ErrorDomain.STREAM, "project-not-loaded")
+    else:
+        result.assert_success()
 
-    assert expected_output in result.output
+        expected_output_template = 
"{target}:\n\tusr\n\tusr/bin\n\tusr/bin/hello\n\n"
+        expected_output = expected_output_template.format(target=arg)
+        assert expected_output in result.output
 
 
 @pytest.mark.datafiles(DATA_DIR)

Reply via email to