summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2018-04-12 15:44:25 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2018-07-24 11:27:17 -0700
commitff83003eafd4ebe9d76b9850dc1be836a77828df (patch)
tree91669cd5bed1c9480b79f6291be4cf09c1a68b89 /lib
parent008f171a7e4ec46b528d2f3492f48a1fa5692d38 (diff)
downloadspack-ff83003eafd4ebe9d76b9850dc1be836a77828df.tar.gz
spack-ff83003eafd4ebe9d76b9850dc1be836a77828df.tar.bz2
spack-ff83003eafd4ebe9d76b9850dc1be836a77828df.tar.xz
spack-ff83003eafd4ebe9d76b9850dc1be836a77828df.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/cmd/lmod.py24
-rw-r--r--lib/spack/spack/test/conftest.py9
-rw-r--r--lib/spack/spack/test/modules/dotkit.py12
-rw-r--r--lib/spack/spack/test/modules/lmod.py46
-rw-r--r--lib/spack/spack/test/modules/tcl.py66
5 files changed, 79 insertions, 78 deletions
diff --git a/lib/spack/spack/test/cmd/lmod.py b/lib/spack/spack/test/cmd/lmod.py
index 5ab886b071..f8f9c6b6f0 100644
--- a/lib/spack/spack/test/cmd/lmod.py
+++ b/lib/spack/spack/test/cmd/lmod.py
@@ -28,12 +28,15 @@ import pytest
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)
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index c2323e5156..44350dfb50 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -33,6 +33,7 @@ import re
import ordereddict_backport
import py
import pytest
+import yaml
from llnl.util.filesystem import remove_linked_tree
@@ -407,9 +408,9 @@ def mock_fetch(mock_archive):
@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):
diff --git a/lib/spack/spack/test/modules/dotkit.py b/lib/spack/spack/test/modules/dotkit.py
index 2d4dbd863f..7885df91e4 100644
--- a/lib/spack/spack/test/modules/dotkit.py
+++ b/lib/spack/spack/test/modules/dotkit.py
@@ -33,12 +33,12 @@ writer_cls = spack.modules.dotkit.DotkitModulefileWriter
@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 @@ class TestDotkit(object):
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')
diff --git a/lib/spack/spack/test/modules/lmod.py b/lib/spack/spack/test/modules/lmod.py
index 82a31b03a3..b615619a92 100644
--- a/lib/spack/spack/test/modules/lmod.py
+++ b/lib/spack/spack/test/modules/lmod.py
@@ -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 @@ class TestLmod(object):
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 @@ class TestLmod(object):
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 @@ class TestLmod(object):
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 @@ class TestLmod(object):
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 @@ class TestLmod(object):
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 @@ class TestLmod(object):
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
diff --git a/lib/spack/spack/test/modules/tcl.py b/lib/spack/spack/test/modules/tcl.py
index 6c56dfaf3f..52415bd791 100644
--- a/lib/spack/spack/test/modules/tcl.py
+++ b/lib/spack/spack/test/modules/tcl.py
@@ -39,18 +39,18 @@ writer_cls = spack.modules.tcl.TclModulefileWriter
@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 @@ class TestTcl(object):
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 @@ class TestTcl(object):
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 @@ class TestTcl(object):
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 @@ class TestTcl(object):
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 @@ class TestTcl(object):
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 @@ class TestTcl(object):
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 @@ class TestTcl(object):
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 @@ class TestTcl(object):
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 @@ class TestTcl(object):
) == 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 @@ class TestTcl(object):
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