summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/cmd/tags.py
blob: 7de107c9234be2658cd20c0052c754cbd412cabb (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
# Copyright 2013-2024 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 spack.main
import spack.repo
import spack.spec

tags = spack.main.SpackCommand("tags")


def test_tags_bad_options():
    out = tags("-a", "tag1", fail_on_error=False)
    assert "option OR provide" in out


def test_tags_no_installed(install_mockery, mock_fetch):
    out = tags("-i")
    assert "No installed" in out


def test_tags_invalid_tag(mock_packages):
    out = tags("nosuchtag")
    assert "None" in out


def test_tags_all_mock_tags(mock_packages):
    out = tags()
    for tag in ["tag1", "tag2", "tag3"]:
        assert tag in out


def test_tags_all_mock_tag_packages(mock_packages):
    out = tags("-a")
    for pkg in ["mpich\n", "mpich2\n"]:
        assert pkg in out


def test_tags_no_tags(monkeypatch):
    class tag_path:
        tag_index = dict()

    monkeypatch.setattr(spack.repo, "PATH", tag_path)
    out = tags()
    assert "No tagged" in out


def test_tags_installed(install_mockery, mock_fetch):
    s = spack.spec.Spec("mpich").concretized()
    s.package.do_install()

    out = tags("-i")
    for tag in ["tag1", "tag2"]:
        assert tag in out

    out = tags("-i", "tag1")
    assert "mpich" in out

    out = tags("-i", "tag3")
    assert "No installed" in out