Skip to content

Commit

Permalink
enhance test for cmd.sh script produced by run_shell_cmd to verify th…
Browse files Browse the repository at this point in the history
…at 'module' function is available
  • Loading branch information
boegel committed Oct 1, 2024
1 parent 04e3b66 commit 9760624
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ jobs:
cd $HOME
# initialize environment for modules tool
if [ -f $HOME/moduleshome ]; then export MODULESHOME=$(cat $HOME/moduleshome); fi
source $(cat $HOME/mod_init); type module
source $(cat $HOME/mod_init)
type module
module --version
# make sure 'eb' is available via $PATH, and that $PYTHONPATH is set (some tests expect that);
# also pick up changes to $PATH set by sourcing $MOD_INIT
export PREFIX=/tmp/$USER/$GITHUB_SHA
Expand Down
15 changes: 15 additions & 0 deletions test/framework/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from easybuild.tools.build_log import EasyBuildError, init_logging, stop_logging
from easybuild.tools.config import update_build_option
from easybuild.tools.filetools import adjust_permissions, change_dir, mkdir, read_file, remove_dir, write_file
from easybuild.tools.modules import EnvironmentModules, Lmod
from easybuild.tools.run import RunShellCmdResult, RunShellCmdError, check_async_cmd, check_log_for_errors
from easybuild.tools.run import complete_cmd, fileprefix_from_cmd, get_output_from_process, parse_log_for_error
from easybuild.tools.run import run_cmd, run_cmd_qa, run_shell_cmd, subprocess_terminate
Expand Down Expand Up @@ -233,6 +234,20 @@ def test_run_shell_cmd_basic(self):
pwd = res[0].strip()[5:]
self.assertTrue(os.path.samefile(pwd, self.test_prefix))

cmd = f"{cmd_script} -c 'module --version'"
with self.mocked_stdout_stderr():
res = run_shell_cmd(cmd, fail_on_error=False)
self.assertEqual(res.exit_code, 0)

if isinstance(self.modtool, Lmod):
regex = re.compile("^Modules based on Lua", re.M)
elif isinstance(self.modtool, EnvironmentModules):
regex = re.compile("xxx", re.M)
else:
regex = re.compile("", re.M)

self.assertTrue(regex.search(res.output), f"Pattern '{regex.pattern}' should be found in {res.output}")

# test running command that emits non-UTF-8 characters
# this is constructed to reproduce errors like:
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2
Expand Down

0 comments on commit 9760624

Please sign in to comment.