Skip to content

Commit

Permalink
CLI: Keep list unique in verdi config set --append (#6162)
Browse files Browse the repository at this point in the history
When calling the command multiple times for the same value, it would be
added multiple times to the list, even though in all cases a unique list
would be expected.
  • Loading branch information
sphuber committed Nov 2, 2023
1 parent 45767f0 commit 3844f86
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aiida/cmdline/commands/cmd_config.py
Expand Up @@ -143,7 +143,7 @@ def verdi_config_set(ctx, option, value, globally, append, remove):
if not isinstance(current, list):
echo.echo_critical(f'cannot append/remove to value: {current}')
if append:
value = current + [value]
value = list(set(current + [value]))
else:
value = [item for item in current if item != value]

Expand Down
6 changes: 3 additions & 3 deletions tests/cmdline/commands/test_config.py
Expand Up @@ -49,18 +49,18 @@ def test_config_append_option(run_cli_command, config_with_profile_factory):
"""Test the `verdi config set --append` command when appending an option value."""
config = config_with_profile_factory()
option_name = 'caching.enabled_for'
for value in ['x', 'y']:
for value in ['x', 'y', 'x', 'y']:
options = ['config', 'set', '--append', option_name, value]
run_cli_command(cmd_verdi.verdi, options, use_subprocess=False)
assert config.get_option(option_name, scope=get_profile().name) == ['x', 'y']
assert sorted(config.get_option(option_name, scope=get_profile().name)) == ['x', 'y']


def test_config_remove_option(run_cli_command, config_with_profile_factory):
"""Test the `verdi config set --remove` command when removing an option value."""
config = config_with_profile_factory()

option_name = 'caching.disabled_for'
config.set_option(option_name, ['x', 'y'], scope=get_profile().name)
config.set_option(option_name, ['x', 'x', 'y', 'x'], scope=get_profile().name)

options = ['config', 'set', '--remove', option_name, 'x']
run_cli_command(cmd_verdi.verdi, options, use_subprocess=False)
Expand Down

0 comments on commit 3844f86

Please sign in to comment.