You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/01/14 07:31:09 UTC
[buildstream] 02/08: tests/frontend/artifact_list_contents.py: Use
parametrized tests
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 b48e14ce1bfbf6fddc464b1202acead3c3b500c9
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Thu Jan 14 15:46:11 2021 +0900
tests/frontend/artifact_list_contents.py: Use parametrized tests
Small refactor to reduce code duplication here
---
tests/frontend/artifact_list_contents.py | 91 ++++++++++++--------------------
1 file changed, 34 insertions(+), 57 deletions(-)
diff --git a/tests/frontend/artifact_list_contents.py b/tests/frontend/artifact_list_contents.py
index ee129cc..6110d83 100644
--- a/tests/frontend/artifact_list_contents.py
+++ b/tests/frontend/artifact_list_contents.py
@@ -29,36 +29,59 @@ DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project",)
@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_list_exact_contents_element(cli, datafiles):
+@pytest.mark.parametrize("target", ["element-name", "artifact-name"])
+def test_artifact_list_exact_contents(cli, datafiles, target):
project = str(datafiles)
+ # Get the cache key of our test element
+ key = cli.get_element_key(project, "import-bin.bst")
+
# Ensure we have an artifact to read
result = cli.run(project=project, args=["build", "import-bin.bst"])
assert result.exit_code == 0
- # List the contents via the element name
- result = cli.run(project=project, args=["artifact", "list-contents", "import-bin.bst"])
+ if target == "element-name":
+ arg = "import-bin.bst"
+ elif target == "artifact-name":
+ key = cli.get_element_key(project, "import-bin.bst")
+ arg = "test/import-bin/" + key
+
+ # List the contents via the key
+ result = cli.run(project=project, args=["artifact", "list-contents", arg])
assert result.exit_code == 0
- expected_output = "import-bin.bst:\n\tusr\n\tusr/bin\n\tusr/bin/hello\n\n"
+
+ 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)
-def test_artifact_list_exact_contents_ref(cli, datafiles):
+@pytest.mark.parametrize("target", ["element-name", "artifact-name"])
+def test_artifact_list_exact_contents_long(cli, datafiles, target):
project = str(datafiles)
- # Get the cache key of our test element
- key = cli.get_element_key(project, "import-bin.bst")
-
# Ensure we have an artifact to read
result = cli.run(project=project, args=["build", "import-bin.bst"])
assert result.exit_code == 0
- # List the contents via the key
- result = cli.run(project=project, args=["artifact", "list-contents", "test/import-bin/" + key])
+ if target == "element-name":
+ arg = "import-bin.bst"
+ elif target == "artifact-name":
+ key = cli.get_element_key(project, "import-bin.bst")
+ arg = "test/import-bin/" + key
+
+ # List the contents via the element name
+ result = cli.run(project=project, args=["artifact", "list-contents", "--long", arg])
assert result.exit_code == 0
+ expected_output_template = (
+ "{target}:\n"
+ "\tdrwxr-xr-x dir 1 usr\n"
+ "\tdrwxr-xr-x dir 1 usr/bin\n"
+ "\t-rw-r--r-- reg 107 usr/bin/hello\n\n"
+ )
+ expected_output = expected_output_template.format(target=arg)
- expected_output = "test/import-bin/" + key + ":\n" "\tusr\n" "\tusr/bin\n" "\tusr/bin/hello\n\n"
assert expected_output in result.output
@@ -89,49 +112,3 @@ def test_artifact_list_exact_contents_glob(cli, datafiles):
for artifact in expected_artifacts:
assert artifact in result.output
-
-
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_list_exact_contents_element_long(cli, datafiles):
- project = str(datafiles)
-
- # Ensure we have an artifact to read
- result = cli.run(project=project, args=["build", "import-bin.bst"])
- assert result.exit_code == 0
-
- # List the contents via the element name
- result = cli.run(project=project, args=["artifact", "list-contents", "--long", "import-bin.bst"])
- assert result.exit_code == 0
- expected_output = (
- "import-bin.bst:\n"
- "\tdrwxr-xr-x dir 1 usr\n"
- "\tdrwxr-xr-x dir 1 usr/bin\n"
- "\t-rw-r--r-- reg 107 usr/bin/hello\n\n"
- )
-
- assert expected_output in result.output
-
-
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_list_exact_contents_ref_long(cli, datafiles):
- project = str(datafiles)
-
- # Get the cache key of our test element
- key = cli.get_element_key(project, "import-bin.bst")
-
- # Ensure we have an artifact to read
- result = cli.run(project=project, args=["build", "import-bin.bst"])
- assert result.exit_code == 0
-
- # List the contents via the key
- result = cli.run(project=project, args=["artifact", "list-contents", "-l", "test/import-bin/" + key])
- assert result.exit_code == 0
-
- expected_output = (
- " test/import-bin/" + key + ":\n"
- "\tdrwxr-xr-x dir 1 usr\n"
- "\tdrwxr-xr-x dir 1 usr/bin\n"
- "\t-rw-r--r-- reg 107 usr/bin/hello\n\n"
- )
-
- assert expected_output in result.output