From 024e517bddfc1cfacf0c10a3c4a2197f562871ee Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Mon, 20 Sep 2021 23:36:09 +0200 Subject: [PATCH 1/2] Add unit tests to reproduce GH #2169 --- unittests/test_argparser.py | 9 ++++++++- unittests/test_cli.py | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/unittests/test_argparser.py b/unittests/test_argparser.py index c2bb546f35..6024a3bb3c 100644 --- a/unittests/test_argparser.py +++ b/unittests/test_argparser.py @@ -104,7 +104,7 @@ def extended_parser(): envvar='RFM_KEEP_STAGE_FILES', configvar='general/keep_stage_files' ) foo_options.add_argument( - '--timestamp', action='store', + '--timestamp', action='store', nargs='?', const='', envvar='RFM_TIMESTAMP_DIRS', configvar='general/timestamp_dirs' ) foo_options.add_argument( @@ -180,3 +180,10 @@ def test_option_envvar_conversion_error(default_exec_ctx, extended_parser): options = extended_parser.parse_args(['--nocolor']) errors = options.update_config(site_config) assert len(errors) == 1 + + +def test_option_nargs(default_exec_ctx, extended_parser): + site_config = rt.runtime().site_config + options = extended_parser.parse_args(['--timestamp']) + assert options.timestamp == '' + assert site_config.get('general/0/timestamp_dirs') == '%FT%T' diff --git a/unittests/test_cli.py b/unittests/test_cli.py index 48abab4af3..d57520afc3 100644 --- a/unittests/test_cli.py +++ b/unittests/test_cli.py @@ -11,6 +11,7 @@ import pytest import re import sys +import time import reframe.core.environments as env import reframe.frontend.runreport as runreport @@ -474,9 +475,7 @@ def test_execution_modes(run_reframe): def test_timestamp_option(run_reframe): - from datetime import datetime - - timefmt = datetime.now().strftime('xxx_%F') + timefmt = time.strftime('xxx_%F') returncode, stdout, _ = run_reframe( checkpath=['unittests/resources/checks'], action='list', @@ -486,6 +485,17 @@ def test_timestamp_option(run_reframe): assert timefmt in stdout +def test_timestamp_option_default(run_reframe): + timefmt_date_part = time.strftime('%FT') + returncode, stdout, _ = run_reframe( + checkpath=['unittests/resources/checks'], + action='list', + more_options=['-R', '--timestamp'] + ) + assert returncode == 0 + assert timefmt_date_part in stdout + + def test_list_empty_prgenvs_check_and_options(run_reframe): returncode, stdout, _ = run_reframe( checkpath=['unittests/resources/checks/frontend_checks.py'], From c535ff5542c73db010a6d4af429292890a22cc96 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Tue, 21 Sep 2021 23:49:15 +0200 Subject: [PATCH 2/2] Fix timestamp value when `--timestamp` is passed no arguments --- reframe/frontend/argparse.py | 3 +-- reframe/frontend/cli.py | 3 ++- unittests/test_argparser.py | 9 +-------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/reframe/frontend/argparse.py b/reframe/frontend/argparse.py index 3f1fb8f810..6b8087768a 100644 --- a/reframe/frontend/argparse.py +++ b/reframe/frontend/argparse.py @@ -184,8 +184,7 @@ def add_argument(self, *flags, **kwargs): kwargs['dest'] = opt_name # Convert 'store_true' and 'store_false' actions to their - # 'store_const' equivalents, because they otherwise imply imply a - # default + # 'store_const' equivalents, because they otherwise imply a default action = kwargs.get('action', None) if action == 'store_true' or action == 'store_false': kwargs['action'] = 'store_const' diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index 40d049b9b1..3072f1e7c4 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -217,7 +217,8 @@ def main(): envvar='RFM_SAVE_LOG_FILES', configvar='general/save_log_files' ) output_options.add_argument( - '--timestamp', action='store', nargs='?', const='', metavar='TIMEFMT', + '--timestamp', action='store', nargs='?', const='%FT%T', + metavar='TIMEFMT', help=('Append a timestamp to the output and stage directory prefixes ' '(default: "%%FT%%T")'), envvar='RFM_TIMESTAMP_DIRS', configvar='general/timestamp_dirs' diff --git a/unittests/test_argparser.py b/unittests/test_argparser.py index 6024a3bb3c..c2bb546f35 100644 --- a/unittests/test_argparser.py +++ b/unittests/test_argparser.py @@ -104,7 +104,7 @@ def extended_parser(): envvar='RFM_KEEP_STAGE_FILES', configvar='general/keep_stage_files' ) foo_options.add_argument( - '--timestamp', action='store', nargs='?', const='', + '--timestamp', action='store', envvar='RFM_TIMESTAMP_DIRS', configvar='general/timestamp_dirs' ) foo_options.add_argument( @@ -180,10 +180,3 @@ def test_option_envvar_conversion_error(default_exec_ctx, extended_parser): options = extended_parser.parse_args(['--nocolor']) errors = options.update_config(site_config) assert len(errors) == 1 - - -def test_option_nargs(default_exec_ctx, extended_parser): - site_config = rt.runtime().site_config - options = extended_parser.parse_args(['--timestamp']) - assert options.timestamp == '' - assert site_config.get('general/0/timestamp_dirs') == '%FT%T'