|
39 | 39 | from easybuild.tools import modules, StrictVersion |
40 | 40 | from easybuild.tools.build_log import EasyBuildError |
41 | 41 | from easybuild.tools.filetools import read_file, which, write_file |
42 | | -from easybuild.tools.modules import Lmod |
| 42 | +from easybuild.tools.modules import EnvironmentModules, Lmod |
43 | 43 | from test.framework.utilities import init_config |
44 | 44 |
|
45 | 45 |
|
@@ -192,6 +192,23 @@ def test_lmod_specific(self): |
192 | 192 | # test updating local spider cache (but don't actually update the local cache file!) |
193 | 193 | self.assertTrue(lmod.update(), "Updated local Lmod spider cache is non-empty") |
194 | 194 |
|
| 195 | + def test_environment_modules_specific(self): |
| 196 | + """Environment Modules-specific test (skipped unless installed).""" |
| 197 | + modulecmd_abspath = which(EnvironmentModules.COMMAND) |
| 198 | + # only run this test if 'modulecmd.tcl' is installed |
| 199 | + if modulecmd_abspath is not None: |
| 200 | + # redefine 'module' and '_module_raw' function (deliberate mismatch with used module |
| 201 | + # command in EnvironmentModules) |
| 202 | + os.environ['_module_raw'] = "() { eval `/usr/share/Modules/libexec/foo.tcl' bash $*`;\n}" |
| 203 | + os.environ['module'] = "() { _module_raw \"$@\" 2>&1;\n}" |
| 204 | + error_regex = ".*pattern .* not found in defined 'module' function" |
| 205 | + self.assertErrorRegex(EasyBuildError, error_regex, EnvironmentModules, testing=True) |
| 206 | + |
| 207 | + # redefine '_module_raw' function with correct module command |
| 208 | + os.environ['_module_raw'] = "() { eval `/usr/share/Modules/libexec/modulecmd.tcl' bash $*`;\n}" |
| 209 | + mt = EnvironmentModules(testing=True) |
| 210 | + self.assertIsInstance(mt.loaded_modules(), list) # dummy usage |
| 211 | + |
195 | 212 | def tearDown(self): |
196 | 213 | """Testcase cleanup.""" |
197 | 214 | super(ModulesToolTest, self).tearDown() |
|
0 commit comments