Skip to content

Commit

Permalink
Fix some tests using new module_depends_on being true by default
Browse files Browse the repository at this point in the history
fix tests that got broken by enabling use of depends_on (instead of load) statement in generated environment modules by default
  • Loading branch information
Micket committed Sep 18, 2024
1 parent 9361e6e commit c9c5395
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
17 changes: 9 additions & 8 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,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 @@ -873,10 +874,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 @@ -1361,27 +1362,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 @@ -4785,6 +4785,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 @@ -4827,6 +4829,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 @@ -4871,6 +4875,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
34 changes: 21 additions & 13 deletions test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,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 @@ -1739,8 +1739,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")
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")

os.remove(toy_mod)

Expand Down Expand Up @@ -1782,7 +1784,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")

# Test we can create a module even for an installation where we don't have write permissions
os.remove(toy_core_mod)
Expand All @@ -1800,7 +1803,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")

os.remove(toy_core_mod)
os.remove(toy_mod)
Expand All @@ -1826,7 +1830,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[-_]on).*intel/2018a', modtxt),
"load statement for intel/2018a found in module")

def test_module_only_extensions(self):
"""
Expand Down Expand Up @@ -2371,7 +2376,7 @@ def test_toy_toy(self):

mod2_txt = read_file(mod2)

load1_regex = re.compile('load.*toy/0.0-one', re.M)
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 @@ -3176,6 +3181,7 @@ def test_toy_multi_deps(self):
test_ec_txt += "\nexts_list = [('barbar', '1.2', {'start_dir': 'src'})]"

test_ec_txt += "\nmulti_deps = {'GCC': ['4.6.3', '7.3.0-2.30']}"

write_file(test_ec, test_ec_txt)

test_mod_path = os.path.join(self.test_installpath, 'modules', 'all')
Expand Down Expand Up @@ -3204,24 +3210,26 @@ 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:
if not self.modtool.supports_safe_auto_load:
expected = '\n'.join([
'if { ![ is-loaded GCC/4.6.3 ] && ![ is-loaded GCC/7.3.0-2.30 ] } {',
' module load GCC/4.6.3',
' depends-on GCC/4.6.3',
'}',
])
else:
expected = '\n'.join([
'',
"if { [ module-info mode remove ] || [ is-loaded GCC/7.3.0-2.30 ] } {",
" module load GCC",
" depends-on GCC",
'} else {',
" module load GCC/4.6.3",
" depends-on GCC/4.6.3",
'}',
'',
])
Expand Down

0 comments on commit c9c5395

Please sign in to comment.