Skip to content

Commit

Permalink
Copy mutable default configuration parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Theofilos Manitaras <[email protected]>
  • Loading branch information
teojgo authored and vkarak committed Feb 7, 2025
1 parent 9842e68 commit aa62ec9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
11 changes: 9 additions & 2 deletions reframe/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@


def _match_option(opt, opt_map):
def _copy_if_mutable(item):
for c in (dict, list):
if isinstance(item, c):
return c(item)

return item

if isinstance(opt, list):
opt = '/'.join(opt)

if opt in opt_map:
return opt_map[opt]
return _copy_if_mutable(opt_map[opt])

for k, v in opt_map.items():
if fnmatch.fnmatchcase(opt, k):
return v
return _copy_if_mutable(v)

raise KeyError(opt)

Expand Down
22 changes: 21 additions & 1 deletion unittests/resources/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def hostname():
'launcher': 'local',
'environs': ['e0', 'e1', 'e2']
}

]
},
{
Expand All @@ -194,6 +193,27 @@ def hostname():
'environs': ['builtin']
}
]
},
{
'name': 'sys3',
'descr': 'System required for testing default extras',
'hostnames': [r'sys3\d+'],
'partitions': [
{
'name': 'part1',
'descr': 'Login nodes',
'scheduler': 'local',
'launcher': 'local',
'environs': ['builtin']
},
{
'name': 'part2',
'descr': 'Compute nodes',
'scheduler': 'slurm',
'launcher': 'srun',
'environs': ['builtin']
}
]
}
],
'environments': [
Expand Down
12 changes: 12 additions & 0 deletions unittests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,18 @@ def test_system_create(site_config):
system = System.create(site_config)
assert system.partitions[0].container_runtime == 'Docker'

# Test correct extras when partitions have no extras set
# See: https://github.com/reframe-hpc/reframe/issues/3371
site_config.select_subconfig('sys3:part1')
system = System.create(site_config)
assert system.partitions[0].extras == {'scheduler': 'local',
'launcher': 'local'}

site_config.select_subconfig('sys3:part2')
system = System.create(site_config)
assert system.partitions[0].extras == {'scheduler': 'slurm',
'launcher': 'srun'}


def test_variables(tmp_path):
# Test that the old syntax using `variables` instead of `env_vars` still
Expand Down

0 comments on commit aa62ec9

Please sign in to comment.