Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions unittests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
os.path.dirname(os.path.realpath(__file__)), 'modules'
)

# Builtin configuration
BUILTIN_CONFIG_FILE = 'reframe/core/settings.py'

# Unit tests site configuration
TEST_CONFIG_FILE = 'unittests/resources/settings.py'

Expand Down
95 changes: 49 additions & 46 deletions unittests/test_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,55 +123,58 @@ def extended_parser():


def test_option_precedence(extended_parser):
with rt.temp_environment(variables={
'RFM_TIMESTAMP': '%F',
'RFM_NON_DEFAULT_CRAYPE': 'yes',
'RFM_MODULES_PRELOAD': 'a,b,c',
'RFM_CHECK_SEARCH_PATH': 'x:y:z'

}):
options = extended_parser.parse_args(
['--timestamp=%FT%T', '--nocolor']
)
assert options.recursive is None
assert options.timestamp == '%FT%T'
assert options.non_default_craype is True
assert options.config_file is None
assert options.prefix is None
assert options.stagedir == '/foo'
assert options.module == ['a', 'b', 'c']
assert options.check_path == ['x', 'y', 'z']
assert options.colorize is False
with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE):
with rt.temp_environment(variables={
'RFM_TIMESTAMP': '%F',
'RFM_NON_DEFAULT_CRAYPE': 'yes',
'RFM_MODULES_PRELOAD': 'a,b,c',
'RFM_CHECK_SEARCH_PATH': 'x:y:z'

}):
options = extended_parser.parse_args(
['--timestamp=%FT%T', '--nocolor']
)
assert options.recursive is None
assert options.timestamp == '%FT%T'
assert options.non_default_craype is True
assert options.config_file is None
assert options.prefix is None
assert options.stagedir == '/foo'
assert options.module == ['a', 'b', 'c']
assert options.check_path == ['x', 'y', 'z']
assert options.colorize is False


def test_option_with_config(extended_parser):
with rt.temp_environment(variables={
'RFM_TIMESTAMP': '%F',
'RFM_NON_DEFAULT_CRAYPE': 'yes',
'RFM_MODULES_PRELOAD': 'a,b,c',
'RFM_KEEP_STAGE_FILES': 'no'
}):
site_config = rt.runtime().site_config
options = extended_parser.parse_args(
['--timestamp=%FT%T', '--nocolor']
)
options.update_config(site_config)
assert site_config.get('general/0/check_search_recursive') is False
assert site_config.get('general/0/timestamp_dirs') == '%FT%T'
assert site_config.get('general/0/non_default_craype') is True
assert site_config.get('systems/0/prefix') == '.'
assert site_config.get('general/0/colorize') is False
assert site_config.get('general/0/keep_stage_files') is False

# Defaults specified in parser override those in configuration file
assert site_config.get('systems/0/stagedir') == '/foo'
with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE):
with rt.temp_environment(variables={
'RFM_TIMESTAMP': '%F',
'RFM_NON_DEFAULT_CRAYPE': 'yes',
'RFM_MODULES_PRELOAD': 'a,b,c',
'RFM_KEEP_STAGE_FILES': 'no'
}):
site_config = rt.runtime().site_config
options = extended_parser.parse_args(
['--timestamp=%FT%T', '--nocolor']
)
options.update_config(site_config)
assert site_config.get('general/0/check_search_recursive') is False
assert site_config.get('general/0/timestamp_dirs') == '%FT%T'
assert site_config.get('general/0/non_default_craype') is True
assert site_config.get('systems/0/prefix') == '.'
assert site_config.get('general/0/colorize') is False
assert site_config.get('general/0/keep_stage_files') is False

# Defaults specified in parser override those in configuration file
assert site_config.get('systems/0/stagedir') == '/foo'


def test_option_envvar_conversion_error(extended_parser):
with rt.temp_environment(variables={
'RFM_NON_DEFAULT_CRAYPE': 'foo',
}):
site_config = rt.runtime().site_config
options = extended_parser.parse_args(['--nocolor'])
errors = options.update_config(site_config)
assert len(errors) == 1
with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE):
with rt.temp_environment(variables={
'RFM_NON_DEFAULT_CRAYPE': 'foo',
}):
site_config = rt.runtime().site_config
options = extended_parser.parse_args(['--nocolor'])
errors = options.update_config(site_config)
assert len(errors) == 1