summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/optional_deps.py
blob: d9268e7e1410e4fe99e2ca0e2d1fb8c2a32fa8d7 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Copyright 2013-2020 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
from spack.spec import Spec


@pytest.fixture(
    params=[
        # Normalize simple conditionals
        ('optional-dep-test', {'optional-dep-test': None}),
        ('optional-dep-test~a', {'optional-dep-test~a': None}),
        ('optional-dep-test+a', {'optional-dep-test+a': {'a': None}}),
        ('optional-dep-test a=true', {
            'optional-dep-test a=true': {
                'a': None
            }}),
        ('optional-dep-test a=true', {
            'optional-dep-test+a': {
                'a': None
            }}),
        ('optional-dep-test@1.1', {'optional-dep-test@1.1': {'b': None}}),
        ('optional-dep-test%intel', {'optional-dep-test%intel': {'c': None}}),
        ('optional-dep-test%intel@64.1', {
            'optional-dep-test%intel@64.1': {
                'c': None,
                'd': None
            }}),
        ('optional-dep-test%intel@64.1.2', {
            'optional-dep-test%intel@64.1.2': {
                'c': None,
                'd': None
            }}),
        ('optional-dep-test%clang@35', {
            'optional-dep-test%clang@35': {
                'e': None
            }}),
        # Normalize multiple conditionals
        ('optional-dep-test+a@1.1', {
            'optional-dep-test+a@1.1': {
                'a': None,
                'b': None
            }}),
        ('optional-dep-test+a%intel', {
            'optional-dep-test+a%intel': {
                'a': None,
                'c': None
            }}),
        ('optional-dep-test@1.1%intel', {
            'optional-dep-test@1.1%intel': {
                'b': None,
                'c': None
            }}),
        ('optional-dep-test@1.1%intel@64.1.2+a', {
            'optional-dep-test@1.1%intel@64.1.2+a': {
                'a': None,
                'b': None,
                'c': None,
                'd': None
            }}),
        ('optional-dep-test@1.1%clang@36.5+a', {
            'optional-dep-test@1.1%clang@36.5+a': {
                'b': None,
                'a': None,
                'e': None
            }}),
        # Chained MPI
        ('optional-dep-test-2+mpi', {
            'optional-dep-test-2+mpi': {
                'optional-dep-test+mpi': {'mpi': None}
            }}),
        # Each of these dependencies comes from a conditional
        # dependency on another.  This requires iterating to evaluate
        # the whole chain.
        ('optional-dep-test+f', {
            'optional-dep-test+f': {
                'f': None,
                'g': None,
                'mpi': None
            }})
    ]
)
def spec_and_expected(request):
    """Parameters for the normalization test."""
    spec, d = request.param
    return spec, Spec.from_literal(d)


def test_normalize(spec_and_expected, config, mock_packages):
    spec, expected = spec_and_expected
    spec = Spec(spec)
    spec.normalize()
    assert spec.eq_dag(expected, deptypes=False)


def test_default_variant(config, mock_packages):
    spec = Spec('optional-dep-test-3')
    spec.concretize()
    assert 'a' in spec

    spec = Spec('optional-dep-test-3~var')
    spec.concretize()
    assert 'a' in spec

    spec = Spec('optional-dep-test-3+var')
    spec.concretize()
    assert 'b' in spec