From 83ca98712643f2b86d7ec23414c0e2e538dc597f Mon Sep 17 00:00:00 2001 From: Tristan van Berkom Date: Wed, 2 Dec 2020 16:57:07 +0900 Subject: Refactor ArtifactElement instantiation When instantiating an ArtifactElement, use an ArtifactProject to ensure that the Element does not accidentally have access to any incidentally existing project loaded from the current working directory. Also pass along the Artifact to the Element's initializer directly, and conditionally instantiate the element based on it's artifact instead of based on loading YAML configuration. Fixes #1410 Summary of changes: * _artifactelement.py: - Now load the Artifact and pass it along to the Element constructor - Now use an ArtifactProject for the element's project - Remove overrides of Element methods, instead of behaving differently, now we just fill in all the blanks for an Element to behave more naturally when loaded from an artifact. - Avoid redundantly loading the same artifact twice, if the artifact was cached then we will load only one artifact. * element.py: - Conditionally instantiate from the passed Artifact instead of considering any YAML loading. - Error out early in _prepare_sandbox() in case that we are trying to instantiate a sandbox for an uncached artifact, in which case we don't have any SandboxConfig at hand to do so. * _stream.py: - Clear the ArtifactProject cache after loading artifacts - Ensure we load a list of unique artifacts without any duplicates * tests/frontend/buildcheckout.py: Expect a different error when trying to checkout an uncached artifact * tests/frontend/push.py, tests/frontend/artifact_show.py: No longer expect duplicates to show up with wild card statements which would capture multiple versions of the same artifact (this changes because of #1410 being fixed) --- tests/frontend/artifact_show.py | 2 +- tests/frontend/buildcheckout.py | 3 +-- tests/frontend/push.py | 8 +++++--- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/frontend/artifact_show.py b/tests/frontend/artifact_show.py index ebea7cf33..392a9e2c6 100644 --- a/tests/frontend/artifact_show.py +++ b/tests/frontend/artifact_show.py @@ -110,7 +110,7 @@ def test_artifact_show_artifact_ref(cli, tmpdir, datafiles): [ # List only artifact results in the test/project # - ("test/**", ["test/target/", "test/target/", "test/compose-all/", "test/import-bin", "test/import-dev"]), + ("test/**", ["test/target/", "test/compose-all/", "test/import-bin", "test/import-dev"]), # List only artifact results by their .bst element names # ("**.bst", ["import-bin.bst", "import-dev.bst", "compose-all.bst", "target.bst", "subdir/target.bst"]), diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py index 709259397..6d1190667 100644 --- a/tests/frontend/buildcheckout.py +++ b/tests/frontend/buildcheckout.py @@ -469,8 +469,7 @@ def test_build_checkout_invalid_ref(datafiles, cli): non_existent_artifact = "test/checkout-deps/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" checkout_args = ["artifact", "checkout", "--deps", "none", "--tar", checkout, non_existent_artifact] result = cli.run(project=project, args=checkout_args) - - assert "Error while staging dependencies into a sandbox: 'No artifacts to stage'" in result.stderr + result.assert_main_error(ErrorDomain.STREAM, "missing-sandbox-config") @pytest.mark.datafiles(DATA_DIR) diff --git a/tests/frontend/push.py b/tests/frontend/push.py index 80cf07067..0b1d988f9 100644 --- a/tests/frontend/push.py +++ b/tests/frontend/push.py @@ -166,11 +166,13 @@ def test_push_artifact_glob(cli, tmpdir, datafiles): # Configure artifact share cli.configure({"artifacts": {"url": share.repo, "push": True}}) - # Run bst artifact push with a wildcard. - # This matches two artifact refs (weak and strong cache keys). + # Run bst artifact push with a wildcard, there is only one artifact + # matching "test/target/*", even though it can be accessed both by it's + # strong and weak key. + # result = cli.run(project=project, args=["artifact", "push", "test/target/*"]) result.assert_success() - assert len(result.get_pushed_elements()) == 2 + assert len(result.get_pushed_elements()) == 1 # Tests that: -- cgit v1.2.1