Skip to content

Commit

Permalink
fix tests that got broken by enabling use of depends_on (instead of l…
Browse files Browse the repository at this point in the history
…oad) statement in generated environment modules by default
  • Loading branch information
boegel committed Jun 5, 2024
1 parent f27a7fc commit 794c068
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
17 changes: 9 additions & 8 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 24 additions & 14 deletions test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
'}',
])

Expand Down

0 comments on commit 794c068

Please sign in to comment.