summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/cmd/reindex.py
blob: e2049b66713209b3eb65e83a1e39f7c3a1db8059 (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-2022 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 os
import sys

import pytest

import spack.store
from spack.main import SpackCommand

install = SpackCommand('install')
deprecate = SpackCommand('deprecate')
reindex = SpackCommand('reindex')


@pytest.mark.skipif(sys.platform == 'win32', reason="All Fetchers Failed")
def test_reindex_basic(mock_packages, mock_archive, mock_fetch,
                       install_mockery):
    install('libelf@0.8.13')
    install('libelf@0.8.12')

    all_installed = spack.store.db.query()

    reindex()

    assert spack.store.db.query() == all_installed


@pytest.mark.skipif(sys.platform == 'win32', reason="All Fetchers Failed")
def test_reindex_db_deleted(mock_packages, mock_archive, mock_fetch,
                            install_mockery):
    install('libelf@0.8.13')
    install('libelf@0.8.12')

    all_installed = spack.store.db.query()

    os.remove(spack.store.db._index_path)
    reindex()

    assert spack.store.db.query() == all_installed


@pytest.mark.skipif(sys.platform == 'win32', reason="All Fetchers Failed")
def test_reindex_with_deprecated_packages(mock_packages, mock_archive,
                                          mock_fetch, install_mockery):
    install('libelf@0.8.13')
    install('libelf@0.8.12')

    deprecate('-y', 'libelf@0.8.12', 'libelf@0.8.13')

    all_installed = spack.store.db.query(installed=any)
    non_deprecated = spack.store.db.query(installed=True)

    os.remove(spack.store.db._index_path)
    reindex()

    assert spack.store.db.query(installed=any) == all_installed
    assert spack.store.db.query(installed=True) == non_deprecated