tests/frontend/artifact_list_contents.py: Use parametrized tests
Small refactor to reduce code duplication here
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,22 +29,8 @@
@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_list_exact_contents_element(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", "import-bin.bst"])
- assert result.exit_code == 0
- expected_output = "import-bin.bst:\n\tusr\n\tusr/bin\n\tusr/bin/hello\n\n"
- 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(cli, datafiles, target):
project = str(datafiles)
# Get the cache key of our test element
@@ -54,11 +40,48 @@
result = cli.run(project=project, args=["build", "import-bin.bst"])
assert result.exit_code == 0
+ 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", "test/import-bin/" + key])
+ result = cli.run(project=project, args=["artifact", "list-contents", arg])
assert result.exit_code == 0
- expected_output = "test/import-bin/" + key + ":\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)
+@pytest.mark.parametrize("target", ["element-name", "artifact-name"])
+def test_artifact_list_exact_contents_long(cli, datafiles, target):
+ 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
+
+ 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)
+
assert expected_output in result.output
@@ -89,49 +112,3 @@
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