summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/config_values.py
blob: 66005456103260787b4fe48281a11fbbc3b23e39 (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
# 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 sys

import pytest

import spack.spec
import spack.store

pytestmark = pytest.mark.skipif(sys.platform == "win32",
                                reason="does not run on windows")


@pytest.mark.parametrize('hash_length', [1, 2, 3, 4, 5, 9])
@pytest.mark.usefixtures('mock_packages')
def test_set_install_hash_length(hash_length, mutable_config, tmpdir):
    mutable_config.set('config:install_hash_length', hash_length)
    mutable_config.set('config:install_tree', {'root': str(tmpdir)})
    # The call below is to reinitialize the directory layout associated
    # with the store according to the configuration changes above (i.e.
    # with the shortened hash)
    store = spack.store._store()
    with spack.store.use_store(store):
        spec = spack.spec.Spec('libelf').concretized()
        prefix = spec.prefix
        hash_str = prefix.rsplit('-')[-1]
        assert len(hash_str) == hash_length


@pytest.mark.use_fixtures('mock_packages')
def test_set_install_hash_length_upper_case(mutable_config, tmpdir):
    mutable_config.set('config:install_hash_length', 5)
    mutable_config.set(
        'config:install_tree',
        {
            'root': str(tmpdir),
            'projections': {
                'all': '{name}-{HASH}'
            }
        }
    )
    # The call below is to reinitialize the directory layout associated
    # with the store according to the configuration changes above (i.e.
    # with the shortened hash and projection)
    store = spack.store._store()
    with spack.store.use_store(store):
        spec = spack.spec.Spec('libelf').concretized()
        prefix = spec.prefix
        hash_str = prefix.rsplit('-')[-1]
        assert len(hash_str) == 5