Skip to content

Commit ebd2ea0

Browse files
author
Vasileios Karakasis
committed
Raise ValueError for invalid pipeline stages
1 parent 985d774 commit ebd2ea0

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

reframe/core/decorators.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ def _fn(*args, **kwargs):
214214
return deco
215215

216216

217+
# Valid pipeline stages that users can specify in the `run_before()` and
218+
# `run_after()` decorators
219+
_USER_PIPELINE_STAGES = (
220+
'init', 'setup', 'compile', 'run', 'sanity', 'performance', 'cleanup'
221+
)
222+
223+
217224
def run_before(stage):
218225
'''Decorator for attaching a test method to a pipeline stage.
219226
@@ -227,6 +234,9 @@ def run_before(stage):
227234
``'run'``, ``'sanity'``, ``'performance'`` or ``'cleanup'``.
228235
229236
'''
237+
if stage not in _USER_PIPELINE_STAGES:
238+
raise ValueError(f'invalid pipeline stage specified: {stage!r}')
239+
230240
if stage == 'init':
231241
raise ValueError('pre-init hooks are not allowed')
232242

@@ -263,6 +273,9 @@ def __init__(self):
263273
264274
'''
265275

276+
if stage not in _USER_PIPELINE_STAGES:
277+
raise ValueError(f'invalid pipeline stage specified: {stage!r}')
278+
266279
# Map user stage names to the actual pipeline functions if needed
267280
if stage == 'init':
268281
stage = '__init__'

unittests/test_pipeline.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,24 @@ def set_resources(self):
526526
assert expected_job_options == set(test.job.options)
527527

528528

529-
def test_pre_init_hook(local_exec_ctx):
529+
def test_unkown_pre_hook():
530+
with pytest.raises(ValueError):
531+
class MyTest(rfm.RunOnlyRegressionTest):
532+
@rfm.run_before('foo')
533+
def prepare(self):
534+
self.x = 1
535+
536+
537+
def test_unkown_post_hook():
538+
with pytest.raises(ValueError):
539+
class MyTest(rfm.RunOnlyRegressionTest):
540+
@rfm.run_after('foo')
541+
def prepare(self):
542+
self.x = 1
543+
544+
545+
def test_pre_init_hook():
530546
with pytest.raises(ValueError):
531-
@fixtures.custom_prefix('unittests/resources/checks')
532547
class MyTest(rfm.RunOnlyRegressionTest):
533548
@rfm.run_before('init')
534549
def prepare(self):

0 commit comments

Comments
 (0)