Skip to content

Commit 1222890

Browse files
authored
Merge pull request #7 from boegel/declare
enhance test for `cmd.sh` script produced by run_shell_cmd to verify that `module` function is available
2 parents 04e3b66 + 5cc7073 commit 1222890

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

.github/workflows/unit_tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ jobs:
152152
cd $HOME
153153
# initialize environment for modules tool
154154
if [ -f $HOME/moduleshome ]; then export MODULESHOME=$(cat $HOME/moduleshome); fi
155-
source $(cat $HOME/mod_init); type module
155+
source $(cat $HOME/mod_init)
156+
type module
157+
module --version
156158
# make sure 'eb' is available via $PATH, and that $PYTHONPATH is set (some tests expect that);
157159
# also pick up changes to $PATH set by sourcing $MOD_INIT
158160
export PREFIX=/tmp/$USER/$GITHUB_SHA

test/framework/run.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from easybuild.tools.build_log import EasyBuildError, init_logging, stop_logging
5353
from easybuild.tools.config import update_build_option
5454
from easybuild.tools.filetools import adjust_permissions, change_dir, mkdir, read_file, remove_dir, write_file
55+
from easybuild.tools.modules import EnvironmentModules, Lmod
5556
from easybuild.tools.run import RunShellCmdResult, RunShellCmdError, check_async_cmd, check_log_for_errors
5657
from easybuild.tools.run import complete_cmd, fileprefix_from_cmd, get_output_from_process, parse_log_for_error
5758
from easybuild.tools.run import run_cmd, run_cmd_qa, run_shell_cmd, subprocess_terminate
@@ -233,6 +234,20 @@ def test_run_shell_cmd_basic(self):
233234
pwd = res[0].strip()[5:]
234235
self.assertTrue(os.path.samefile(pwd, self.test_prefix))
235236

237+
cmd = f"{cmd_script} -c 'module --version'"
238+
with self.mocked_stdout_stderr():
239+
res = run_shell_cmd(cmd, fail_on_error=False)
240+
self.assertEqual(res.exit_code, 0)
241+
242+
if isinstance(self.modtool, Lmod):
243+
regex = re.compile("^Modules based on Lua: Version [0-9]", re.M)
244+
elif isinstance(self.modtool, EnvironmentModules):
245+
regex = re.compile("^Modules Release [0-9]", re.M)
246+
else:
247+
self.fail("Unknown modules tool used!")
248+
249+
self.assertTrue(regex.search(res.output), f"Pattern '{regex.pattern}' should be found in {res.output}")
250+
236251
# test running command that emits non-UTF-8 characters
237252
# this is constructed to reproduce errors like:
238253
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2

0 commit comments

Comments
 (0)