Renamed 'patch_configuration' fixture to 'module_configuration'
This just because the fixture has been moved one level above the one it was originally defined. In this more general context there's more than one configuration file that could be patched for tests.
This commit is contained in:
parent
008f171a7e
commit
ff83003eaf
5 changed files with 79 additions and 78 deletions
|
@ -28,12 +28,15 @@
|
|||
|
||||
import spack.main
|
||||
import spack.modules
|
||||
import spack.spec
|
||||
|
||||
lmod = spack.main.SpackCommand('lmod')
|
||||
|
||||
# Needed to make the fixture work
|
||||
writer_cls = spack.modules.lmod.LmodModulefileWriter
|
||||
|
||||
# TODO : add tests for loads and find to check the prompt format
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
params=[
|
||||
|
@ -47,26 +50,23 @@ def failure_args(request):
|
|||
return request.param
|
||||
|
||||
|
||||
# TODO : test the --delete-tree option
|
||||
# TODO : this requires having a separate directory for test modules
|
||||
# TODO : add tests for loads and find to check the prompt format
|
||||
|
||||
|
||||
def test_exit_with_failure(database, failure_args):
|
||||
with pytest.raises(spack.main.SpackCommandError):
|
||||
lmod(*failure_args)
|
||||
|
||||
|
||||
def test_setdefault_command(refresh_db_on_exit, database, patch_configuration):
|
||||
def test_setdefault_command(
|
||||
mutable_database, module_configuration
|
||||
):
|
||||
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
|
||||
# Install two different versions of a package
|
||||
other_spec, preferred = 'a@1.0', 'a@2.0'
|
||||
database.install(preferred)
|
||||
database.install(other_spec)
|
||||
|
||||
writer_cls = spack.modules.module_types['lmod']
|
||||
spack.spec.Spec(other_spec).concretized().package.do_install(fake=True)
|
||||
spack.spec.Spec(preferred).concretized().package.do_install(fake=True)
|
||||
|
||||
writers = {
|
||||
preferred: writer_cls(spack.spec.Spec(preferred).concretized()),
|
||||
other_spec: writer_cls(spack.spec.Spec(other_spec).concretized())
|
||||
|
@ -87,7 +87,7 @@ def test_setdefault_command(refresh_db_on_exit, database, patch_configuration):
|
|||
# Set the default to be the other spec
|
||||
lmod('setdefault', other_spec)
|
||||
|
||||
# Check that a link named default exists, and points to the right file
|
||||
# Check that a link named 'default' exists, and points to the right file
|
||||
for k in preferred, other_spec:
|
||||
assert os.path.exists(writers[k].layout.filename)
|
||||
assert os.path.exists(link_name) and os.path.islink(link_name)
|
||||
|
@ -96,7 +96,7 @@ def test_setdefault_command(refresh_db_on_exit, database, patch_configuration):
|
|||
# Reset the default to be the preferred spec
|
||||
lmod('setdefault', preferred)
|
||||
|
||||
# Check that a link named default exists, and points to the right file
|
||||
# Check that a link named 'default' exists, and points to the right file
|
||||
for k in preferred, other_spec:
|
||||
assert os.path.exists(writers[k].layout.filename)
|
||||
assert os.path.exists(link_name) and os.path.islink(link_name)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
import ordereddict_backport
|
||||
import py
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from llnl.util.filesystem import remove_linked_tree
|
||||
|
||||
|
@ -407,9 +408,9 @@ def fake_fn(self):
|
|||
|
||||
|
||||
@pytest.fixture()
|
||||
def patch_configuration(monkeypatch, request):
|
||||
"""Reads a configuration file from the mock ones prepared for tests
|
||||
and monkeypatches the right classes to hook it in.
|
||||
def module_configuration(monkeypatch, request):
|
||||
"""Reads the module configuration file from the mock ones prepared
|
||||
for tests and monkeypatches the right classes to hook it in.
|
||||
"""
|
||||
# Class of the module file writer
|
||||
writer_cls = getattr(request.module, 'writer_cls')
|
||||
|
@ -419,7 +420,7 @@ def patch_configuration(monkeypatch, request):
|
|||
writer_key = str(writer_mod.__name__).split('.')[-1]
|
||||
# Root folder for configuration
|
||||
root_for_conf = os.path.join(
|
||||
spack.test_path, 'data', 'modules', writer_key
|
||||
spack.paths.test_path, 'data', 'modules', writer_key
|
||||
)
|
||||
|
||||
def _impl(filename):
|
||||
|
|
|
@ -33,12 +33,12 @@
|
|||
@pytest.mark.usefixtures('config', 'mock_packages')
|
||||
class TestDotkit(object):
|
||||
|
||||
def test_dotkit(self, modulefile_content, patch_configuration):
|
||||
def test_dotkit(self, modulefile_content, module_configuration):
|
||||
"""Tests the generation of a dotkit file that loads dependencies
|
||||
automatically.
|
||||
"""
|
||||
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
content = modulefile_content('mpileaks arch=x86-linux')
|
||||
|
||||
assert '#c spack' in content
|
||||
|
@ -46,21 +46,21 @@ def test_dotkit(self, modulefile_content, patch_configuration):
|
|||
assert len([x for x in content if 'dk_op' in x]) == 2
|
||||
|
||||
def test_override_template_in_package(
|
||||
self, modulefile_content, patch_configuration
|
||||
self, modulefile_content, module_configuration
|
||||
):
|
||||
"""Tests overriding a template from and attribute in the package."""
|
||||
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
content = modulefile_content('override-module-templates')
|
||||
|
||||
assert 'Override successful!' in content
|
||||
|
||||
def test_override_template_in_modules_yaml(
|
||||
self, modulefile_content, patch_configuration
|
||||
self, modulefile_content, module_configuration
|
||||
):
|
||||
"""Tests overriding a template from `modules.yaml`"""
|
||||
|
||||
patch_configuration('override_template')
|
||||
module_configuration('override_template')
|
||||
|
||||
# Check that this takes precedence over an attribute in the package
|
||||
content = modulefile_content('override-module-templates')
|
||||
|
|
|
@ -56,10 +56,10 @@ def provider(request):
|
|||
class TestLmod(object):
|
||||
|
||||
def test_file_layout(
|
||||
self, compiler, provider, factory, patch_configuration
|
||||
self, compiler, provider, factory, module_configuration
|
||||
):
|
||||
"""Tests the layout of files in the hierarchy is the one expected."""
|
||||
patch_configuration('complex_hierarchy')
|
||||
module_configuration('complex_hierarchy')
|
||||
spec_string, services = provider
|
||||
module, spec = factory(spec_string + '%' + compiler)
|
||||
|
||||
|
@ -91,10 +91,10 @@ def test_file_layout(
|
|||
else:
|
||||
assert repetitions == 1
|
||||
|
||||
def test_simple_case(self, modulefile_content, patch_configuration):
|
||||
def test_simple_case(self, modulefile_content, module_configuration):
|
||||
"""Tests the generation of a simple TCL module file."""
|
||||
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
content = modulefile_content(mpich_spec_string)
|
||||
|
||||
assert '-- -*- lua -*-' in content
|
||||
|
@ -102,10 +102,10 @@ def test_simple_case(self, modulefile_content, patch_configuration):
|
|||
assert 'whatis([[Version : 3.0.4]])' in content
|
||||
assert 'family("mpi")' in content
|
||||
|
||||
def test_autoload_direct(self, modulefile_content, patch_configuration):
|
||||
def test_autoload_direct(self, modulefile_content, module_configuration):
|
||||
"""Tests the automatic loading of direct dependencies."""
|
||||
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
content = modulefile_content(mpileaks_spec_string)
|
||||
|
||||
assert len([x for x in content if 'if not isloaded(' in x]) == 2
|
||||
|
@ -116,10 +116,10 @@ def test_autoload_direct(self, modulefile_content, patch_configuration):
|
|||
messages = [x for x in content if 'LmodMessage("Autoloading' in x]
|
||||
assert len(messages) == 0
|
||||
|
||||
def test_autoload_all(self, modulefile_content, patch_configuration):
|
||||
def test_autoload_all(self, modulefile_content, module_configuration):
|
||||
"""Tests the automatic loading of all dependencies."""
|
||||
|
||||
patch_configuration('autoload_all')
|
||||
module_configuration('autoload_all')
|
||||
content = modulefile_content(mpileaks_spec_string)
|
||||
|
||||
assert len([x for x in content if 'if not isloaded(' in x]) == 5
|
||||
|
@ -129,10 +129,10 @@ def test_autoload_all(self, modulefile_content, patch_configuration):
|
|||
messages = [x for x in content if 'LmodMessage("Autoloading' in x]
|
||||
assert len(messages) == 5
|
||||
|
||||
def test_alter_environment(self, modulefile_content, patch_configuration):
|
||||
def test_alter_environment(self, modulefile_content, module_configuration):
|
||||
"""Tests modifications to run-time environment."""
|
||||
|
||||
patch_configuration('alter_environment')
|
||||
module_configuration('alter_environment')
|
||||
content = modulefile_content('mpileaks platform=test target=x86_64')
|
||||
|
||||
assert len(
|
||||
|
@ -151,22 +151,22 @@ def test_alter_environment(self, modulefile_content, patch_configuration):
|
|||
assert len([x for x in content if 'setenv("FOO", "foo")' in x]) == 0
|
||||
assert len([x for x in content if 'unsetenv("BAR")' in x]) == 0
|
||||
|
||||
def test_blacklist(self, modulefile_content, patch_configuration):
|
||||
def test_blacklist(self, modulefile_content, module_configuration):
|
||||
"""Tests blacklisting the generation of selected modules."""
|
||||
|
||||
patch_configuration('blacklist')
|
||||
module_configuration('blacklist')
|
||||
content = modulefile_content(mpileaks_spec_string)
|
||||
|
||||
assert len([x for x in content if 'if not isloaded(' in x]) == 1
|
||||
assert len([x for x in content if 'load(' in x]) == 1
|
||||
|
||||
def test_no_hash(self, factory, patch_configuration):
|
||||
def test_no_hash(self, factory, module_configuration):
|
||||
"""Makes sure that virtual providers (in the hierarchy) always
|
||||
include a hash. Make sure that the module file for the spec
|
||||
does not include a hash if hash_length is 0.
|
||||
"""
|
||||
|
||||
patch_configuration('no_hash')
|
||||
module_configuration('no_hash')
|
||||
module, spec = factory(mpileaks_spec_string)
|
||||
path = module.layout.filename
|
||||
mpi_spec = spec['mpi']
|
||||
|
@ -184,50 +184,50 @@ def test_no_hash(self, factory, patch_configuration):
|
|||
|
||||
assert path.endswith(mpileaks_element)
|
||||
|
||||
def test_no_core_compilers(self, factory, patch_configuration):
|
||||
def test_no_core_compilers(self, factory, module_configuration):
|
||||
"""Ensures that missing 'core_compilers' in the configuration file
|
||||
raises the right exception.
|
||||
"""
|
||||
|
||||
# In this case we miss the entry completely
|
||||
patch_configuration('missing_core_compilers')
|
||||
module_configuration('missing_core_compilers')
|
||||
|
||||
module, spec = factory(mpileaks_spec_string)
|
||||
with pytest.raises(spack.modules.lmod.CoreCompilersNotFoundError):
|
||||
module.write()
|
||||
|
||||
# Here we have an empty list
|
||||
patch_configuration('core_compilers_empty')
|
||||
module_configuration('core_compilers_empty')
|
||||
|
||||
module, spec = factory(mpileaks_spec_string)
|
||||
with pytest.raises(spack.modules.lmod.CoreCompilersNotFoundError):
|
||||
module.write()
|
||||
|
||||
def test_non_virtual_in_hierarchy(self, factory, patch_configuration):
|
||||
def test_non_virtual_in_hierarchy(self, factory, module_configuration):
|
||||
"""Ensures that if a non-virtual is in hierarchy, an exception will
|
||||
be raised.
|
||||
"""
|
||||
patch_configuration('non_virtual_in_hierarchy')
|
||||
module_configuration('non_virtual_in_hierarchy')
|
||||
|
||||
module, spec = factory(mpileaks_spec_string)
|
||||
with pytest.raises(spack.modules.lmod.NonVirtualInHierarchyError):
|
||||
module.write()
|
||||
|
||||
def test_override_template_in_package(
|
||||
self, modulefile_content, patch_configuration
|
||||
self, modulefile_content, module_configuration
|
||||
):
|
||||
"""Tests overriding a template from and attribute in the package."""
|
||||
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
content = modulefile_content('override-module-templates')
|
||||
|
||||
assert 'Override successful!' in content
|
||||
|
||||
def test_override_template_in_modules_yaml(
|
||||
self, modulefile_content, patch_configuration
|
||||
self, modulefile_content, module_configuration
|
||||
):
|
||||
"""Tests overriding a template from `modules.yaml`"""
|
||||
patch_configuration('override_template')
|
||||
module_configuration('override_template')
|
||||
|
||||
content = modulefile_content('override-module-templates')
|
||||
assert 'Override even better!' in content
|
||||
|
|
|
@ -39,18 +39,18 @@
|
|||
@pytest.mark.usefixtures('config', 'mock_packages')
|
||||
class TestTcl(object):
|
||||
|
||||
def test_simple_case(self, modulefile_content, patch_configuration):
|
||||
def test_simple_case(self, modulefile_content, module_configuration):
|
||||
"""Tests the generation of a simple TCL module file."""
|
||||
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
content = modulefile_content(mpich_spec_string)
|
||||
|
||||
assert 'module-whatis "mpich @3.0.4"' in content
|
||||
|
||||
def test_autoload_direct(self, modulefile_content, patch_configuration):
|
||||
def test_autoload_direct(self, modulefile_content, module_configuration):
|
||||
"""Tests the automatic loading of direct dependencies."""
|
||||
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
content = modulefile_content(mpileaks_spec_string)
|
||||
|
||||
assert len([x for x in content if 'is-loaded' in x]) == 2
|
||||
|
@ -70,10 +70,10 @@ def test_autoload_direct(self, modulefile_content, patch_configuration):
|
|||
messages = [x for x in content if 'puts stderr "Autoloading' in x]
|
||||
assert len(messages) == 0
|
||||
|
||||
def test_autoload_all(self, modulefile_content, patch_configuration):
|
||||
def test_autoload_all(self, modulefile_content, module_configuration):
|
||||
"""Tests the automatic loading of all dependencies."""
|
||||
|
||||
patch_configuration('autoload_all')
|
||||
module_configuration('autoload_all')
|
||||
content = modulefile_content(mpileaks_spec_string)
|
||||
|
||||
assert len([x for x in content if 'is-loaded' in x]) == 5
|
||||
|
@ -94,27 +94,27 @@ def test_autoload_all(self, modulefile_content, patch_configuration):
|
|||
assert len(messages) == 2
|
||||
|
||||
def test_prerequisites_direct(
|
||||
self, modulefile_content, patch_configuration
|
||||
self, modulefile_content, module_configuration
|
||||
):
|
||||
"""Tests asking direct dependencies as prerequisites."""
|
||||
|
||||
patch_configuration('prerequisites_direct')
|
||||
module_configuration('prerequisites_direct')
|
||||
content = modulefile_content('mpileaks arch=x86-linux')
|
||||
|
||||
assert len([x for x in content if 'prereq' in x]) == 2
|
||||
|
||||
def test_prerequisites_all(self, modulefile_content, patch_configuration):
|
||||
def test_prerequisites_all(self, modulefile_content, module_configuration):
|
||||
"""Tests asking all dependencies as prerequisites."""
|
||||
|
||||
patch_configuration('prerequisites_all')
|
||||
module_configuration('prerequisites_all')
|
||||
content = modulefile_content('mpileaks arch=x86-linux')
|
||||
|
||||
assert len([x for x in content if 'prereq' in x]) == 5
|
||||
|
||||
def test_alter_environment(self, modulefile_content, patch_configuration):
|
||||
def test_alter_environment(self, modulefile_content, module_configuration):
|
||||
"""Tests modifications to run-time environment."""
|
||||
|
||||
patch_configuration('alter_environment')
|
||||
module_configuration('alter_environment')
|
||||
content = modulefile_content('mpileaks platform=test target=x86_64')
|
||||
|
||||
assert len([x for x in content
|
||||
|
@ -143,10 +143,10 @@ def test_alter_environment(self, modulefile_content, patch_configuration):
|
|||
assert len([x for x in content if 'module load foo/bar' in x]) == 1
|
||||
assert len([x for x in content if 'setenv LIBDWARF_ROOT' in x]) == 1
|
||||
|
||||
def test_blacklist(self, modulefile_content, patch_configuration):
|
||||
def test_blacklist(self, modulefile_content, module_configuration):
|
||||
"""Tests blacklisting the generation of selected modules."""
|
||||
|
||||
patch_configuration('blacklist')
|
||||
module_configuration('blacklist')
|
||||
content = modulefile_content('mpileaks ^zmpi')
|
||||
|
||||
assert len([x for x in content if 'is-loaded' in x]) == 1
|
||||
|
@ -161,12 +161,12 @@ def test_blacklist(self, modulefile_content, patch_configuration):
|
|||
assert len([x for x in content if 'is-loaded' in x]) == 1
|
||||
assert len([x for x in content if 'module load ' in x]) == 1
|
||||
|
||||
def test_naming_scheme(self, factory, patch_configuration):
|
||||
def test_naming_scheme(self, factory, module_configuration):
|
||||
"""Tests reading the correct naming scheme."""
|
||||
|
||||
# This configuration has no error, so check the conflicts directives
|
||||
# are there
|
||||
patch_configuration('conflicts')
|
||||
module_configuration('conflicts')
|
||||
|
||||
# Test we read the expected configuration for the naming scheme
|
||||
writer, _ = factory('mpileaks')
|
||||
|
@ -174,10 +174,10 @@ def test_naming_scheme(self, factory, patch_configuration):
|
|||
|
||||
assert writer.conf.naming_scheme == expected
|
||||
|
||||
def test_invalid_naming_scheme(self, factory, patch_configuration):
|
||||
def test_invalid_naming_scheme(self, factory, module_configuration):
|
||||
"""Tests the evaluation of an invalid naming scheme."""
|
||||
|
||||
patch_configuration('invalid_naming_scheme')
|
||||
module_configuration('invalid_naming_scheme')
|
||||
|
||||
# Test that having invalid tokens in the naming scheme raises
|
||||
# a RuntimeError
|
||||
|
@ -185,21 +185,21 @@ def test_invalid_naming_scheme(self, factory, patch_configuration):
|
|||
with pytest.raises(RuntimeError):
|
||||
writer.layout.use_name
|
||||
|
||||
def test_invalid_token_in_env_name(self, factory, patch_configuration):
|
||||
def test_invalid_token_in_env_name(self, factory, module_configuration):
|
||||
"""Tests setting environment variables with an invalid name."""
|
||||
|
||||
patch_configuration('invalid_token_in_env_var_name')
|
||||
module_configuration('invalid_token_in_env_var_name')
|
||||
|
||||
writer, _ = factory('mpileaks')
|
||||
with pytest.raises(RuntimeError):
|
||||
writer.write()
|
||||
|
||||
def test_conflicts(self, modulefile_content, patch_configuration):
|
||||
def test_conflicts(self, modulefile_content, module_configuration):
|
||||
"""Tests adding conflicts to the module."""
|
||||
|
||||
# This configuration has no error, so check the conflicts directives
|
||||
# are there
|
||||
patch_configuration('conflicts')
|
||||
module_configuration('conflicts')
|
||||
content = modulefile_content('mpileaks')
|
||||
|
||||
assert len([x for x in content if x.startswith('conflict')]) == 2
|
||||
|
@ -207,13 +207,13 @@ def test_conflicts(self, modulefile_content, patch_configuration):
|
|||
assert len([x for x in content if x == 'conflict intel/14.0.1']) == 1
|
||||
|
||||
# This configuration is inconsistent, check an error is raised
|
||||
patch_configuration('wrong_conflicts')
|
||||
module_configuration('wrong_conflicts')
|
||||
with pytest.raises(SystemExit):
|
||||
modulefile_content('mpileaks')
|
||||
|
||||
def test_suffixes(self, patch_configuration, factory):
|
||||
def test_suffixes(self, module_configuration, factory):
|
||||
"""Tests adding suffixes to module file name."""
|
||||
patch_configuration('suffix')
|
||||
module_configuration('suffix')
|
||||
|
||||
writer, spec = factory('mpileaks+debug arch=x86-linux')
|
||||
assert 'foo' in writer.layout.use_name
|
||||
|
@ -221,10 +221,10 @@ def test_suffixes(self, patch_configuration, factory):
|
|||
writer, spec = factory('mpileaks~debug arch=x86-linux')
|
||||
assert 'bar' in writer.layout.use_name
|
||||
|
||||
def test_setup_environment(self, modulefile_content, patch_configuration):
|
||||
def test_setup_environment(self, modulefile_content, module_configuration):
|
||||
"""Tests the internal set-up of run-time environment."""
|
||||
|
||||
patch_configuration('suffix')
|
||||
module_configuration('suffix')
|
||||
content = modulefile_content('mpileaks')
|
||||
|
||||
assert len([x for x in content if 'setenv FOOBAR' in x]) == 1
|
||||
|
@ -242,20 +242,20 @@ def test_setup_environment(self, modulefile_content, patch_configuration):
|
|||
) == 1
|
||||
|
||||
def test_override_template_in_package(
|
||||
self, modulefile_content, patch_configuration
|
||||
self, modulefile_content, module_configuration
|
||||
):
|
||||
"""Tests overriding a template from and attribute in the package."""
|
||||
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
content = modulefile_content('override-module-templates')
|
||||
|
||||
assert 'Override successful!' in content
|
||||
|
||||
def test_override_template_in_modules_yaml(
|
||||
self, modulefile_content, patch_configuration
|
||||
self, modulefile_content, module_configuration
|
||||
):
|
||||
"""Tests overriding a template from `modules.yaml`"""
|
||||
patch_configuration('override_template')
|
||||
module_configuration('override_template')
|
||||
|
||||
content = modulefile_content('override-module-templates')
|
||||
assert 'Override even better!' in content
|
||||
|
@ -264,10 +264,10 @@ def test_override_template_in_modules_yaml(
|
|||
assert 'Override even better!' in content
|
||||
|
||||
def test_extend_context(
|
||||
self, modulefile_content, patch_configuration
|
||||
self, modulefile_content, module_configuration
|
||||
):
|
||||
"""Tests using a package defined context"""
|
||||
patch_configuration('autoload_direct')
|
||||
module_configuration('autoload_direct')
|
||||
content = modulefile_content('override-context-templates')
|
||||
|
||||
assert 'puts stderr "sentence from package"' in content
|
||||
|
|
Loading…
Reference in a new issue