Skip to content

Commit

Permalink
Merge pull request #3308 from easybuilders/t
Browse files Browse the repository at this point in the history
use `run_shell_cmd` in testsuite
  • Loading branch information
boegel authored Apr 17, 2024
2 parents 37eb9d9 + d146f89 commit 57cfdce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 9 additions & 6 deletions test/easyblocks/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from easybuild.base.testing import TestCase
from easybuild.easyblocks import VERSION
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.run import run_cmd
from easybuild.tools.run import run_shell_cmd


EASYBLOCK_BODY = """
Expand All @@ -62,11 +62,14 @@ def det_path_for_import(module, pythonpath=None):

cmd = cmd_tmpl % {'mod': module}

out, _ = run_cmd(cmd, simple=False)
res = run_shell_cmd(cmd, hidden=True, fail_on_error=False)

if res.exit_code:
raise EasyBuildError(res.output)

# only return last line that should contain path to imported module
# warning messages may precede it
return out.strip().split('\n')[-1]
return res.output.strip().split('\n')[-1]


def up(path, level):
Expand Down Expand Up @@ -134,7 +137,7 @@ def write_module(path, txt):
self.assertTrue(os.path.samefile(easyblocks_path, parent_path), msg)

# importing EB_R class from easybuild.easyblocks.r works fine
run_cmd("python -c 'from easybuild.easyblocks.r import EB_R'")
run_shell_cmd("python -c 'from easybuild.easyblocks.r import EB_R'", hidden=True)

# importing a non-existing module fails
err_msg = "No module named .*"
Expand Down Expand Up @@ -163,7 +166,7 @@ def write_module(path, txt):
self.assertTrue(os.path.samefile(repo_path, parent_path), msg)

# importing EB_R class from easybuild.easyblocks.r still works fine
run_cmd("python -c 'from easybuild.easyblocks.r import EB_R'")
run_shell_cmd("python -c 'from easybuild.easyblocks.r import EB_R'", hidden=True)

# custom easyblocks override existing easyblocks (with custom easyblocks repo first in $PYTHONPATH)
for software in ['GCC', 'R']:
Expand All @@ -175,7 +178,7 @@ def write_module(path, txt):
self.assertTrue(os.path.samefile(custom_easyblocks_repo_path, parent_path), msg)

# importing EB_R class from easybuild.easyblocks.r still works fine
run_cmd("python -c 'from easybuild.easyblocks.r import EB_R'")
run_shell_cmd("python -c 'from easybuild.easyblocks.r import EB_R'", hidden=True)


def suite():
Expand Down
10 changes: 6 additions & 4 deletions test/easyblocks/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def test_make_module_pythonpackage(self):
print(which('python'))

# create module file
app.make_module_step()
with self.mocked_stdout_stderr():
app.make_module_step()

remove_file(python)

Expand Down Expand Up @@ -227,8 +228,8 @@ def test_pythonpackage_pick_python_cmd(self):
"""Test pick_python_cmd function from pythonpackage.py."""
from easybuild.easyblocks.generic.pythonpackage import pick_python_cmd
self.assertTrue(pick_python_cmd() is not None)
self.assertTrue(pick_python_cmd(2) is not None)
self.assertTrue(pick_python_cmd(2, 6) is not None)
self.assertTrue(pick_python_cmd(3) is not None)
self.assertTrue(pick_python_cmd(3, 6) is not None)
self.assertTrue(pick_python_cmd(123, 456) is None)


Expand Down Expand Up @@ -356,7 +357,8 @@ def template_module_only_test(self, easyblock, name, version='1.3.2', extra_txt=
# run all steps, most should be skipped
orig_workdir = os.getcwd()
try:
app.run_all_steps(run_test_cases=False)
with self.mocked_stdout_stderr():
app.run_all_steps(run_test_cases=False)
finally:
change_dir(orig_workdir)

Expand Down

0 comments on commit 57cfdce

Please sign in to comment.