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
87
88
89
90
91
92
93
|
# Copyright 2013-2019 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
from llnl.util.filesystem import mkdirp
import spack.config
import spack.environment as ev
from spack.main import SpackCommand
config = SpackCommand('config')
def test_get_config_scope(mock_config):
assert config('get', 'compilers').strip() == 'compilers: {}'
def test_get_config_scope_merged(mock_config):
low_path = mock_config.scopes['low'].path
high_path = mock_config.scopes['high'].path
mkdirp(low_path)
mkdirp(high_path)
with open(os.path.join(low_path, 'repos.yaml'), 'w') as f:
f.write('''\
repos:
- repo3
''')
with open(os.path.join(high_path, 'repos.yaml'), 'w') as f:
f.write('''\
repos:
- repo1
- repo2
''')
assert config('get', 'repos').strip() == '''repos:
- repo1
- repo2
- repo3'''
def test_config_edit():
"""Ensure `spack config edit` edits the right paths."""
dms = spack.config.default_modify_scope()
dms_path = spack.config.config.scopes[dms].path
user_path = spack.config.config.scopes['user'].path
comp_path = os.path.join(dms_path, 'compilers.yaml')
repos_path = os.path.join(user_path, 'repos.yaml')
assert config('edit', '--print-file', 'compilers').strip() == comp_path
assert config('edit', '--print-file', 'repos').strip() == repos_path
def test_config_get_gets_spack_yaml(mutable_mock_env_path):
env = ev.create('test')
config('get', fail_on_error=False)
assert config.returncode == 1
with env:
config('get', fail_on_error=False)
assert config.returncode == 1
env.write()
assert 'mpileaks' not in config('get')
env.add('mpileaks')
env.write()
assert 'mpileaks' in config('get')
def test_config_edit_edits_spack_yaml(mutable_mock_env_path):
env = ev.create('test')
with env:
assert config('edit', '--print-file').strip() == env.manifest_path
def test_config_edit_fails_correctly_with_no_env(mutable_mock_env_path):
output = config('edit', '--print-file', fail_on_error=False)
assert "requires a section argument or an active environment" in output
def test_config_get_fails_correctly_with_no_env(mutable_mock_env_path):
output = config('get', fail_on_error=False)
assert "requires a section argument or an active environment" in output
|