From 8fd32d42fd93560e54e962f611a28f334de700d7 Mon Sep 17 00:00:00 2001 From: Theofilos Manitaras Date: Wed, 15 Feb 2023 17:41:10 +0100 Subject: [PATCH 1/2] Raise warning for invalid mode cli option Signed-off-by: Theofilos Manitaras --- reframe/frontend/cli.py | 26 ++++++++++++++++---------- unittests/test_cli.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index 9a465ea2af..f44b68b1f6 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -737,16 +737,22 @@ def restrict_logging(): # Update options from the selected execution mode if options.mode: - mode_args = site_config.get(f'modes/@{options.mode}/options') - - # We lexically split the mode options, because otherwise spaces - # will be treated as part of the option argument; see GH bug #1554 - mode_args = list(itertools.chain.from_iterable(shlex.split(m) - for m in mode_args)) - # Parse the mode's options and reparse the command-line - options = argparser.parse_args(mode_args) - options = argparser.parse_args(namespace=options.cmd_options) - options.update_config(site_config) + mode = site_config.get(f'modes/@{options.mode}') + if mode is None: + printer.warning(f'invalid mode: {options.mode!r}; ignoring') + else: + mode_args = site_config.get(f'modes/@{options.mode}/options') + + # We lexically split the mode options, because otherwise spaces + # will be treated as part of the option argument; + # see GH bug #1554 + mode_args = list( + itertools.chain.from_iterable(shlex.split(m) + for m in mode_args)) + # Parse the mode's options and reparse the command-line + options = argparser.parse_args(mode_args) + options = argparser.parse_args(namespace=options.cmd_options) + options.update_config(site_config) logging.configure_logging(site_config) except (OSError, errors.ConfigError) as e: diff --git a/unittests/test_cli.py b/unittests/test_cli.py index 4cf8609204..2ea7e561bb 100644 --- a/unittests/test_cli.py +++ b/unittests/test_cli.py @@ -478,6 +478,20 @@ def test_execution_modes(run_reframe): assert 'Ran 2/2 test case' in stdout +def test_invalid_mode_warning(run_reframe): + mode = 'invalid' + returncode, stdout, stderr = run_reframe( + action='list', + checkpath=[], + environs=[], + local=False, + mode=mode + ) + assert 'Traceback' not in stdout + assert 'Traceback' not in stderr + assert f'invalid mode: {mode!r}; ignoring' in stdout + + def test_timestamp_option(run_reframe): timefmt = time.strftime('xxx_%F') returncode, stdout, _ = run_reframe( From e48f904c48c62883058befe6a0c9f4ae71a55ed7 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Wed, 15 Feb 2023 20:54:39 +0100 Subject: [PATCH 2/2] Minor style changes --- reframe/frontend/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index f44b68b1f6..5443675505 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -739,7 +739,7 @@ def restrict_logging(): if options.mode: mode = site_config.get(f'modes/@{options.mode}') if mode is None: - printer.warning(f'invalid mode: {options.mode!r}; ignoring') + printer.warning(f'invalid mode: {options.mode!r}; ignoring...') else: mode_args = site_config.get(f'modes/@{options.mode}/options')