Swap noun/verb in :config-{add,remove}-{dict-list}

See https://github.com/qutebrowser/qutebrowser/pull/4324#issuecomment-428934193
This commit is contained in:
Florian Bruhin 2018-10-11 14:29:10 +02:00
parent 1c1223821c
commit 9d09aa1b40
3 changed files with 43 additions and 43 deletions

View File

@ -26,9 +26,9 @@ Added
- New `completion.open_categories` setting which allows to configure which - New `completion.open_categories` setting which allows to configure which
categories are shown in the `:open` completion, and how they are ordered. categories are shown in the `:open` completion, and how they are ordered.
- New config manipulation commands: - New config manipulation commands:
* `:config-add-dict` and `:config-add-list` to a new element to a dict/list * `:config-dict-add` and `:config-list-add` to a new element to a dict/list
setting. setting.
* `:config-remove-dict` and `:config-remove-list` to remove an element from a * `:config-dict-remove` and `:config-list-remove` to remove an element from a
dict/list setting. dict/list setting.
- New `hints.selectors` setting which allows to configure what CSS selectors - New `hints.selectors` setting which allows to configure what CSS selectors
are used for hints, and also allows adding custom hint groups. are used for hints, and also allows adding custom hint groups.

View File

@ -252,7 +252,7 @@ class ConfigCommands:
@cmdutils.register(instance='config-commands') @cmdutils.register(instance='config-commands')
@cmdutils.argument('option', completion=configmodel.list_option) @cmdutils.argument('option', completion=configmodel.list_option)
def config_add_list(self, option, value, temp=False): def config_list_add(self, option, value, temp=False):
"""Append a value to a config option that is a list. """Append a value to a config option that is a list.
Args: Args:
@ -263,7 +263,7 @@ class ConfigCommands:
opt = self._config.get_opt(option) opt = self._config.get_opt(option)
valid_list_types = (configtypes.List, configtypes.ListOrValue) valid_list_types = (configtypes.List, configtypes.ListOrValue)
if not isinstance(opt.typ, valid_list_types): if not isinstance(opt.typ, valid_list_types):
raise cmdexc.CommandError(":config-add-list can only be used for " raise cmdexc.CommandError(":config-list-add can only be used for "
"lists") "lists")
with self._handle_config_error(): with self._handle_config_error():
@ -273,7 +273,7 @@ class ConfigCommands:
@cmdutils.register(instance='config-commands') @cmdutils.register(instance='config-commands')
@cmdutils.argument('option', completion=configmodel.dict_option) @cmdutils.argument('option', completion=configmodel.dict_option)
def config_add_dict(self, option, key, value, temp=False, replace=False): def config_dict_add(self, option, key, value, temp=False, replace=False):
"""Add a key/value pair to a dictionary option. """Add a key/value pair to a dictionary option.
Args: Args:
@ -286,7 +286,7 @@ class ConfigCommands:
""" """
opt = self._config.get_opt(option) opt = self._config.get_opt(option)
if not isinstance(opt.typ, configtypes.Dict): if not isinstance(opt.typ, configtypes.Dict):
raise cmdexc.CommandError(":config-add-dict can only be used for " raise cmdexc.CommandError(":config-dict-add can only be used for "
"dicts") "dicts")
with self._handle_config_error(): with self._handle_config_error():
@ -302,7 +302,7 @@ class ConfigCommands:
@cmdutils.register(instance='config-commands') @cmdutils.register(instance='config-commands')
@cmdutils.argument('option', completion=configmodel.list_option) @cmdutils.argument('option', completion=configmodel.list_option)
def config_remove_list(self, option, value, temp=False): def config_list_remove(self, option, value, temp=False):
"""Remove a value from a list. """Remove a value from a list.
Args: Args:
@ -313,7 +313,7 @@ class ConfigCommands:
opt = self._config.get_opt(option) opt = self._config.get_opt(option)
valid_list_types = (configtypes.List, configtypes.ListOrValue) valid_list_types = (configtypes.List, configtypes.ListOrValue)
if not isinstance(opt.typ, valid_list_types): if not isinstance(opt.typ, valid_list_types):
raise cmdexc.CommandError(":config-remove-list can only be used " raise cmdexc.CommandError(":config-list-remove can only be used "
"for lists") "for lists")
with self._handle_config_error(): with self._handle_config_error():
@ -329,7 +329,7 @@ class ConfigCommands:
@cmdutils.register(instance='config-commands') @cmdutils.register(instance='config-commands')
@cmdutils.argument('option', completion=configmodel.dict_option) @cmdutils.argument('option', completion=configmodel.dict_option)
def config_remove_dict(self, option, key, temp=False): def config_dict_remove(self, option, key, temp=False):
"""Remove a key from a dict. """Remove a key from a dict.
Args: Args:
@ -339,7 +339,7 @@ class ConfigCommands:
""" """
opt = self._config.get_opt(option) opt = self._config.get_opt(option)
if not isinstance(opt.typ, configtypes.Dict): if not isinstance(opt.typ, configtypes.Dict):
raise cmdexc.CommandError(":config-remove-dict can only be used " raise cmdexc.CommandError(":config-dict-remove can only be used "
"for dicts") "for dicts")
with self._handle_config_error(): with self._handle_config_error():

View File

@ -284,14 +284,14 @@ class TestCycle:
class TestAdd: class TestAdd:
"""Test :config-add-list and :config-add-dict.""" """Test :config-list-add and :config-dict-add."""
@pytest.mark.parametrize('temp', [True, False]) @pytest.mark.parametrize('temp', [True, False])
@pytest.mark.parametrize('value', ['test1', 'test2']) @pytest.mark.parametrize('value', ['test1', 'test2'])
def test_add_list(self, commands, config_stub, yaml_value, temp, value): def test_list_add(self, commands, config_stub, yaml_value, temp, value):
name = 'content.host_blocking.whitelist' name = 'content.host_blocking.whitelist'
commands.config_add_list(name, value, temp=temp) commands.config_list_add(name, value, temp=temp)
assert str(config_stub.get(name)[-1]) == value assert str(config_stub.get(name)[-1]) == value
if temp: if temp:
@ -299,26 +299,26 @@ class TestAdd:
else: else:
assert yaml_value(name)[-1] == value assert yaml_value(name)[-1] == value
def test_add_list_non_list(self, commands): def test_list_add_non_list(self, commands):
with pytest.raises( with pytest.raises(
cmdexc.CommandError, cmdexc.CommandError,
match=":config-add-list can only be used for lists"): match=":config-list-add can only be used for lists"):
commands.config_add_list('history_gap_interval', 'value') commands.config_list_add('history_gap_interval', 'value')
@pytest.mark.parametrize('value', ['', None, 42]) @pytest.mark.parametrize('value', ['', None, 42])
def test_add_list_invalid_values(self, commands, value): def test_list_add_invalid_values(self, commands, value):
with pytest.raises( with pytest.raises(
cmdexc.CommandError, cmdexc.CommandError,
match="Invalid value '{}'".format(value)): match="Invalid value '{}'".format(value)):
commands.config_add_list('content.host_blocking.whitelist', value) commands.config_list_add('content.host_blocking.whitelist', value)
@pytest.mark.parametrize('value', ['test1', 'test2']) @pytest.mark.parametrize('value', ['test1', 'test2'])
@pytest.mark.parametrize('temp', [True, False]) @pytest.mark.parametrize('temp', [True, False])
def test_add_dict(self, commands, config_stub, yaml_value, value, temp): def test_dict_add(self, commands, config_stub, yaml_value, value, temp):
name = 'aliases' name = 'aliases'
key = 'missingkey' key = 'missingkey'
commands.config_add_dict(name, key, value, temp=temp) commands.config_dict_add(name, key, value, temp=temp)
assert str(config_stub.get(name)[key]) == value assert str(config_stub.get(name)[key]) == value
if temp: if temp:
@ -327,43 +327,43 @@ class TestAdd:
assert yaml_value(name)[key] == value assert yaml_value(name)[key] == value
@pytest.mark.parametrize('replace', [True, False]) @pytest.mark.parametrize('replace', [True, False])
def test_add_dict_replace(self, commands, config_stub, replace): def test_dict_add_replace(self, commands, config_stub, replace):
name = 'aliases' name = 'aliases'
key = 'w' key = 'w'
value = 'anything' value = 'anything'
if replace: if replace:
commands.config_add_dict(name, key, value, replace=True) commands.config_dict_add(name, key, value, replace=True)
assert str(config_stub.get(name)[key]) == value assert str(config_stub.get(name)[key]) == value
else: else:
with pytest.raises( with pytest.raises(
cmdexc.CommandError, cmdexc.CommandError,
match="w already exists in aliases - use --replace to " match="w already exists in aliases - use --replace to "
"overwrite!"): "overwrite!"):
commands.config_add_dict(name, key, value, replace=False) commands.config_dict_add(name, key, value, replace=False)
def test_add_dict_non_dict(self, commands): def test_dict_add_non_dict(self, commands):
with pytest.raises( with pytest.raises(
cmdexc.CommandError, cmdexc.CommandError,
match=":config-add-dict can only be used for dicts"): match=":config-dict-add can only be used for dicts"):
commands.config_add_dict('history_gap_interval', 'key', 'value') commands.config_dict_add('history_gap_interval', 'key', 'value')
@pytest.mark.parametrize('value', ['', None, 42]) @pytest.mark.parametrize('value', ['', None, 42])
def test_add_dict_invalid_values(self, commands, value): def test_dict_add_invalid_values(self, commands, value):
with pytest.raises(cmdexc.CommandError, with pytest.raises(cmdexc.CommandError,
match="Invalid value '{}'".format(value)): match="Invalid value '{}'".format(value)):
commands.config_add_dict('aliases', 'missingkey', value) commands.config_dict_add('aliases', 'missingkey', value)
class TestRemove: class TestRemove:
"""Test :config-remove-list and :config-remove-dict.""" """Test :config-list-remove and :config-dict-remove."""
@pytest.mark.parametrize('value', ['25%', '50%']) @pytest.mark.parametrize('value', ['25%', '50%'])
@pytest.mark.parametrize('temp', [True, False]) @pytest.mark.parametrize('temp', [True, False])
def test_remove_list(self, commands, config_stub, yaml_value, value, temp): def test_list_remove(self, commands, config_stub, yaml_value, value, temp):
name = 'zoom.levels' name = 'zoom.levels'
commands.config_remove_list(name, value, temp=temp) commands.config_list_remove(name, value, temp=temp)
assert value not in config_stub.get(name) assert value not in config_stub.get(name)
if temp: if temp:
@ -371,24 +371,24 @@ class TestRemove:
else: else:
assert value not in yaml_value(name) assert value not in yaml_value(name)
def test_remove_list_non_list(self, commands): def test_list_remove_non_list(self, commands):
with pytest.raises( with pytest.raises(
cmdexc.CommandError, cmdexc.CommandError,
match=":config-remove-list can only be used for lists"): match=":config-list-remove can only be used for lists"):
commands.config_remove_list('content.javascript.enabled', commands.config_list_remove('content.javascript.enabled',
'never') 'never')
def test_remove_list_no_value(self, commands): def test_list_remove_no_value(self, commands):
with pytest.raises( with pytest.raises(
cmdexc.CommandError, cmdexc.CommandError,
match="never is not in colors.completion.fg!"): match="never is not in colors.completion.fg!"):
commands.config_remove_list('colors.completion.fg', 'never') commands.config_list_remove('colors.completion.fg', 'never')
@pytest.mark.parametrize('key', ['w', 'q']) @pytest.mark.parametrize('key', ['w', 'q'])
@pytest.mark.parametrize('temp', [True, False]) @pytest.mark.parametrize('temp', [True, False])
def test_remove_dict(self, commands, config_stub, yaml_value, key, temp): def test_dict_remove(self, commands, config_stub, yaml_value, key, temp):
name = 'aliases' name = 'aliases'
commands.config_remove_dict(name, key, temp=temp) commands.config_dict_remove(name, key, temp=temp)
assert key not in config_stub.get(name) assert key not in config_stub.get(name)
if temp: if temp:
@ -396,18 +396,18 @@ class TestRemove:
else: else:
assert key not in yaml_value(name) assert key not in yaml_value(name)
def test_remove_dict_non_dict(self, commands): def test_dict_remove_non_dict(self, commands):
with pytest.raises( with pytest.raises(
cmdexc.CommandError, cmdexc.CommandError,
match=":config-remove-dict can only be used for dicts"): match=":config-dict-remove can only be used for dicts"):
commands.config_remove_dict('content.javascript.enabled', commands.config_dict_remove('content.javascript.enabled',
'never') 'never')
def test_remove_dict_no_value(self, commands): def test_dict_remove_no_value(self, commands):
with pytest.raises( with pytest.raises(
cmdexc.CommandError, cmdexc.CommandError,
match="never is not in aliases!"): match="never is not in aliases!"):
commands.config_remove_dict('aliases', 'never') commands.config_dict_remove('aliases', 'never')
class TestUnsetAndClear: class TestUnsetAndClear: