Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions reframe/core/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,17 @@ def _fn(*args, **kwargs):
return _fn

return _runtime_deco


class module_use:
'''Context manager for temporarily modifying the module path'''

def __init__(self, *paths):
self._paths = paths

def __enter__(self):
runtime().modules_system.searchpath_add(*self._paths)
return self

def __exit__(self, exc_type, exc_value, traceback):
runtime().modules_system.searchpath_remove(*self._paths)
13 changes: 7 additions & 6 deletions unittests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,14 @@ def test_unload_module(self):
if ms.name == 'nomod':
pytest.skip('no modules system found')

ms.searchpath_add('unittests/modules')
ms.load_module('testmod_foo')
self.more_options = ['-u testmod_foo']
self.action = 'list'
returncode, stdout, stderr = self._run_reframe()
with rt.module_use('unittests/modules'):
ms.load_module('testmod_foo')
self.more_options = ['-u testmod_foo']
self.action = 'list'
returncode, stdout, stderr = self._run_reframe()
ms.unload_module('testmod_foo')

assert stdout != ''
assert 'Traceback' not in stdout
assert 'Traceback' not in stderr
assert returncode == 0
ms.unload_module('testmod_foo')
24 changes: 14 additions & 10 deletions unittests/test_schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def setUp(self):
def tearDown(self):
os_ext.rmtree(self.workdir)

def prepare(self):
with rt.module_use('unittests/modules'):
self.testjob.prepare(self.commands, self.environs)

@property
def commands(self):
runcmd = self.launcher.run_command(self.testjob)
Expand Down Expand Up @@ -99,13 +103,13 @@ def setup_job(self):
self.testjob._sched_exclusive_access = True

def test_prepare(self):
self.testjob.prepare(self.commands, self.environs)
self.prepare()
self.assertScriptSanity(self.testjob.script_filename)

@fixtures.switch_to_user_runtime
def test_submit(self):
self.setup_user()
self.testjob.prepare(self.commands, self.environs)
self.prepare()
self.assertIsNone(self.testjob.nodelist)
self.testjob.submit()
self.assertIsNotNone(self.testjob.jobid)
Expand All @@ -116,7 +120,7 @@ def test_submit_timelimit(self, check_elapsed_time=True):
self.setup_user()
self.parallel_cmd = 'sleep 10'
self.testjob.time_limit = (0, 0, 2)
self.testjob.prepare(self.commands, self.environs)
self.prepare()
t_job = datetime.now()
self.testjob.submit()
self.assertIsNotNone(self.testjob.jobid)
Expand All @@ -133,7 +137,7 @@ def test_submit_timelimit(self, check_elapsed_time=True):
def test_cancel(self):
self.setup_user()
self.parallel_cmd = 'sleep 30'
self.testjob.prepare(self.commands, self.environs)
self.prepare()
t_job = datetime.now()
self.testjob.submit()
self.testjob.cancel()
Expand All @@ -144,26 +148,26 @@ def test_cancel(self):

def test_cancel_before_submit(self):
self.parallel_cmd = 'sleep 3'
self.testjob.prepare(self.commands, self.environs)
self.prepare()
self.assertRaises(JobNotStartedError, self.testjob.cancel)

def test_wait_before_submit(self):
self.parallel_cmd = 'sleep 3'
self.testjob.prepare(self.commands, self.environs)
self.prepare()
self.assertRaises(JobNotStartedError, self.testjob.wait)

@fixtures.switch_to_user_runtime
def test_poll(self):
self.setup_user()
self.parallel_cmd = 'sleep 2'
self.testjob.prepare(self.commands, self.environs)
self.prepare()
self.testjob.submit()
self.assertFalse(self.testjob.finished())
self.testjob.wait()

def test_poll_before_submit(self):
self.parallel_cmd = 'sleep 3'
self.testjob.prepare(self.commands, self.environs)
self.prepare()
self.assertRaises(JobNotStartedError, self.testjob.finished)

def test_no_empty_lines_in_preamble(self):
Expand Down Expand Up @@ -227,7 +231,7 @@ def test_cancel_with_grace(self):
self.testjob.time_limit = (0, 1, 0)
self.testjob.cancel_grace_period = 2

self.testjob.prepare(self.commands, self.environs)
self.prepare()
self.testjob.submit()

# Stall a bit here to let the the spawned process start and install its
Expand Down Expand Up @@ -267,7 +271,7 @@ def test_cancel_term_ignore(self):
self.parallel_cmd = os.path.join(fixtures.TEST_RESOURCES_CHECKS,
'src', 'sleep_deeply.sh')
self.testjob.cancel_grace_period = 2
self.testjob.prepare(self.commands, self.environs)
self.prepare()
self.testjob.submit()

# Stall a bit here to let the the spawned process start and install its
Expand Down