summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/cmd/concretize.py
blob: 914f0fe6af9e8efc008fb4a7eb27f71067fba1bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)


import pytest

import spack.environment as ev
from spack import spack_version
from spack.main import SpackCommand

pytestmark = pytest.mark.usefixtures("config", "mutable_mock_repo")

env = SpackCommand("env")
add = SpackCommand("add")
concretize = SpackCommand("concretize")


unification_strategies = [False, True, "when_possible"]


@pytest.mark.parametrize("unify", unification_strategies)
def test_concretize_all_test_dependencies(unify, mutable_mock_env_path):
    """Check all test dependencies are concretized."""
    env("create", "test")

    with ev.read("test") as e:
        e.unify = unify
        add("depb")
        concretize("--test", "all")
        assert e.matching_spec("test-dependency")


@pytest.mark.parametrize("unify", unification_strategies)
def test_concretize_root_test_dependencies_not_recursive(unify, mutable_mock_env_path):
    """Check that test dependencies are not concretized recursively."""
    env("create", "test")

    with ev.read("test") as e:
        e.unify = unify
        add("depb")
        concretize("--test", "root")
        assert e.matching_spec("test-dependency") is None


@pytest.mark.parametrize("unify", unification_strategies)
def test_concretize_root_test_dependencies_are_concretized(unify, mutable_mock_env_path):
    """Check that root test dependencies are concretized."""
    env("create", "test")

    with ev.read("test") as e:
        e.unify = unify
        add("a")
        add("b")
        concretize("--test", "root")
        assert e.matching_spec("test-dependency")

        data = e._to_lockfile_dict()
        assert data["spack"]["version"] == spack_version