Skip to content

Commit 321bad5

Browse files
author
Theofilos Manitaras
committed
Address PR comments (version 4)
1 parent 26da566 commit 321bad5

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

docs/manpage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ It does so by leveraging the selected system's environment modules system.
390390
.. option:: --module-path=PATH
391391

392392
Manipulate the ``MODULEPATH`` environment variable before acting on any tests.
393-
If ``PATH`` starts with the `-` character it will be removed from the ``MODULEPATH``, whereas if it starts with the `+` character, it will be added to it.
393+
If ``PATH`` starts with the `-` character, it will be removed from the ``MODULEPATH``, whereas if it starts with the `+` character, it will be added to it.
394394
In all other cases, ``PATH`` will completely override MODULEPATH.
395395
This option may be specified multiple times, in which case all the paths specified will be added or removed in order.
396396

reframe/core/modules.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def execute(self, cmd, *args):
215215
'''
216216
return self._backend.execute(cmd, *args)
217217

218+
218219
def load_module(self, name, force=False, collection=False):
219220
'''Load the module ``name``.
220221
@@ -391,10 +392,26 @@ class ModulesSystemImpl(abc.ABC):
391392
:meta private:
392393
'''
393394

394-
@abc.abstractmethod
395395
def execute(self, cmd, *args):
396+
'''Execute an arbitrary module command using the modules backend.
397+
398+
:arg cmd: The command to execute, e.g., ``load``, ``restore`` etc.
399+
:arg args: The arguments to pass to the command.
400+
:returns: The command output.
401+
'''
402+
try:
403+
exec_output = self._execute(cmd, *args)
404+
except SpawnedProcessError as e:
405+
raise EnvironError from e
406+
407+
return exec_output
408+
409+
410+
@abc.abstractmethod
411+
def _execute(self, cmd, *args):
396412
'''Execute an arbitrary command of the module system.'''
397413

414+
398415
@abc.abstractmethod
399416
def available_modules(self, substr):
400417
'''Return a list of available modules, whose name contains ``substr``.
@@ -530,7 +547,7 @@ def version(self):
530547
def modulecmd(self, *args):
531548
return ' '.join(['modulecmd', 'python', *args])
532549

533-
def execute(self, cmd, *args):
550+
def _execute(self, cmd, *args):
534551
modulecmd = self.modulecmd(cmd, *args)
535552
completed = osext.run_command(modulecmd)
536553
if re.search(r'ERROR', completed.stderr) is not None:
@@ -652,7 +669,7 @@ def name(self):
652669
def modulecmd(self, *args):
653670
return ' '.join([self._command, *args])
654671

655-
def execute(self, cmd, *args):
672+
def _execute(self, cmd, *args):
656673
modulecmd = self.modulecmd(cmd, *args)
657674
completed = osext.run_command(modulecmd)
658675
if re.search(r'ERROR', completed.stderr) is not None:
@@ -713,7 +730,7 @@ def name(self):
713730
def modulecmd(self, *args):
714731
return ' '.join(['modulecmd', 'python', *args])
715732

716-
def execute(self, cmd, *args):
733+
def _execute(self, cmd, *args):
717734
modulecmd = self.modulecmd(cmd, *args)
718735
completed = osext.run_command(modulecmd, check=False)
719736
namespace = {}
@@ -874,7 +891,7 @@ def loaded_modules(self):
874891
def conflicted_modules(self, module):
875892
return []
876893

877-
def execute(self, cmd, *args):
894+
def _execute(self, cmd, *args):
878895
return ''
879896

880897
def load_module(self, module):

reframe/frontend/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ def print_infoline(param, value):
770770
printer.debug('Loading user modules from command line')
771771
for m in site_config.get('general/0/user_modules'):
772772
try:
773+
import pdb; pdb.set_trace()
773774
rt.modules_system.load_module(**m, force=True)
774775
except errors.EnvironError as e:
775776
printer.warning(

unittests/test_cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,15 +599,13 @@ def test_unuse_module_path(run_reframe, user_exec_ctx, monkeypatch):
599599
module_path = 'unittests/modules'
600600
monkeypatch.setenv('MODULEPATH', module_path)
601601
returncode, stdout, stderr = run_reframe(
602-
more_options=[f'--module-path=-{module_path}', '-m testmod_foo'],
602+
more_options=[f'--module-path=-{module_path}', '--module=testmod_foo'],
603603
config_file=fixtures.USER_CONFIG_FILE, action='run',
604604
system=rt.runtime().system.name
605605
)
606-
607-
# Here we test that ReFrame fails to run because 'testmod_foo' cannot
608-
# be found and therefore the module name is included in the given error
609-
assert 'testmod_foo' in stdout
610-
assert returncode == 1
606+
assert "could not load module 'testmod_foo' correctly" in stdout
607+
assert 'Traceback' not in stderr
608+
assert returncode == 0
611609

612610

613611
def test_use_module_path(run_reframe, user_exec_ctx):
@@ -617,13 +615,14 @@ def test_use_module_path(run_reframe, user_exec_ctx):
617615

618616
module_path = 'unittests/modules'
619617
returncode, stdout, stderr = run_reframe(
620-
more_options=[f'--module-path=+{module_path}', '-m testmod_foo'],
618+
more_options=[f'--module-path=+{module_path}', '--module=testmod_foo'],
621619
config_file=fixtures.USER_CONFIG_FILE, action='run',
622620
system=rt.runtime().system.name
623621
)
624622

625623
assert 'Traceback' not in stdout
626624
assert 'Traceback' not in stderr
625+
assert "could not load module 'testmod_foo' correctly" not in stdout
627626
assert returncode == 0
628627

629628

@@ -634,13 +633,14 @@ def test_overwrite_module_path(run_reframe, user_exec_ctx):
634633

635634
module_path = 'unittests/modules'
636635
returncode, stdout, stderr = run_reframe(
637-
more_options=[f'--module-path={module_path}', '-m testmod_foo'],
636+
more_options=[f'--module-path={module_path}', '--module=testmod_foo'],
638637
config_file=fixtures.USER_CONFIG_FILE, action='run',
639638
system=rt.runtime().system.name
640639
)
641640

642641
assert 'Traceback' not in stdout
643642
assert 'Traceback' not in stderr
643+
assert "could not load module 'testmod_foo' correctly" not in stdout
644644
assert returncode == 0
645645

646646

unittests/test_environments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def test_emit_loadenv_failure(user_runtime):
258258

259259
# Suppress the module load error and verify that the original environment
260260
# is preserved
261-
with contextlib.suppress(SpawnedProcessError):
261+
with contextlib.suppress(EnvironError):
262262
rt.emit_loadenv_commands(environ)
263263

264264
assert rt.snapshot() == snap

unittests/test_modules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_module_load(modules_system):
8080
modules_system.load_module('foo')
8181
modules_system.unload_module('foo')
8282
else:
83-
with pytest.raises(SpawnedProcessError):
83+
with pytest.raises(EnvironError):
8484
modules_system.load_module('foo')
8585

8686
assert not modules_system.is_module_loaded('foo')
@@ -307,7 +307,7 @@ def loaded_modules(self):
307307
def conflicted_modules(self, module):
308308
return []
309309

310-
def execute(self, cmd, *args):
310+
def _execute(self, cmd, *args):
311311
return ''
312312

313313
def load_module(self, module):

0 commit comments

Comments
 (0)