summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/cmd/dependencies.py
blob: bc615c7a3a10d777f907772fa3cdb74247378dad (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
# 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 re

import pytest

from llnl.util.tty.color import color_when

import spack.store
from spack.main import SpackCommand

dependencies = SpackCommand("dependencies")

mpis = [
    "intel-parallel-studio",
    "low-priority-provider",
    "mpich",
    "mpich2",
    "multi-provider-mpi",
    "zmpi",
]
mpi_deps = ["fake"]


def test_direct_dependencies(mock_packages):
    out = dependencies("mpileaks")
    actual = set(re.split(r"\s+", out.strip()))
    expected = set(["callpath"] + mpis)
    assert expected == actual


def test_transitive_dependencies(mock_packages):
    out = dependencies("--transitive", "mpileaks")
    actual = set(re.split(r"\s+", out.strip()))
    expected = set(["callpath", "dyninst", "libdwarf", "libelf"] + mpis + mpi_deps)
    assert expected == actual


def test_transitive_dependencies_with_deptypes(mock_packages):
    out = dependencies("--transitive", "--deptype=link,run", "dtbuild1")
    deps = set(re.split(r"\s+", out.strip()))
    assert set(["dtlink2", "dtrun2"]) == deps

    out = dependencies("--transitive", "--deptype=build", "dtbuild1")
    deps = set(re.split(r"\s+", out.strip()))
    assert set(["dtbuild2", "dtlink2"]) == deps

    out = dependencies("--transitive", "--deptype=link", "dtbuild1")
    deps = set(re.split(r"\s+", out.strip()))
    assert set(["dtlink2"]) == deps


@pytest.mark.db
def test_direct_installed_dependencies(mock_packages, database):
    with color_when(False):
        out = dependencies("--installed", "mpileaks^mpich")

    lines = [line for line in out.strip().split("\n") if not line.startswith("--")]
    hashes = set([re.split(r"\s+", line)[0] for line in lines])

    expected = set(
        [spack.store.STORE.db.query_one(s).dag_hash(7) for s in ["mpich", "callpath^mpich"]]
    )

    assert expected == hashes


@pytest.mark.db
def test_transitive_installed_dependencies(mock_packages, database):
    with color_when(False):
        out = dependencies("--installed", "--transitive", "mpileaks^zmpi")

    lines = [line for line in out.strip().split("\n") if not line.startswith("--")]
    hashes = set([re.split(r"\s+", line)[0] for line in lines])

    expected = set(
        [
            spack.store.STORE.db.query_one(s).dag_hash(7)
            for s in ["zmpi", "callpath^zmpi", "fake", "dyninst", "libdwarf", "libelf"]
        ]
    )

    assert expected == hashes