|
6 | 6 | import pytest |
7 | 7 |
|
8 | 8 | import reframe.core.runtime as rt |
9 | | -import unittests.fixtures as fixtures |
| 9 | +import unittests.utility as test_util |
10 | 10 | from reframe.frontend.argparse import ArgumentParser |
11 | 11 |
|
12 | 12 |
|
13 | 13 | @pytest.fixture |
14 | | -def argparser(): |
15 | | - with rt.temp_runtime(fixtures.TEST_CONFIG_FILE): |
16 | | - return ArgumentParser() |
| 14 | +def default_exec_ctx(make_exec_ctx_g): |
| 15 | + yield from make_exec_ctx_g(test_util.BUILTIN_CONFIG_FILE) |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture |
| 19 | +def argparser(make_exec_ctx): |
| 20 | + make_exec_ctx() |
| 21 | + return ArgumentParser() |
17 | 22 |
|
18 | 23 |
|
19 | 24 | @pytest.fixture |
@@ -122,59 +127,56 @@ def extended_parser(): |
122 | 127 | return parser |
123 | 128 |
|
124 | 129 |
|
125 | | -def test_option_precedence(extended_parser): |
126 | | - with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE): |
127 | | - with rt.temp_environment(variables={ |
128 | | - 'RFM_TIMESTAMP': '%F', |
129 | | - 'RFM_NON_DEFAULT_CRAYPE': 'yes', |
130 | | - 'RFM_MODULES_PRELOAD': 'a,b,c', |
131 | | - 'RFM_CHECK_SEARCH_PATH': 'x:y:z' |
132 | | - |
133 | | - }): |
134 | | - options = extended_parser.parse_args( |
135 | | - ['--timestamp=%FT%T', '--nocolor'] |
136 | | - ) |
137 | | - assert options.recursive is None |
138 | | - assert options.timestamp == '%FT%T' |
139 | | - assert options.non_default_craype is True |
140 | | - assert options.config_file is None |
141 | | - assert options.prefix is None |
142 | | - assert options.stagedir == '/foo' |
143 | | - assert options.module == ['a', 'b', 'c'] |
144 | | - assert options.check_path == ['x', 'y', 'z'] |
145 | | - assert options.colorize is False |
146 | | - |
147 | | - |
148 | | -def test_option_with_config(extended_parser): |
149 | | - with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE): |
150 | | - with rt.temp_environment(variables={ |
151 | | - 'RFM_TIMESTAMP': '%F', |
152 | | - 'RFM_NON_DEFAULT_CRAYPE': 'yes', |
153 | | - 'RFM_MODULES_PRELOAD': 'a,b,c', |
154 | | - 'RFM_KEEP_STAGE_FILES': 'no' |
155 | | - }): |
156 | | - site_config = rt.runtime().site_config |
157 | | - options = extended_parser.parse_args( |
158 | | - ['--timestamp=%FT%T', '--nocolor'] |
159 | | - ) |
160 | | - options.update_config(site_config) |
161 | | - assert site_config.get('general/0/check_search_recursive') is False |
162 | | - assert site_config.get('general/0/timestamp_dirs') == '%FT%T' |
163 | | - assert site_config.get('general/0/non_default_craype') is True |
164 | | - assert site_config.get('systems/0/prefix') == '.' |
165 | | - assert site_config.get('general/0/colorize') is False |
166 | | - assert site_config.get('general/0/keep_stage_files') is False |
167 | | - |
168 | | - # Defaults specified in parser override those in configuration file |
169 | | - assert site_config.get('systems/0/stagedir') == '/foo' |
170 | | - |
171 | | - |
172 | | -def test_option_envvar_conversion_error(extended_parser): |
173 | | - with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE): |
174 | | - with rt.temp_environment(variables={ |
175 | | - 'RFM_NON_DEFAULT_CRAYPE': 'foo', |
176 | | - }): |
177 | | - site_config = rt.runtime().site_config |
178 | | - options = extended_parser.parse_args(['--nocolor']) |
179 | | - errors = options.update_config(site_config) |
180 | | - assert len(errors) == 1 |
| 130 | +def test_option_precedence(default_exec_ctx, extended_parser): |
| 131 | + with rt.temp_environment(variables={ |
| 132 | + 'RFM_TIMESTAMP': '%F', |
| 133 | + 'RFM_NON_DEFAULT_CRAYPE': 'yes', |
| 134 | + 'RFM_MODULES_PRELOAD': 'a,b,c', |
| 135 | + 'RFM_CHECK_SEARCH_PATH': 'x:y:z' |
| 136 | + |
| 137 | + }): |
| 138 | + options = extended_parser.parse_args( |
| 139 | + ['--timestamp=%FT%T', '--nocolor'] |
| 140 | + ) |
| 141 | + assert options.recursive is None |
| 142 | + assert options.timestamp == '%FT%T' |
| 143 | + assert options.non_default_craype is True |
| 144 | + assert options.config_file is None |
| 145 | + assert options.prefix is None |
| 146 | + assert options.stagedir == '/foo' |
| 147 | + assert options.module == ['a', 'b', 'c'] |
| 148 | + assert options.check_path == ['x', 'y', 'z'] |
| 149 | + assert options.colorize is False |
| 150 | + |
| 151 | + |
| 152 | +def test_option_with_config(default_exec_ctx, extended_parser, tmp_path): |
| 153 | + with rt.temp_environment(variables={ |
| 154 | + 'RFM_TIMESTAMP': '%F', |
| 155 | + 'RFM_NON_DEFAULT_CRAYPE': 'yes', |
| 156 | + 'RFM_MODULES_PRELOAD': 'a,b,c', |
| 157 | + 'RFM_KEEP_STAGE_FILES': 'no' |
| 158 | + }): |
| 159 | + site_config = rt.runtime().site_config |
| 160 | + options = extended_parser.parse_args( |
| 161 | + ['--timestamp=%FT%T', '--nocolor'] |
| 162 | + ) |
| 163 | + options.update_config(site_config) |
| 164 | + assert site_config.get('general/0/check_search_recursive') is False |
| 165 | + assert site_config.get('general/0/timestamp_dirs') == '%FT%T' |
| 166 | + assert site_config.get('general/0/non_default_craype') is True |
| 167 | + assert site_config.get('systems/0/prefix') == str(tmp_path) |
| 168 | + assert site_config.get('general/0/colorize') is False |
| 169 | + assert site_config.get('general/0/keep_stage_files') is False |
| 170 | + |
| 171 | + # Defaults specified in parser override those in configuration file |
| 172 | + assert site_config.get('systems/0/stagedir') == '/foo' |
| 173 | + |
| 174 | + |
| 175 | +def test_option_envvar_conversion_error(default_exec_ctx, extended_parser): |
| 176 | + with rt.temp_environment(variables={ |
| 177 | + 'RFM_NON_DEFAULT_CRAYPE': 'foo', |
| 178 | + }): |
| 179 | + site_config = rt.runtime().site_config |
| 180 | + options = extended_parser.parse_args(['--nocolor']) |
| 181 | + errors = options.update_config(site_config) |
| 182 | + assert len(errors) == 1 |
0 commit comments