Skip to content

Commit f278859

Browse files
committed
Add unittests for argparser type conversion
1 parent cdc8102 commit f278859

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

unittests/test_argparser.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def extended_parser():
103103
dest='keep_stage_files', action='store_true',
104104
envvar='RFM_KEEP_STAGE_FILES', configvar='general/keep_stage_files'
105105
)
106+
parser.add_argument(
107+
'--git-timeout', envvar='RFM_GIT_TIMEOUT', action='store',
108+
configvar='general/git_timeout', type=float
109+
)
106110
foo_options.add_argument(
107111
'--timestamp', action='store',
108112
envvar='RFM_TIMESTAMP_DIRS', configvar='general/timestamp_dirs'
@@ -154,7 +158,8 @@ def test_option_with_config(default_exec_ctx, extended_parser, tmp_path):
154158
'RFM_TIMESTAMP': '%F',
155159
'RFM_NON_DEFAULT_CRAYPE': 'yes',
156160
'RFM_MODULES_PRELOAD': 'a,b,c',
157-
'RFM_KEEP_STAGE_FILES': 'no'
161+
'RFM_KEEP_STAGE_FILES': 'no',
162+
'RFM_GIT_TIMEOUT': '0.3'
158163
}):
159164
site_config = rt.runtime().site_config
160165
options = extended_parser.parse_args(
@@ -167,6 +172,7 @@ def test_option_with_config(default_exec_ctx, extended_parser, tmp_path):
167172
assert site_config.get('systems/0/prefix') == str(tmp_path)
168173
assert site_config.get('general/0/colorize') is False
169174
assert site_config.get('general/0/keep_stage_files') is False
175+
assert site_config.get('general/0/git_timeout') == 0.3
170176

171177
# Defaults specified in parser override those in configuration file
172178
assert site_config.get('systems/0/stagedir') == '/foo'
@@ -175,8 +181,9 @@ def test_option_with_config(default_exec_ctx, extended_parser, tmp_path):
175181
def test_option_envvar_conversion_error(default_exec_ctx, extended_parser):
176182
with rt.temp_environment(variables={
177183
'RFM_NON_DEFAULT_CRAYPE': 'foo',
184+
'RFM_GIT_TIMEOUT': 'non-float'
178185
}):
179186
site_config = rt.runtime().site_config
180187
options = extended_parser.parse_args(['--nocolor'])
181188
errors = options.update_config(site_config)
182-
assert len(errors) == 1
189+
assert len(errors) == 2

0 commit comments

Comments
 (0)