Skip to content

Commit 52e95fd

Browse files
author
Vasileios Karakasis
committed
Add CLI unit tests
1 parent 8c45413 commit 52e95fd

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

reframe/core/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ class ContainerError(ReframeError):
154154
'''Raised when a container platform is not configured properly.'''
155155

156156

157+
class CommandLineError(ReframeError):
158+
'''Raised when an error in command-line arguments occurs.'''
159+
160+
157161
class BuildError(ReframeError):
158162
'''Raised when a build fails.'''
159163

reframe/frontend/cli.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,15 @@ def _case_failed(t):
10411041
)
10421042

10431043
if options.repeat is not None:
1044-
num_repeats = int(options.repeat)
1045-
if num_repeats <= 0:
1046-
raise ValueError('the number of repetitions '
1047-
'must be a positive integer')
1044+
try:
1045+
num_repeats = int(options.repeat)
1046+
if num_repeats <= 0:
1047+
raise ValueError
1048+
except ValueError:
1049+
raise errors.CommandLineError(
1050+
"argument to '--repeat' option must be "
1051+
"a non-negative integer"
1052+
) from None
10481053

10491054
testcases = repeat_tests(testcases, num_repeats)
10501055
testcases_all = testcases
@@ -1241,7 +1246,7 @@ def module_unuse(*paths):
12411246
errmsg = "invalid option for --flex-alloc-nodes: '{0}'"
12421247
sched_flex_alloc_nodes = int(options.flex_alloc_nodes)
12431248
if sched_flex_alloc_nodes <= 0:
1244-
raise errors.ConfigError(
1249+
raise errors.CommandLineError(
12451250
errmsg.format(options.flex_alloc_nodes)
12461251
)
12471252
except ValueError:
@@ -1250,7 +1255,7 @@ def module_unuse(*paths):
12501255
exec_policy.sched_flex_alloc_nodes = sched_flex_alloc_nodes
12511256
exec_policy.sched_options = parsed_job_options
12521257
if options.maxfail < 0:
1253-
raise errors.ConfigError(
1258+
raise errors.CommandLineError(
12541259
f'--maxfail should be a non-negative integer: '
12551260
f'{options.maxfail!r}'
12561261
)

unittests/test_cli.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,42 @@ def test_maxfail_negative(run_reframe):
808808
assert returncode == 1
809809

810810

811+
def test_repeat_option(run_reframe):
812+
returncode, stdout, stderr = run_reframe(
813+
more_options=['--repeat', '2', '-n', 'HelloTest'],
814+
checkpath=['unittests/resources/checks/hellocheck.py']
815+
)
816+
assert 'Traceback' not in stdout
817+
assert 'Traceback' not in stderr
818+
assert ('Ran 2/2 test case(s) from 2 check(s) '
819+
'(0 failure(s), 0 skipped)') in stdout
820+
assert returncode == 0
821+
822+
823+
def test_repeat_invalid_option(run_reframe):
824+
returncode, stdout, stderr = run_reframe(
825+
more_options=['--repeat', 'foo'],
826+
checkpath=['unittests/resources/checks/hellocheck.py']
827+
)
828+
errmsg = "argument to '--repeat' option must be a non-negative integer"
829+
assert 'Traceback' not in stdout
830+
assert 'Traceback' not in stderr
831+
assert errmsg in stdout
832+
assert returncode == 1
833+
834+
835+
def test_repeat_negative(run_reframe):
836+
returncode, stdout, stderr = run_reframe(
837+
more_options=['--repeat', 'foo'],
838+
checkpath=['unittests/resources/checks/hellocheck.py']
839+
)
840+
errmsg = "argument to '--repeat' option must be a non-negative integer"
841+
assert 'Traceback' not in stdout
842+
assert 'Traceback' not in stderr
843+
assert errmsg in stdout
844+
assert returncode == 1
845+
846+
811847
def test_detect_host_topology(run_reframe):
812848
from reframe.utility.cpuinfo import cpuinfo
813849

0 commit comments

Comments
 (0)