summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/modules/lmod.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/spack/test/modules/lmod.py')
-rw-r--r--lib/spack/spack/test/modules/lmod.py218
1 files changed, 95 insertions, 123 deletions
diff --git a/lib/spack/spack/test/modules/lmod.py b/lib/spack/spack/test/modules/lmod.py
index 66dc8f90de..58c013ef86 100644
--- a/lib/spack/spack/test/modules/lmod.py
+++ b/lib/spack/spack/test/modules/lmod.py
@@ -12,47 +12,45 @@ import spack.main
import spack.modules.lmod
import spack.spec
-mpich_spec_string = 'mpich@3.0.4'
-mpileaks_spec_string = 'mpileaks'
-libdwarf_spec_string = 'libdwarf arch=x64-linux'
+mpich_spec_string = "mpich@3.0.4"
+mpileaks_spec_string = "mpileaks"
+libdwarf_spec_string = "libdwarf arch=x64-linux"
-install = spack.main.SpackCommand('install')
+install = spack.main.SpackCommand("install")
#: Class of the writer tested in this module
writer_cls = spack.modules.lmod.LmodModulefileWriter
-pytestmark = pytest.mark.skipif(sys.platform == "win32",
- reason="does not run on windows")
+pytestmark = pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
-@pytest.fixture(params=[
- 'clang@3.3',
- 'gcc@4.5.0'
-])
+@pytest.fixture(params=["clang@3.3", "gcc@4.5.0"])
def compiler(request):
return request.param
-@pytest.fixture(params=[
- ('mpich@3.0.4', ('mpi',)),
- ('mpich@3.0.1', []),
- ('openblas@0.2.15', ('blas',)),
- ('openblas-with-lapack@0.2.15', ('blas', 'lapack'))
-])
+@pytest.fixture(
+ params=[
+ ("mpich@3.0.4", ("mpi",)),
+ ("mpich@3.0.1", []),
+ ("openblas@0.2.15", ("blas",)),
+ ("openblas-with-lapack@0.2.15", ("blas", "lapack")),
+ ]
+)
def provider(request):
return request.param
-@pytest.mark.usefixtures('config', 'mock_packages',)
+@pytest.mark.usefixtures(
+ "config",
+ "mock_packages",
+)
class TestLmod(object):
-
- def test_file_layout(
- self, compiler, provider, factory, module_configuration
- ):
+ def test_file_layout(self, compiler, provider, factory, module_configuration):
"""Tests the layout of files in the hierarchy is the one expected."""
- module_configuration('complex_hierarchy')
+ module_configuration("complex_hierarchy")
spec_string, services = provider
- module, spec = factory(spec_string + '%' + compiler)
+ module, spec = factory(spec_string + "%" + compiler)
layout = module.layout
@@ -64,21 +62,21 @@ class TestLmod(object):
# is transformed to r"Core" if the compiler is listed among core
# compilers
# Check that specs listed as core_specs are transformed to "Core"
- if compiler == 'clang@3.3' or spec_string == 'mpich@3.0.1':
- assert 'Core' in layout.available_path_parts
+ if compiler == "clang@3.3" or spec_string == "mpich@3.0.1":
+ assert "Core" in layout.available_path_parts
else:
- assert compiler.replace('@', '/') in layout.available_path_parts
+ assert compiler.replace("@", "/") in layout.available_path_parts
# Check that the provider part instead has always an hash even if
# hash has been disallowed in the configuration file
path_parts = layout.available_path_parts
- service_part = spec_string.replace('@', '/')
- service_part = '-'.join([service_part, layout.spec.dag_hash(length=7)])
+ service_part = spec_string.replace("@", "/")
+ service_part = "-".join([service_part, layout.spec.dag_hash(length=7)])
assert service_part in path_parts
# Check that multi-providers have repetitions in path parts
repetitions = len([x for x in path_parts if service_part == x])
- if spec_string == 'openblas-with-lapack@0.2.15':
+ if spec_string == "openblas-with-lapack@0.2.15":
assert repetitions == 2
else:
assert repetitions == 1
@@ -86,64 +84,53 @@ class TestLmod(object):
def test_simple_case(self, modulefile_content, module_configuration):
"""Tests the generation of a simple TCL module file."""
- module_configuration('autoload_direct')
+ module_configuration("autoload_direct")
content = modulefile_content(mpich_spec_string)
- assert '-- -*- lua -*-' in content
- assert 'whatis([[Name : mpich]])' in content
- assert 'whatis([[Version : 3.0.4]])' in content
+ assert "-- -*- lua -*-" in content
+ assert "whatis([[Name : mpich]])" in content
+ assert "whatis([[Version : 3.0.4]])" in content
assert 'family("mpi")' in content
def test_autoload_direct(self, modulefile_content, module_configuration):
"""Tests the automatic loading of direct dependencies."""
- module_configuration('autoload_direct')
+ module_configuration("autoload_direct")
content = modulefile_content(mpileaks_spec_string)
- assert len([x for x in content if 'depends_on(' in x]) == 2
+ assert len([x for x in content if "depends_on(" in x]) == 2
def test_autoload_all(self, modulefile_content, module_configuration):
"""Tests the automatic loading of all dependencies."""
- module_configuration('autoload_all')
+ module_configuration("autoload_all")
content = modulefile_content(mpileaks_spec_string)
- assert len([x for x in content if 'depends_on(' in x]) == 5
+ assert len([x for x in content if "depends_on(" in x]) == 5
# DEPRECATED: remove blacklist in v0.20
- @pytest.mark.parametrize(
- "config_name", ["alter_environment", "blacklist_environment"]
- )
- def test_alter_environment(
- self, modulefile_content, module_configuration, config_name
- ):
+ @pytest.mark.parametrize("config_name", ["alter_environment", "blacklist_environment"])
+ def test_alter_environment(self, modulefile_content, module_configuration, config_name):
"""Tests modifications to run-time environment."""
module_configuration(config_name)
- content = modulefile_content('mpileaks platform=test target=x86_64')
+ content = modulefile_content("mpileaks platform=test target=x86_64")
- assert len(
- [x for x in content if x.startswith('prepend_path("CMAKE_PREFIX_PATH"')]
- ) == 0
+ assert len([x for x in content if x.startswith('prepend_path("CMAKE_PREFIX_PATH"')]) == 0
assert len([x for x in content if 'setenv("FOO", "foo")' in x]) == 1
assert len([x for x in content if 'unsetenv("BAR")' in x]) == 1
- content = modulefile_content(
- 'libdwarf platform=test target=core2'
- )
+ content = modulefile_content("libdwarf platform=test target=core2")
- assert len(
- [x for x in content if x.startswith('prepend-path("CMAKE_PREFIX_PATH"')]
- ) == 0
+ assert len([x for x in content if x.startswith('prepend-path("CMAKE_PREFIX_PATH"')]) == 0
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_prepend_path_separator(self, modulefile_content,
- module_configuration):
+ def test_prepend_path_separator(self, modulefile_content, module_configuration):
"""Tests modifications to run-time environment."""
- module_configuration('module_path_separator')
- content = modulefile_content('module-path-separator')
+ module_configuration("module_path_separator")
+ content = modulefile_content("module-path-separator")
for line in content:
if re.match(r'[a-z]+_path\("COLON"', line):
@@ -158,7 +145,7 @@ class TestLmod(object):
module_configuration(config_name)
content = modulefile_content(mpileaks_spec_string)
- assert len([x for x in content if 'depends_on(' in x]) == 1
+ assert len([x for x in content if "depends_on(" in x]) == 1
def test_no_hash(self, factory, module_configuration):
"""Makes sure that virtual providers (in the hierarchy) always
@@ -166,10 +153,10 @@ class TestLmod(object):
does not include a hash if hash_length is 0.
"""
- module_configuration('no_hash')
+ module_configuration("no_hash")
module, spec = factory(mpileaks_spec_string)
path = module.layout.filename
- mpi_spec = spec['mpi']
+ mpi_spec = spec["mpi"]
mpi_element = "{0}/{1}-{2}/".format(
mpi_spec.name, mpi_spec.version, mpi_spec.dag_hash(length=7)
@@ -178,9 +165,7 @@ class TestLmod(object):
assert mpi_element in path
mpileaks_spec = spec
- mpileaks_element = "{0}/{1}.lua".format(
- mpileaks_spec.name, mpileaks_spec.version
- )
+ mpileaks_element = "{0}/{1}.lua".format(mpileaks_spec.name, mpileaks_spec.version)
assert path.endswith(mpileaks_element)
@@ -190,14 +175,14 @@ class TestLmod(object):
"""
# In this case we miss the entry completely
- module_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
- module_configuration('core_compilers_empty')
+ module_configuration("core_compilers_empty")
module, spec = factory(mpileaks_spec_string)
with pytest.raises(spack.modules.lmod.CoreCompilersNotFoundError):
@@ -207,77 +192,71 @@ class TestLmod(object):
"""Ensures that if a non-virtual is in hierarchy, an exception will
be raised.
"""
- module_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, module_configuration
- ):
+ def test_override_template_in_package(self, modulefile_content, module_configuration):
"""Tests overriding a template from and attribute in the package."""
- module_configuration('autoload_direct')
- content = modulefile_content('override-module-templates')
+ module_configuration("autoload_direct")
+ content = modulefile_content("override-module-templates")
- assert 'Override successful!' in content
+ assert "Override successful!" in content
- def test_override_template_in_modules_yaml(
- self, modulefile_content, module_configuration
- ):
+ def test_override_template_in_modules_yaml(self, modulefile_content, module_configuration):
"""Tests overriding a template from `modules.yaml`"""
- module_configuration('override_template')
+ module_configuration("override_template")
- content = modulefile_content('override-module-templates')
- assert 'Override even better!' in content
+ content = modulefile_content("override-module-templates")
+ assert "Override even better!" in content
- content = modulefile_content('mpileaks target=x86_64')
- assert 'Override even better!' in content
+ content = modulefile_content("mpileaks target=x86_64")
+ assert "Override even better!" in content
- @pytest.mark.usefixtures('config')
- def test_external_configure_args(
- self, factory
- ):
+ @pytest.mark.usefixtures("config")
+ def test_external_configure_args(self, factory):
# If this package is detected as an external, its configure option line
# in the module file starts with 'unknown'
- writer, spec = factory('externaltool')
+ writer, spec = factory("externaltool")
- assert 'unknown' in writer.context.configure_options
+ assert "unknown" in writer.context.configure_options
- def test_guess_core_compilers(
- self, factory, module_configuration, monkeypatch
- ):
+ def test_guess_core_compilers(self, factory, module_configuration, monkeypatch):
"""Check that we can guess core compilers."""
# In this case we miss the entry completely
- module_configuration('missing_core_compilers')
+ module_configuration("missing_core_compilers")
# Our mock paths must be detected as system paths
- monkeypatch.setattr(
- spack.util.environment, 'system_dirs', ['/path/to']
- )
+ monkeypatch.setattr(spack.util.environment, "system_dirs", ["/path/to"])
# We don't want to really write into user configuration
# when running tests
def no_op_set(*args, **kwargs):
pass
- monkeypatch.setattr(spack.config, 'set', no_op_set)
+
+ monkeypatch.setattr(spack.config, "set", no_op_set)
# Assert we have core compilers now
writer, _ = factory(mpileaks_spec_string)
assert writer.conf.core_compilers
- @pytest.mark.parametrize('spec_str', [
- 'mpileaks target=nocona',
- 'mpileaks target=core2',
- 'mpileaks target=x86_64',
- ])
- @pytest.mark.regression('13005')
+ @pytest.mark.parametrize(
+ "spec_str",
+ [
+ "mpileaks target=nocona",
+ "mpileaks target=core2",
+ "mpileaks target=x86_64",
+ ],
+ )
+ @pytest.mark.regression("13005")
def test_only_generic_microarchitectures_in_root(
- self, spec_str, factory, module_configuration
+ self, spec_str, factory, module_configuration
):
- module_configuration('complex_hierarchy')
+ module_configuration("complex_hierarchy")
writer, spec = factory(spec_str)
assert str(spec.target.family) in writer.layout.arch_dirname
@@ -289,17 +268,14 @@ class TestLmod(object):
# This configuration has no error, so check the conflicts directives
# are there
- module_configuration('projections')
+ module_configuration("projections")
# Test we read the expected configuration for the naming scheme
- writer, _ = factory('mpileaks')
- expected = {
- 'all': '{name}/v{version}',
- 'mpileaks': '{name}-mpiprojection'
- }
+ writer, _ = factory("mpileaks")
+ expected = {"all": "{name}/v{version}", "mpileaks": "{name}-mpiprojection"}
assert writer.conf.projections == expected
- projection = writer.spec.format(writer.conf.projections['mpileaks'])
+ projection = writer.spec.format(writer.conf.projections["mpileaks"])
assert projection in writer.layout.use_name
def test_projections_all(self, factory, module_configuration):
@@ -307,30 +283,26 @@ class TestLmod(object):
# This configuration has no error, so check the conflicts directives
# are there
- module_configuration('projections')
+ module_configuration("projections")
# Test we read the expected configuration for the naming scheme
- writer, _ = factory('libelf')
- expected = {
- 'all': '{name}/v{version}',
- 'mpileaks': '{name}-mpiprojection'
- }
+ writer, _ = factory("libelf")
+ expected = {"all": "{name}/v{version}", "mpileaks": "{name}-mpiprojection"}
assert writer.conf.projections == expected
- projection = writer.spec.format(writer.conf.projections['all'])
+ projection = writer.spec.format(writer.conf.projections["all"])
assert projection in writer.layout.use_name
def test_modules_relative_to_view(
- self, tmpdir, modulefile_content, module_configuration, install_mockery,
- mock_fetch
+ self, tmpdir, modulefile_content, module_configuration, install_mockery, mock_fetch
):
with ev.Environment(str(tmpdir), with_view=True) as e:
- module_configuration('with_view')
- install('cmake')
+ module_configuration("with_view")
+ install("cmake")
- spec = spack.spec.Spec('cmake').concretized()
+ spec = spack.spec.Spec("cmake").concretized()
- content = modulefile_content('cmake')
+ content = modulefile_content("cmake")
expected = e.default_view.get_projection_for_spec(spec)
# Rather than parse all lines, ensure all prefixes in the content
# point to the right one
@@ -338,7 +310,7 @@ class TestLmod(object):
assert not any(spec.prefix in line for line in content)
def test_modules_no_arch(self, factory, module_configuration):
- module_configuration('no_arch')
+ module_configuration("no_arch")
module, spec = factory(mpileaks_spec_string)
path = module.layout.filename