Make unit-test case reproduce CLI investigation

This commit is contained in:
psakiev
2024-04-30 09:08:21 -06:00
parent b88c0e6b6d
commit f003060ea6
3 changed files with 108 additions and 33 deletions

View File

@@ -4,7 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import copy
import os
import pathlib
import sys
import jinja2
@@ -2809,60 +2808,47 @@ def mock_runtime_dependencies(*args, **kwargs):
"""
mock function moved outside local definition to allow
multiprocessing pickling to work
----------------- Captured stderr call -------------
AttributeError:
Can't pickle local object 'test_reuse_prefers_standard_over_git_versions.<locals>.<lambda>'
"""
return True
@pytest.mark.only_clingo("clingo only re-use feature being tested")
@pytest.mark.regression("38484")
def test_git_ref_version_can_be_reused(
monkeypatch, mock_packages, install_mockery_mutable_config, mock_git_version_info
):
repo_path, filename, commits = mock_git_version_info
monkeypatch.setattr(
spack.package_base.PackageBase, "git", pathlib.Path(repo_path).as_uri(), raising=False
)
def test_git_ref_version_can_be_reused(monkeypatch, mock_packages, install_mockery_mutable_config):
# override gcc-runtime dep and make all installs reusable
monkeypatch.setattr(spack.solver.asp, "_has_runtime_dependencies", mock_runtime_dependencies)
first_spec = spack.spec.Spec(
"git-test-commit@git.v1.0=1.0+generic_install+feature"
).concretized()
first_spec = spack.spec.Spec("zlib-ng@git.2.1.5=2.1.5").concretized()
first_spec.package.do_install(fake=True, explicit=True)
with spack.config.override("concretizer:reuse", True):
second_spec = spack.spec.Spec(
"git-test-commit@git.v1.0=1.0+generic_install~feature"
).concretized()
second_spec = spack.spec.Spec("zlib-ng@git.2.1.5=2.1.5~opt").concretized()
# is_installed(first_spec)
assert second_spec.dag_hash() != first_spec.dag_hash()
@pytest.mark.only_clingo("clingo only re-use feature being tested")
def test_reuse_prefers_standard_over_git_versions(
monkeypatch, mock_packages, install_mockery_mutable_config, mock_git_version_info
monkeypatch, mock_packages, install_mockery_mutable_config
):
"""
order matters in this test. typically re-use would pick the last installed match
but we want to prefer the standard version over git ref based versions
so install git ref last and ensure it is not picked up by re-use
"""
repo_path, filename, commits = mock_git_version_info
monkeypatch.setattr(
spack.package_base.PackageBase, "git", pathlib.Path(repo_path).as_uri(), raising=False
)
# override gcc-runtime dep and make all installs reusable
monkeypatch.setattr(spack.solver.asp, "_has_runtime_dependencies", mock_runtime_dependencies)
standard_spec = spack.spec.Spec("git-test-commit@1.0+generic_install+feature").concretized()
standard_spec = spack.spec.Spec("zlib-ng@2.1.5").concretized()
standard_spec.package.do_install(fake=True, explicit=True)
git_spec = spack.spec.Spec(
"git-test-commit@git.v1.0=1.0+generic_install+feature"
).concretized()
git_spec = spack.spec.Spec("zlib-ng@git.2.1.5=2.1.5").concretized()
git_spec.package.do_install(fake=True, explicit=True)
with spack.config.override("concretizer:reuse", True):
test_spec = spack.spec.Spec("git-test-commit@1.0+generic_install").concretized()
test_spec = spack.spec.Spec("zlib-ng@2").concretized()
assert git_spec.dag_hash() != test_spec.dag_hash()
assert standard_spec.dag_hash() == test_spec.dag_hash()