From 794c068e58a8571ab1330c1c6722364842c47d5e Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Wed, 5 Jun 2024 20:14:24 +0200 Subject: [PATCH] fix tests that got broken by enabling use of depends_on (instead of load) statement in generated environment modules by default --- test/framework/easyblock.py | 17 ++++++++-------- test/framework/easyconfig.py | 6 ++++++ test/framework/toy_build.py | 38 +++++++++++++++++++++++------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/test/framework/easyblock.py b/test/framework/easyblock.py index 61e2f5683d..1c0c896716 100644 --- a/test/framework/easyblock.py +++ b/test/framework/easyblock.py @@ -743,6 +743,7 @@ def test_make_module_dep(self): " ('FFTW', '3.3.7'),", " ('OpenBLAS', '0.2.20', '', ('GCC', '6.4.0-2.28')),", ']', + 'module_depends_on = False', ]) self.writeEC() eb = EasyBlock(EasyConfig(self.eb_file)) @@ -856,10 +857,10 @@ def test_make_module_dep_hmns(self): with self.mocked_stdout_stderr(): mod_dep_txt = eb.make_module_dep() for mod in ['GCC/6.4.0-2.28', 'OpenMPI/2.1.2']: - regex = re.compile('load.*%s' % mod) + regex = re.compile('(load|depends[-_]on).*%s' % mod) self.assertFalse(regex.search(mod_dep_txt), "Pattern '%s' found in: %s" % (regex.pattern, mod_dep_txt)) - regex = re.compile('load.*FFTW/3.3.7') + regex = re.compile('(load|depends[-_]on).*FFTW/3.3.7') self.assertTrue(regex.search(mod_dep_txt), "Pattern '%s' found in: %s" % (regex.pattern, mod_dep_txt)) def test_make_module_dep_of_dep_hmns(self): @@ -1344,27 +1345,27 @@ def test_make_module_step(self): for (name, ver) in [('GCC', '6.4.0-2.28')]: if get_module_syntax() == 'Tcl': - regex = re.compile(r'^\s*module load %s\s*$' % os.path.join(name, ver), re.M) + regex = re.compile(r'^\s*(module load|depends-on) %s\s*$' % os.path.join(name, ver), re.M) elif get_module_syntax() == 'Lua': - regex = re.compile(r'^\s*load\("%s"\)$' % os.path.join(name, ver), re.M) + regex = re.compile(r'^\s*(load|depends_on)\("%s"\)$' % os.path.join(name, ver), re.M) else: self.fail("Unknown module syntax: %s" % get_module_syntax()) self.assertTrue(regex.search(txt), "Pattern %s found in %s" % (regex.pattern, txt)) for (name, ver) in [('test', '1.2.3')]: if get_module_syntax() == 'Tcl': - regex = re.compile(r'^\s*module load %s/.%s\s*$' % (name, ver), re.M) + regex = re.compile(r'^\s*(module load|depends-on) %s/.%s\s*$' % (name, ver), re.M) elif get_module_syntax() == 'Lua': - regex = re.compile(r'^\s*load\("%s/.%s"\)$' % (name, ver), re.M) + regex = re.compile(r'^\s*(load|depends_on)\("%s/.%s"\)$' % (name, ver), re.M) else: self.fail("Unknown module syntax: %s" % get_module_syntax()) self.assertTrue(regex.search(txt), "Pattern %s found in %s" % (regex.pattern, txt)) for (name, ver) in [('OpenMPI', '2.1.2-GCC-6.4.0-2.28')]: if get_module_syntax() == 'Tcl': - regex = re.compile(r'^\s*module load %s/.?%s\s*$' % (name, ver), re.M) + regex = re.compile(r'^\s*(module load|depends-on) %s/.?%s\s*$' % (name, ver), re.M) elif get_module_syntax() == 'Lua': - regex = re.compile(r'^\s*load\("%s/.?%s"\)$' % (name, ver), re.M) + regex = re.compile(r'^\s*(load|depends_on)\("%s/.?%s"\)$' % (name, ver), re.M) else: self.fail("Unknown module syntax: %s" % get_module_syntax()) self.assertFalse(regex.search(txt), "Pattern '%s' *not* found in %s" % (regex.pattern, txt)) diff --git a/test/framework/easyconfig.py b/test/framework/easyconfig.py index 4a1e1df608..33dae310ba 100644 --- a/test/framework/easyconfig.py +++ b/test/framework/easyconfig.py @@ -4596,6 +4596,8 @@ def test_recursive_module_unload(self): toy_ec = os.path.join(test_ecs_dir, 'f', 'foss', 'foss-2018a.eb') test_ec = os.path.join(self.test_prefix, 'test.eb') test_ec_txt = read_file(toy_ec) + # this test only makes sense if depends_on is not used + test_ec_txt += '\nmodule_depends_on = False' write_file(test_ec, test_ec_txt) test_module = os.path.join(self.test_installpath, 'modules', 'all', 'foss', '2018a') @@ -4635,6 +4637,8 @@ def test_recursive_module_unload(self): # recursive_module_unload easyconfig parameter is honored test_ec_bis = os.path.join(self.test_prefix, 'test_bis.eb') test_ec_bis_txt = read_file(toy_ec) + '\nrecursive_module_unload = True' + # this test only makes sense if depends_on is not used + test_ec_bis_txt += '\nmodule_depends_on = False' write_file(test_ec_bis, test_ec_bis_txt) ec_bis = EasyConfig(test_ec_bis) @@ -4667,6 +4671,8 @@ def test_recursive_module_unload(self): self.assertTrue(build_option('recursive_mod_unload')) test_ec_bis = os.path.join(self.test_prefix, 'test_bis.eb') test_ec_bis_txt = read_file(toy_ec) + '\nrecursive_module_unload = False' + # this test only makes sense if depends_on is not used + test_ec_bis_txt += '\nmodule_depends_on = False' write_file(test_ec_bis, test_ec_bis_txt) ec_bis = EasyConfig(test_ec_bis) self.assertEqual(ec_bis['recursive_module_unload'], False) diff --git a/test/framework/toy_build.py b/test/framework/toy_build.py index 61a9cca2e5..3b5d7b6ecb 100644 --- a/test/framework/toy_build.py +++ b/test/framework/toy_build.py @@ -861,9 +861,9 @@ def test_toy_hierarchical(self): # check that toolchain load is expanded to loads for toolchain dependencies, # except for the ones that extend $MODULEPATH to make the toy module available if get_module_syntax() == 'Tcl': - load_regex_template = "load %s" + load_regex_template = "(load|depends-on) %s" elif get_module_syntax() == 'Lua': - load_regex_template = r'load\("%s/.*"\)' + load_regex_template = r'(load|depends_on)\("%s/.*"\)' else: self.fail("Unknown module syntax: %s" % get_module_syntax()) @@ -892,7 +892,7 @@ def test_toy_hierarchical(self): # no dependencies or toolchain => no module load statements in module file modtxt = read_file(toy_module_path) - self.assertFalse(re.search("module load", modtxt)) + self.assertFalse(re.search("(module load|depends-on)", modtxt)) os.remove(toy_module_path) # test module path with GCC/6.4.0-2.28 build, pretend to be an MPI lib by setting moduleclass extra_args = [ @@ -952,7 +952,7 @@ def test_toy_hierarchical(self): # no dependencies or toolchain => no module load statements in module file modtxt = read_file(toy_module_path) - self.assertFalse(re.search("module load", modtxt)) + self.assertFalse(re.search("(module load|depends-on)", modtxt)) os.remove(toy_module_path) # test module path with system/system build, pretend to be a compiler by setting moduleclass @@ -1727,8 +1727,10 @@ def test_module_only(self): # make sure load statements for dependencies are included in additional module file generated with --module-only modtxt = read_file(toy_mod) - self.assertTrue(re.search('load.*intel/2018a', modtxt), "load statement for intel/2018a found in module") - self.assertTrue(re.search('load.*GCC/6.4.0-2.28', modtxt), "load statement for GCC/6.4.0-2.28 found in module") + self.assertTrue(re.search('(load|depends[-_]on).*intel/2018a', modtxt), + "load statement for intel/2018a found in module: %s" % modtxt) + self.assertTrue(re.search('(load|depends[-_]on).*GCC/6.4.0-2.28', modtxt), + "load statement for GCC/6.4.0-2.28 found in module: %s" % modtxt) os.remove(toy_mod) @@ -1770,7 +1772,8 @@ def test_module_only(self): # make sure load statements for dependencies are included modtxt = read_file(toy_core_mod) - self.assertTrue(re.search('load.*intel/2018a', modtxt), "load statement for intel/2018a found in module") + self.assertTrue(re.search('(load|depends[-_]on).*intel/2018a', modtxt), + "load statement for intel/2018a found in module: %s" % modtxt) # Test we can create a module even for an installation where we don't have write permissions os.remove(toy_core_mod) @@ -1788,7 +1791,8 @@ def test_module_only(self): # make sure load statements for dependencies are included modtxt = read_file(toy_core_mod) - self.assertTrue(re.search('load.*intel/2018a', modtxt), "load statement for intel/2018a found in module") + self.assertTrue(re.search('(load|depends[-_]).*intel/2018a', modtxt), + "load statement for intel/2018a found in module: %s" % modtxt) os.remove(toy_core_mod) os.remove(toy_mod) @@ -1814,7 +1818,8 @@ def test_module_only(self): # make sure load statements for dependencies are included modtxt = read_file(toy_mod + '.lua') - self.assertTrue(re.search('load.*intel/2018a', modtxt), "load statement for intel/2018a found in module") + self.assertTrue(re.search('(load|depends[-_]).*intel/2018a', modtxt), + "load statement for intel/2018a found in module: %s" % modtxt) def test_module_only_extensions(self): """ @@ -2350,7 +2355,8 @@ def test_toy_toy(self): mod2_txt = read_file(mod2) - load1_regex = re.compile('load.*toy/0.0-one', re.M) + # load statement is (by default) either depends_on (Lua) or depends-on (Tcl) + load1_regex = re.compile('(load|depends[-_]on).*toy/0.0-one', re.M) self.assertTrue(load1_regex.search(mod2_txt), "Pattern '%s' found in: %s" % (load1_regex.pattern, mod2_txt)) # Check the contents of the dumped env in the reprod dir to ensure it contains the dependency load @@ -3183,14 +3189,18 @@ def test_toy_multi_deps(self): # check whether (guarded) load statement for first version listed in multi_deps is there if get_module_syntax() == 'Lua': expected = '\n'.join([ - 'if not ( isloaded("GCC/4.6.3") ) and not ( isloaded("GCC/7.3.0-2.30") ) then', - ' load("GCC/4.6.3")', + 'if mode() == "unload" or isloaded("GCC/7.3.0-2.30") then', + ' depends_on("GCC")', + 'else', + ' depends_on("GCC/4.6.3")', 'end', ]) else: expected = '\n'.join([ - 'if { ![ is-loaded GCC/4.6.3 ] && ![ is-loaded GCC/7.3.0-2.30 ] } {', - ' module load GCC/4.6.3', + 'if { [ module-info mode remove ] || [ is-loaded GCC/7.3.0-2.30 ] } {', + ' depends-on GCC', + '} else {', + ' depends-on GCC/4.6.3', '}', ])