tests: consolidate mock scope creation logic in conftest.py

Config scopes were different for `config` and `mutable_config`,
and `mutable_config` did not have a command line scope.

- [x] Fix by consolidating the creation logic for the two fixtures.
This commit is contained in:
Todd Gamblin 2022-01-17 11:04:54 -08:00 committed by Greg Becker
parent 800ed16e7a
commit f155de7462
2 changed files with 18 additions and 22 deletions

View File

@ -103,16 +103,8 @@ def test_bootstrap_search_for_compilers_with_environment_active(
@pytest.mark.regression('26189')
def test_config_yaml_is_preserved_during_bootstrap(mutable_config):
# Mock the command line scope
expected_dir = '/tmp/test'
internal_scope = spack.config.InternalConfigScope(
name='command_line', data={
'config': {
'test_stage': expected_dir
}
}
)
spack.config.config.push_scope(internal_scope)
spack.config.set("config:test_stage", expected_dir, scope="command_line")
assert spack.config.get('config:test_stage') == expected_dir
with spack.bootstrap.ensure_bootstrap_configuration():

View File

@ -612,19 +612,23 @@ def configuration_dir(tmpdir_factory, linux_os):
shutil.rmtree(str(tmpdir))
def _create_mock_configuration_scopes(configuration_dir):
"""Create the configuration scopes used in `config` and `mutable_config`."""
scopes = [
spack.config.InternalConfigScope('_builtin', spack.config.config_defaults),
]
scopes += [
spack.config.ConfigScope(name, str(configuration_dir.join(name)))
for name in ['site', 'system', 'user']
]
scopes += [spack.config.InternalConfigScope('command_line')]
return scopes
@pytest.fixture(scope='session')
def mock_configuration_scopes(configuration_dir):
"""Create a persistent Configuration object from the configuration_dir."""
defaults = spack.config.InternalConfigScope(
'_builtin', spack.config.config_defaults
)
test_scopes = [defaults]
test_scopes += [
spack.config.ConfigScope(name, str(configuration_dir.join(name)))
for name in ['site', 'system', 'user']]
test_scopes.append(spack.config.InternalConfigScope('command_line'))
yield test_scopes
yield _create_mock_configuration_scopes(configuration_dir)
@pytest.fixture(scope='function')
@ -640,9 +644,7 @@ def mutable_config(tmpdir_factory, configuration_dir):
mutable_dir = tmpdir_factory.mktemp('mutable_config').join('tmp')
configuration_dir.copy(mutable_dir)
scopes = [spack.config.ConfigScope(name, str(mutable_dir.join(name)))
for name in ['site', 'system', 'user']]
scopes = _create_mock_configuration_scopes(mutable_dir)
with spack.config.use_configuration(*scopes) as cfg:
yield cfg
@ -662,6 +664,8 @@ def mutable_empty_config(tmpdir_factory, configuration_dir):
def no_compilers_yaml(mutable_config):
"""Creates a temporary configuration without compilers.yaml"""
for scope, local_config in mutable_config.scopes.items():
if not local_config.path: # skip internal scopes
continue
compilers_yaml = os.path.join(local_config.path, 'compilers.yaml')
if os.path.exists(compilers_yaml):
os.remove(compilers_yaml)