unit-test: port changes from compiler as deps (#48104)

Extracted #45189

Common test setup has been extracted in fixtures. Some matrix
dimensions moved from being "compiler" to be "targets".

Use --fake install for packages in test.
This commit is contained in:
Massimiliano Culpo 2024-12-16 09:27:41 +01:00 committed by GitHub
parent 6005813518
commit f6ab2f5b99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import contextlib
import filecmp import filecmp
import glob import glob
import io import io
@ -210,6 +211,49 @@ def test_env_untrack_managed(tmp_path, capfd):
assert f"'{env_name}' is not a tracked env" in out assert f"'{env_name}' is not a tracked env" in out
@pytest.fixture()
def installed_environment(tmp_path, mock_fetch, mock_packages, mock_archive, install_mockery):
spack_yaml = tmp_path / "spack.yaml"
@contextlib.contextmanager
def _installed_environment(content):
spack_yaml.write_text(content)
with fs.working_dir(tmp_path):
env("create", "test", "./spack.yaml")
with ev.read("test"):
install("--fake")
test = ev.read("test")
yield test
return _installed_environment
@pytest.fixture()
def template_combinatorial_env(tmp_path):
"""Returns a template base environment for tests. Since the environment configuration is
extended using str.format, we need double '{' escaping for the projections.
"""
view_dir = tmp_path / "view"
return f"""\
spack:
definitions:
- packages: [mpileaks, callpath]
- targets: ['target=x86_64', 'target=core2']
specs:
- matrix:
- [$packages]
- [$targets]
view:
combinatorial:
root: {view_dir}
{{view_config}}
projections:
'all': '{{{{architecture.target}}}}/{{{{name}}}}-{{{{version}}}}'
"""
def test_add(): def test_add():
e = ev.create("test") e = ev.create("test")
e.add("mpileaks") e.add("mpileaks")
@ -455,7 +499,7 @@ def test_env_specs_partition(install_mockery, mock_fetch):
assert roots_to_install[0].name == "cmake-client" assert roots_to_install[0].name == "cmake-client"
# Single installed root. # Single installed root.
e.install_all() e.install_all(fake=True)
roots_already_installed, roots_to_install = e._partition_roots_by_install_status() roots_already_installed, roots_to_install = e._partition_roots_by_install_status()
assert len(roots_already_installed) == 1 assert len(roots_already_installed) == 1
assert roots_already_installed[0].name == "cmake-client" assert roots_already_installed[0].name == "cmake-client"
@ -475,7 +519,7 @@ def test_env_install_all(install_mockery, mock_fetch):
e = ev.create("test") e = ev.create("test")
e.add("cmake-client") e.add("cmake-client")
e.concretize() e.concretize()
e.install_all() e.install_all(fake=True)
env_specs = e._get_environment_specs() env_specs = e._get_environment_specs()
spec = next(x for x in env_specs if x.name == "cmake-client") spec = next(x for x in env_specs if x.name == "cmake-client")
assert spec.installed assert spec.installed
@ -487,7 +531,7 @@ def test_env_install_single_spec(install_mockery, mock_fetch):
e = ev.read("test") e = ev.read("test")
with e: with e:
install("--add", "cmake-client") install("--fake", "--add", "cmake-client")
e = ev.read("test") e = ev.read("test")
assert e.user_specs[0].name == "cmake-client" assert e.user_specs[0].name == "cmake-client"
@ -508,7 +552,7 @@ def test_env_install_include_concrete_env(unify, install_mockery, mock_fetch, mu
combined.write() combined.write()
with combined: with combined:
install() install("--fake")
test1_roots = test1.concretized_order test1_roots = test1.concretized_order
test2_roots = test2.concretized_order test2_roots = test2.concretized_order
@ -556,7 +600,7 @@ def test_env_modifications_error_on_activate(install_mockery, mock_fetch, monkey
e = ev.read("test") e = ev.read("test")
with e: with e:
install("--add", "cmake-client") install("--fake", "--add", "cmake-client")
def setup_error(pkg, env): def setup_error(pkg, env):
raise RuntimeError("cmake-client had issues!") raise RuntimeError("cmake-client had issues!")
@ -625,12 +669,12 @@ def test_env_install_two_specs_same_dep(install_mockery, mock_fetch, tmpdir, cap
with ev.read("test"): with ev.read("test"):
with capsys.disabled(): with capsys.disabled():
out = install() out = install("--fake")
# Ensure both packages reach install phase processing and are installed # Ensure both packages reach install phase processing and are installed
out = str(out) out = str(out)
assert "depb: Executing phase:" in out assert "depb: Successfully installed" in out
assert "a: Executing phase:" in out assert "pkg-a: Successfully installed" in out
depb = spack.store.STORE.db.query_one("depb", installed=True) depb = spack.store.STORE.db.query_one("depb", installed=True)
assert depb, "Expected depb to be installed" assert depb, "Expected depb to be installed"
@ -1649,9 +1693,7 @@ def test_stage(mock_stage, mock_fetch, install_mockery):
def check_stage(spec): def check_stage(spec):
spec = Spec(spec).concretized() spec = Spec(spec).concretized()
for dep in spec.traverse(): for dep in spec.traverse():
stage_name = "{0}{1}-{2}-{3}".format( stage_name = f"{stage_prefix}{dep.name}-{dep.version}-{dep.dag_hash()}"
stage_prefix, dep.name, dep.version, dep.dag_hash()
)
assert os.path.isdir(os.path.join(root, stage_name)) assert os.path.isdir(os.path.join(root, stage_name))
check_stage("mpileaks") check_stage("mpileaks")
@ -2821,207 +2863,75 @@ def test_stack_definition_conditional_add_write(tmpdir):
assert "zmpi" not in packages_lists[1]["packages"] assert "zmpi" not in packages_lists[1]["packages"]
def test_stack_combinatorial_view( def test_stack_combinatorial_view(installed_environment, template_combinatorial_env, tmp_path):
tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery """Tests creating a default view for a combinatorial stack."""
): view_dir = tmp_path / "view"
filename = str(tmpdir.join("spack.yaml")) with installed_environment(template_combinatorial_env.format(view_config="")) as test:
viewdir = str(tmpdir.join("view"))
with open(filename, "w", encoding="utf-8") as f:
f.write(
"""\
spack:
definitions:
- packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang']
specs:
- matrix:
- [$packages]
- [$compilers]
view:
combinatorial:
root: %s
projections:
'all': '{name}/{version}-{compiler.name}'"""
% viewdir
)
with tmpdir.as_cwd():
env("create", "test", "./spack.yaml")
with ev.read("test"):
install()
test = ev.read("test")
for spec in test._get_environment_specs(): for spec in test._get_environment_specs():
assert os.path.exists( if spec.name == "gcc-runtime":
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name)) continue
) current_dir = view_dir / f"{spec.architecture.target}" / f"{spec.name}-{spec.version}"
assert current_dir.exists() and current_dir.is_dir()
def test_stack_view_select(tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery): def test_stack_view_select(installed_environment, template_combinatorial_env, tmp_path):
filename = str(tmpdir.join("spack.yaml")) view_dir = tmp_path / "view"
viewdir = str(tmpdir.join("view")) content = template_combinatorial_env.format(view_config="select: ['target=x86_64']\n")
with open(filename, "w", encoding="utf-8") as f: with installed_environment(content) as test:
f.write(
"""\
spack:
definitions:
- packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang']
specs:
- matrix:
- [$packages]
- [$compilers]
view:
combinatorial:
root: %s
select: ['%%gcc']
projections:
'all': '{name}/{version}-{compiler.name}'"""
% viewdir
)
with tmpdir.as_cwd():
env("create", "test", "./spack.yaml")
with ev.read("test"):
install()
test = ev.read("test")
for spec in test._get_environment_specs(): for spec in test._get_environment_specs():
if spec.satisfies("%gcc"): if spec.name == "gcc-runtime":
assert os.path.exists( continue
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name)) current_dir = view_dir / f"{spec.architecture.target}" / f"{spec.name}-{spec.version}"
) assert current_dir.exists() is spec.satisfies("target=x86_64")
else:
assert not os.path.exists(
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name))
)
def test_stack_view_exclude(tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery): def test_stack_view_exclude(installed_environment, template_combinatorial_env, tmp_path):
filename = str(tmpdir.join("spack.yaml")) view_dir = tmp_path / "view"
viewdir = str(tmpdir.join("view")) content = template_combinatorial_env.format(view_config="exclude: [callpath]\n")
with open(filename, "w", encoding="utf-8") as f: with installed_environment(content) as test:
f.write(
"""\
spack:
definitions:
- packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang']
specs:
- matrix:
- [$packages]
- [$compilers]
view:
combinatorial:
root: %s
exclude: [callpath]
projections:
'all': '{name}/{version}-{compiler.name}'"""
% viewdir
)
with tmpdir.as_cwd():
env("create", "test", "./spack.yaml")
with ev.read("test"):
install()
test = ev.read("test")
for spec in test._get_environment_specs(): for spec in test._get_environment_specs():
if not spec.satisfies("callpath"): if spec.name == "gcc-runtime":
assert os.path.exists( continue
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name)) current_dir = view_dir / f"{spec.architecture.target}" / f"{spec.name}-{spec.version}"
) assert current_dir.exists() is not spec.satisfies("callpath")
else:
assert not os.path.exists(
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name))
)
def test_stack_view_select_and_exclude( def test_stack_view_select_and_exclude(
tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery installed_environment, template_combinatorial_env, tmp_path
): ):
filename = str(tmpdir.join("spack.yaml")) view_dir = tmp_path / "view"
viewdir = str(tmpdir.join("view")) content = template_combinatorial_env.format(
with open(filename, "w", encoding="utf-8") as f: view_config="""select: ['target=x86_64']
f.write( exclude: [callpath]
"""\ """
spack: )
definitions: with installed_environment(content) as test:
- packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang']
specs:
- matrix:
- [$packages]
- [$compilers]
view:
combinatorial:
root: %s
select: ['%%gcc']
exclude: [callpath]
projections:
'all': '{name}/{version}-{compiler.name}'"""
% viewdir
)
with tmpdir.as_cwd():
env("create", "test", "./spack.yaml")
with ev.read("test"):
install()
test = ev.read("test")
for spec in test._get_environment_specs(): for spec in test._get_environment_specs():
if spec.satisfies("%gcc") and not spec.satisfies("callpath"): if spec.name == "gcc-runtime":
assert os.path.exists( continue
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name)) current_dir = view_dir / f"{spec.architecture.target}" / f"{spec.name}-{spec.version}"
) assert current_dir.exists() is (
else: spec.satisfies("target=x86_64") and not spec.satisfies("callpath")
assert not os.path.exists( )
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name))
)
def test_view_link_roots(tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery): def test_view_link_roots(installed_environment, template_combinatorial_env, tmp_path):
filename = str(tmpdir.join("spack.yaml")) view_dir = tmp_path / "view"
viewdir = str(tmpdir.join("view")) content = template_combinatorial_env.format(
with open(filename, "w", encoding="utf-8") as f: view_config="""select: ['target=x86_64']
f.write( exclude: [callpath]
"""\ link: 'roots'
spack: """
definitions: )
- packages: [mpileaks, callpath] with installed_environment(content) as test:
- compilers: ['%%gcc', '%%clang']
specs:
- matrix:
- [$packages]
- [$compilers]
view:
combinatorial:
root: %s
select: ['%%gcc']
exclude: [callpath]
link: 'roots'
projections:
'all': '{name}/{version}-{compiler.name}'"""
% viewdir
)
with tmpdir.as_cwd():
env("create", "test", "./spack.yaml")
with ev.read("test"):
install()
test = ev.read("test")
for spec in test._get_environment_specs(): for spec in test._get_environment_specs():
if spec in test.roots() and ( if spec.name == "gcc-runtime":
spec.satisfies("%gcc") and not spec.satisfies("callpath") continue
): current_dir = view_dir / f"{spec.architecture.target}" / f"{spec.name}-{spec.version}"
assert os.path.exists( expected_exists = spec in test.roots() and (
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name)) spec.satisfies("target=x86_64") and not spec.satisfies("callpath")
) )
else: assert current_dir.exists() == expected_exists
assert not os.path.exists(
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name))
)
def test_view_link_run(tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery): def test_view_link_run(tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery):
@ -3065,169 +2975,84 @@ def test_view_link_run(tmpdir, mock_fetch, mock_packages, mock_archive, install_
@pytest.mark.parametrize("link_type", ["hardlink", "copy", "symlink"]) @pytest.mark.parametrize("link_type", ["hardlink", "copy", "symlink"])
def test_view_link_type( def test_view_link_type(link_type, installed_environment, tmp_path):
link_type, tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery view_dir = tmp_path / "view"
): with installed_environment(
filename = str(tmpdir.join("spack.yaml")) f"""\
viewdir = str(tmpdir.join("view"))
with open(filename, "w", encoding="utf-8") as f:
f.write(
"""\
spack: spack:
specs: specs:
- mpileaks - mpileaks
view: view:
default: default:
root: %s root: {view_dir}
link_type: %s""" link_type: {link_type}"""
% (viewdir, link_type) ) as test:
)
with tmpdir.as_cwd():
env("create", "test", "./spack.yaml")
with ev.read("test"):
install()
test = ev.read("test")
for spec in test.roots(): for spec in test.roots():
file_path = test.default_view.view()._root # Assertions are based on the behavior of the "--fake" install
file_to_test = os.path.join(file_path, spec.name) bin_file = pathlib.Path(test.default_view.view()._root) / "bin" / spec.name
assert os.path.isfile(file_to_test) assert bin_file.exists()
assert os.path.islink(file_to_test) == (link_type == "symlink") assert bin_file.is_symlink() == (link_type == "symlink")
def test_view_link_all(tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery): def test_view_link_all(installed_environment, template_combinatorial_env, tmp_path):
filename = str(tmpdir.join("spack.yaml")) view_dir = tmp_path / "view"
viewdir = str(tmpdir.join("view")) content = template_combinatorial_env.format(
with open(filename, "w", encoding="utf-8") as f: view_config="""select: ['target=x86_64']
f.write( exclude: [callpath]
"""\ link: 'all'
spack: """
definitions: )
- packages: [mpileaks, callpath]
- compilers: ['%%gcc', '%%clang']
specs:
- matrix:
- [$packages]
- [$compilers]
view: with installed_environment(content) as test:
combinatorial:
root: %s
select: ['%%gcc']
exclude: [callpath]
link: 'all'
projections:
'all': '{name}/{version}-{compiler.name}'"""
% viewdir
)
with tmpdir.as_cwd():
env("create", "test", "./spack.yaml")
with ev.read("test"):
install()
test = ev.read("test")
for spec in test._get_environment_specs(): for spec in test._get_environment_specs():
if spec.satisfies("%gcc") and not spec.satisfies("callpath"): if spec.name == "gcc-runtime":
assert os.path.exists( continue
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name)) current_dir = view_dir / f"{spec.architecture.target}" / f"{spec.name}-{spec.version}"
) assert current_dir.exists() == (
else: spec.satisfies("target=x86_64") and not spec.satisfies("callpath")
assert not os.path.exists( )
os.path.join(viewdir, spec.name, "%s-%s" % (spec.version, spec.compiler.name))
)
def test_stack_view_activate_from_default( def test_stack_view_activate_from_default(
tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery installed_environment, template_combinatorial_env, tmp_path
): ):
filename = str(tmpdir.join("spack.yaml")) view_dir = tmp_path / "view"
viewdir = str(tmpdir.join("view")) content = template_combinatorial_env.format(view_config="select: ['target=x86_64']")
with open(filename, "w", encoding="utf-8") as f: # Replace the name of the view
f.write( content = content.replace("combinatorial:", "default:")
"""\ with installed_environment(content):
spack:
definitions:
- packages: [mpileaks, cmake]
- compilers: ['%%gcc', '%%clang']
specs:
- matrix:
- [$packages]
- [$compilers]
view:
default:
root: %s
select: ['%%gcc']"""
% viewdir
)
with tmpdir.as_cwd():
env("create", "test", "./spack.yaml")
with ev.read("test"):
install()
shell = env("activate", "--sh", "test") shell = env("activate", "--sh", "test")
assert "PATH" in shell, shell
assert "PATH" in shell assert str(view_dir / "bin") in shell
assert os.path.join(viewdir, "bin") in shell
assert "FOOBAR=mpileaks" in shell assert "FOOBAR=mpileaks" in shell
def test_stack_view_no_activate_without_default( def test_stack_view_no_activate_without_default(
tmpdir, mock_fetch, mock_packages, mock_archive, install_mockery installed_environment, template_combinatorial_env, tmp_path
): ):
filename = str(tmpdir.join("spack.yaml")) view_dir = tmp_path / "view"
viewdir = str(tmpdir.join("view")) content = template_combinatorial_env.format(view_config="select: ['target=x86_64']")
with open(filename, "w", encoding="utf-8") as f: with installed_environment(content):
f.write(
"""\
spack:
definitions:
- packages: [mpileaks, cmake]
- compilers: ['%%gcc', '%%clang']
specs:
- matrix:
- [$packages]
- [$compilers]
view:
not-default:
root: %s
select: ['%%gcc']"""
% viewdir
)
with tmpdir.as_cwd():
env("create", "test", "./spack.yaml")
with ev.read("test"):
install()
shell = env("activate", "--sh", "test") shell = env("activate", "--sh", "test")
assert "PATH" not in shell assert "PATH" not in shell
assert viewdir not in shell assert str(view_dir) not in shell
@pytest.mark.parametrize("include_views", [True, False, "split"]) @pytest.mark.parametrize("include_views", [True, False, "split"])
def test_stack_view_multiple_views( def test_stack_view_multiple_views(installed_environment, tmp_path, include_views):
tmp_path,
mock_fetch,
mock_packages,
mock_archive,
install_mockery,
mutable_config,
include_views,
):
"""Test multiple views as both included views (True), as both environment """Test multiple views as both included views (True), as both environment
views (False), or as one included and the other in the environment.""" views (False), or as one included and the other in the environment.
"""
# Write the view configuration and or manifest file # Write the view configuration and or manifest file
view_filename = tmp_path / "view.yaml" view_filename = tmp_path / "view.yaml"
base_content = """\ base_content = """\
definitions: definitions:
- packages: [mpileaks, cmake] - packages: [mpileaks, cmake]
- compilers: ['%gcc', '%clang'] - targets: ['target=x86_64', 'target=core2']
specs: specs:
- matrix: - matrix:
- [$packages] - [$packages]
- [$compilers] - [$targets]
""" """
include_content = f" include:\n - {view_filename}\n" include_content = f" include:\n - {view_filename}\n"
@ -3237,17 +3062,17 @@ def test_stack_view_multiple_views(
comb_view = """\ comb_view = """\
{0}combinatorial: {0}combinatorial:
{0} root: {1} {0} root: {1}
{0} exclude: [callpath%gcc] {0} exclude: [target=core2]
{0} projections: {0} projections:
""" """
projection = " 'all': '{name}/{version}-{compiler.name}'" projection = " 'all': '{architecture.target}/{name}-{version}'"
default_dir = tmp_path / "default-view" default_dir = tmp_path / "default-view"
default_view = """\ default_view = """\
{0}default: {0}default:
{0} root: {1} {0} root: {1}
{0} select: ['%gcc'] {0} select: ['target=x86_64']
""" """
content = "spack:\n" content = "spack:\n"
@ -3272,22 +3097,13 @@ def test_stack_view_multiple_views(
content += default_view.format(indent, str(default_dir)) content += default_view.format(indent, str(default_dir))
content += comb_view.format(indent, str(comb_dir)) + indent + projection content += comb_view.format(indent, str(comb_dir)) + indent + projection
filename = tmp_path / ev.manifest_name with installed_environment(content) as e:
filename.write_text(content)
env("create", "test", str(filename))
with ev.read("test"):
install()
with ev.read("test") as e:
assert os.path.exists(str(default_dir / "bin")) assert os.path.exists(str(default_dir / "bin"))
for spec in e._get_environment_specs(): for spec in e._get_environment_specs():
spec_subdir = f"{spec.version}-{spec.compiler.name}" if spec.name == "gcc-runtime":
comb_spec_dir = str(comb_dir / spec.name / spec_subdir) continue
if not spec.satisfies("callpath%gcc"): current_dir = comb_dir / f"{spec.architecture.target}" / f"{spec.name}-{spec.version}"
assert os.path.exists(comb_spec_dir) assert current_dir.exists() is not spec.satisfies("target=core2")
else:
assert not os.path.exists(comb_spec_dir)
def test_env_activate_sh_prints_shell_output(tmpdir, mock_stage, mock_fetch, install_mockery): def test_env_activate_sh_prints_shell_output(tmpdir, mock_stage, mock_fetch, install_mockery):
@ -3656,12 +3472,10 @@ def test_modules_relative_to_views(environment_from_manifest, install_mockery, m
assert spec.prefix not in contents assert spec.prefix not in contents
def test_modules_exist_after_env_install( def test_modules_exist_after_env_install(installed_environment, monkeypatch):
environment_from_manifest, install_mockery, mock_fetch, monkeypatch
):
# Some caching issue # Some caching issue
monkeypatch.setattr(spack.modules.tcl, "configuration_registry", {}) monkeypatch.setattr(spack.modules.tcl, "configuration_registry", {})
environment_from_manifest( with installed_environment(
""" """
spack: spack:
specs: specs:
@ -3677,16 +3491,15 @@ def test_modules_exist_after_env_install(
roots: roots:
tcl: without_view tcl: without_view
""" """
) ) as e:
with ev.read("test") as e:
install()
specs = e.all_specs() specs = e.all_specs()
for module_set in ("uses_view", "without_view"): for module_set in ("uses_view", "without_view"):
modules = glob.glob(f"{e.path}/{module_set}/**/*/*") modules = glob.glob(f"{e.path}/{module_set}/**/*/*")
assert len(modules) == len(specs), "Not all modules were generated" assert len(modules) == len(specs), "Not all modules were generated"
for spec in specs: for spec in specs:
if spec.external:
continue
module = next((m for m in modules if os.path.dirname(m).endswith(spec.name)), None) module = next((m for m in modules if os.path.dirname(m).endswith(spec.name)), None)
assert module, f"Module for {spec} not found" assert module, f"Module for {spec} not found"
@ -3728,7 +3541,7 @@ def test_install_develop_keep_stage(
(mpileaks_spec,) = e.all_matching_specs("mpileaks") (mpileaks_spec,) = e.all_matching_specs("mpileaks")
assert not os.path.exists(libelf_spec.package.stage.path) assert not os.path.exists(libelf_spec.package.stage.path)
assert not os.path.exists(mpileaks_spec.package.stage.path) assert not os.path.exists(mpileaks_spec.package.stage.path)
install() install("--fake")
assert os.path.exists(libelf_spec.package.stage.path) assert os.path.exists(libelf_spec.package.stage.path)
assert not os.path.exists(mpileaks_spec.package.stage.path) assert not os.path.exists(mpileaks_spec.package.stage.path)
@ -3938,7 +3751,7 @@ def test_environment_query_spec_by_hash(mock_stage, mock_fetch, install_mockery)
concretize() concretize()
with ev.read("test") as e: with ev.read("test") as e:
spec = e.matching_spec("libelf") spec = e.matching_spec("libelf")
install("/{0}".format(spec.dag_hash())) install("--fake", f"/{spec.dag_hash()}")
with ev.read("test") as e: with ev.read("test") as e:
assert not e.matching_spec("libdwarf").installed assert not e.matching_spec("libdwarf").installed
assert e.matching_spec("libelf").installed assert e.matching_spec("libelf").installed
@ -4401,7 +4214,7 @@ def test_env_include_packages_url(
ev.activate(env) ev.activate(env)
cfg = spack.config.get("packages") cfg = spack.config.get("packages")
assert "openmpi" in cfg["all"]["providers"]["mpi"] assert "mpich" in cfg["all"]["providers"]["mpi"]
def test_relative_view_path_on_command_line_is_made_absolute(tmp_path): def test_relative_view_path_on_command_line_is_made_absolute(tmp_path):
@ -4525,7 +4338,7 @@ def test_env_include_mixed_views(tmp_path, mutable_mock_env_path, mutable_config
def test_stack_view_multiple_views_same_name( def test_stack_view_multiple_views_same_name(
tmp_path, mock_fetch, mock_packages, mock_archive, install_mockery, mutable_config installed_environment, template_combinatorial_env, tmp_path
): ):
"""Test multiple views with the same name combine settings with precedence """Test multiple views with the same name combine settings with precedence
given to the options in spack.yaml.""" given to the options in spack.yaml."""
@ -4537,58 +4350,52 @@ def test_stack_view_multiple_views_same_name(
view: view:
default: default:
root: {default_dir} root: {default_dir}
select: ['%gcc'] select: ['target=x86_64']
projections: projections:
all: '{{name}}/{{version}}-{{compiler.name}}' all: '{{architecture.target}}/{{name}}-{{version}}-from-view'
""" """
view_filename.write_text(default_view) view_filename.write_text(default_view)
view_dir = tmp_path / "view" view_dir = tmp_path / "view"
content = f"""\ with installed_environment(
f"""\
spack: spack:
include: include:
- {view_filename} - {view_filename}
definitions: definitions:
- packages: [mpileaks, cmake] - packages: [mpileaks, cmake]
- compilers: ['%gcc', '%clang'] - targets: ['target=x86_64', 'target=core2']
specs: specs:
- matrix: - matrix:
- [$packages] - [$packages]
- [$compilers] - [$targets]
view: view:
default: default:
root: {view_dir} root: {view_dir}
exclude: ['cmake'] exclude: ['cmake']
projections: projections:
all: '{{name}}/{{compiler.name}}-{{version}}' all: '{{architecture.target}}/{{name}}-{{version}}'
""" """
) as e:
filename = tmp_path / ev.manifest_name
filename.write_text(content)
env("create", "test", str(filename))
with ev.read("test"):
install()
with ev.read("test") as e:
# the view root in the included view should NOT exist # the view root in the included view should NOT exist
assert not os.path.exists(str(default_dir)) assert not os.path.exists(str(default_dir))
for spec in e._get_environment_specs(): for spec in e._get_environment_specs():
# no specs will exist in the included view projection # no specs will exist in the included view projection
included_spec_subdir = f"{spec.version}-{spec.compiler.name}" base_dir = view_dir / f"{spec.architecture.target}"
included_spec_dir = str(view_dir / spec.name / included_spec_subdir) included_dir = base_dir / f"{spec.name}-{spec.version}-from-view"
assert not os.path.exists(included_spec_dir) assert not included_dir.exists()
# only specs compiled with %gcc (selected in the included view) that # only target=x86_64 specs (selected in the included view) that
# are also not cmake (excluded in the environment view) should exist # are also not cmake (excluded in the environment view) should exist
env_spec_subdir = f"{spec.compiler.name}-{spec.version}" if spec.name == "gcc-runtime":
env_spec_dir = str(view_dir / spec.name / env_spec_subdir) continue
if spec.satisfies("cmake") or spec.satisfies("%clang"): current_dir = view_dir / f"{spec.architecture.target}" / f"{spec.name}-{spec.version}"
assert not os.path.exists(env_spec_dir) assert current_dir.exists() is not (
else: spec.satisfies("cmake") or spec.satisfies("target=core2")
assert os.path.exists(env_spec_dir) )
def test_env_view_resolves_identical_file_conflicts(tmp_path, install_mockery, mock_fetch): def test_env_view_resolves_identical_file_conflicts(tmp_path, install_mockery, mock_fetch):