Rename KeyConfig._prepare to ._validate

This commit is contained in:
Florian Bruhin 2018-02-27 14:16:41 +01:00
parent 49d297f7bf
commit 5a5873d4ee
2 changed files with 10 additions and 12 deletions

View File

@ -136,8 +136,8 @@ class KeyConfig:
def __init__(self, config):
self._config = config
def _prepare(self, key, mode):
"""Make sure the given mode exists."""
def _validate(self, key, mode):
"""Validate the given key and mode."""
# Catch old usage of this code
assert isinstance(key, keyutils.KeySequence), key
if mode not in configdata.DATA['bindings.default'].default:
@ -170,7 +170,7 @@ class KeyConfig:
def get_command(self, key, mode, default=False):
"""Get the command for a given key (or None)."""
self._prepare(key, mode)
self._validate(key, mode)
if default:
bindings = dict(val.bindings.default[mode])
else:
@ -184,7 +184,7 @@ class KeyConfig:
"Can't add binding '{}' with empty command in {} "
'mode'.format(key, mode))
self._prepare(key, mode)
self._validate(key, mode)
log.keyboard.vdebug("Adding binding {} -> {} in mode {}.".format(
key, command, mode))
@ -196,7 +196,7 @@ class KeyConfig:
def bind_default(self, key, *, mode='normal', save_yaml=False):
"""Restore a default keybinding."""
self._prepare(key, mode)
self._validate(key, mode)
bindings_commands = self._config.get_mutable_obj('bindings.commands')
try:
@ -208,7 +208,7 @@ class KeyConfig:
def unbind(self, key, *, mode='normal', save_yaml=False):
"""Unbind the given key in the given mode."""
self._prepare(key, mode)
self._validate(key, mode)
bindings_commands = self._config.get_mutable_obj('bindings.commands')

View File

@ -103,15 +103,13 @@ class TestKeyConfig:
"""Get a dict with no bindings."""
return {'normal': {}}
def test_prepare_invalid_mode(self, key_config_stub):
"""Make sure prepare checks the mode."""
def test_validate_invalid_mode(self, key_config_stub):
with pytest.raises(configexc.KeybindingError):
assert key_config_stub._prepare(keyseq('x'), 'abnormal')
assert key_config_stub._validate(keyseq('x'), 'abnormal')
def test_prepare_invalid_type(self, key_config_stub):
"""Make sure prepare checks the type."""
def test_validate_invalid_type(self, key_config_stub):
with pytest.raises(AssertionError):
assert key_config_stub._prepare('x', 'normal')
assert key_config_stub._validate('x', 'normal')
@pytest.mark.parametrize('commands, expected', [
# Unbinding default key