Rename KeyConfig._prepare to ._validate
This commit is contained in:
parent
49d297f7bf
commit
5a5873d4ee
@ -136,8 +136,8 @@ class KeyConfig:
|
|||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self._config = config
|
self._config = config
|
||||||
|
|
||||||
def _prepare(self, key, mode):
|
def _validate(self, key, mode):
|
||||||
"""Make sure the given mode exists."""
|
"""Validate the given key and mode."""
|
||||||
# Catch old usage of this code
|
# Catch old usage of this code
|
||||||
assert isinstance(key, keyutils.KeySequence), key
|
assert isinstance(key, keyutils.KeySequence), key
|
||||||
if mode not in configdata.DATA['bindings.default'].default:
|
if mode not in configdata.DATA['bindings.default'].default:
|
||||||
@ -170,7 +170,7 @@ class KeyConfig:
|
|||||||
|
|
||||||
def get_command(self, key, mode, default=False):
|
def get_command(self, key, mode, default=False):
|
||||||
"""Get the command for a given key (or None)."""
|
"""Get the command for a given key (or None)."""
|
||||||
self._prepare(key, mode)
|
self._validate(key, mode)
|
||||||
if default:
|
if default:
|
||||||
bindings = dict(val.bindings.default[mode])
|
bindings = dict(val.bindings.default[mode])
|
||||||
else:
|
else:
|
||||||
@ -184,7 +184,7 @@ class KeyConfig:
|
|||||||
"Can't add binding '{}' with empty command in {} "
|
"Can't add binding '{}' with empty command in {} "
|
||||||
'mode'.format(key, mode))
|
'mode'.format(key, mode))
|
||||||
|
|
||||||
self._prepare(key, mode)
|
self._validate(key, mode)
|
||||||
log.keyboard.vdebug("Adding binding {} -> {} in mode {}.".format(
|
log.keyboard.vdebug("Adding binding {} -> {} in mode {}.".format(
|
||||||
key, command, mode))
|
key, command, mode))
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ class KeyConfig:
|
|||||||
|
|
||||||
def bind_default(self, key, *, mode='normal', save_yaml=False):
|
def bind_default(self, key, *, mode='normal', save_yaml=False):
|
||||||
"""Restore a default keybinding."""
|
"""Restore a default keybinding."""
|
||||||
self._prepare(key, mode)
|
self._validate(key, mode)
|
||||||
|
|
||||||
bindings_commands = self._config.get_mutable_obj('bindings.commands')
|
bindings_commands = self._config.get_mutable_obj('bindings.commands')
|
||||||
try:
|
try:
|
||||||
@ -208,7 +208,7 @@ class KeyConfig:
|
|||||||
|
|
||||||
def unbind(self, key, *, mode='normal', save_yaml=False):
|
def unbind(self, key, *, mode='normal', save_yaml=False):
|
||||||
"""Unbind the given key in the given mode."""
|
"""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')
|
bindings_commands = self._config.get_mutable_obj('bindings.commands')
|
||||||
|
|
||||||
|
@ -103,15 +103,13 @@ class TestKeyConfig:
|
|||||||
"""Get a dict with no bindings."""
|
"""Get a dict with no bindings."""
|
||||||
return {'normal': {}}
|
return {'normal': {}}
|
||||||
|
|
||||||
def test_prepare_invalid_mode(self, key_config_stub):
|
def test_validate_invalid_mode(self, key_config_stub):
|
||||||
"""Make sure prepare checks the mode."""
|
|
||||||
with pytest.raises(configexc.KeybindingError):
|
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):
|
def test_validate_invalid_type(self, key_config_stub):
|
||||||
"""Make sure prepare checks the type."""
|
|
||||||
with pytest.raises(AssertionError):
|
with pytest.raises(AssertionError):
|
||||||
assert key_config_stub._prepare('x', 'normal')
|
assert key_config_stub._validate('x', 'normal')
|
||||||
|
|
||||||
@pytest.mark.parametrize('commands, expected', [
|
@pytest.mark.parametrize('commands, expected', [
|
||||||
# Unbinding default key
|
# Unbinding default key
|
||||||
|
Loading…
Reference in New Issue
Block a user