summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/cmd/dependents.py
blob: 376332cf88baf928e144712b2c93c87be86f9720 (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
# Copyright 2013-2021 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

dependents = SpackCommand('dependents')


def test_immediate_dependents(mock_packages):
    out = dependents('libelf')
    actual = set(re.split(r'\s+', out.strip()))
    assert actual == set([
        'dyninst',
        'libdwarf',
        'patch-a-dependency',
        'patch-several-dependencies',
        'quantum-espresso',
        'conditionally-patch-dependency'
    ])


def test_transitive_dependents(mock_packages):
    out = dependents('--transitive', 'libelf')
    actual = set(re.split(r'\s+', out.strip()))
    assert actual == set([
        'callpath',
        'dyninst',
        'libdwarf',
        'mpileaks',
        'multivalue-variant',
        'singlevalue-variant-dependent',
        'patch-a-dependency', 'patch-several-dependencies',
        'quantum-espresso',
        'conditionally-patch-dependency'
    ])


@pytest.mark.db
def test_immediate_installed_dependents(mock_packages, database):
    with color_when(False):
        out = dependents('--installed', 'libelf')

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

    expected = set([spack.store.db.query_one(s).dag_hash(7)
                    for s in ['dyninst', 'libdwarf']])

    libelf = spack.store.db.query_one('libelf')
    expected = set([d.dag_hash(7) for d in libelf.dependents()])

    assert expected == hashes


@pytest.mark.db
def test_transitive_installed_dependents(mock_packages, database):
    with color_when(False):
        out = dependents('--installed', '--transitive', 'fake')

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

    expected = set([spack.store.db.query_one(s).dag_hash(7)
                    for s in ['zmpi', 'callpath^zmpi', 'mpileaks^zmpi']])

    assert expected == hashes