Refactor read_config for easier testing
This commit is contained in:
parent
05eb9bd08c
commit
09161faca5
@ -326,9 +326,12 @@ class BaseKeyParser(QObject):
|
|||||||
self.special_bindings = {}
|
self.special_bindings = {}
|
||||||
keyconfparser = objreg.get('key-config')
|
keyconfparser = objreg.get('key-config')
|
||||||
for (key, cmd) in keyconfparser.get_bindings_for(modename).items():
|
for (key, cmd) in keyconfparser.get_bindings_for(modename).items():
|
||||||
if not cmd:
|
if cmd:
|
||||||
continue
|
self._parse_key_command(modename, key, cmd)
|
||||||
elif key.startswith('<') and key.endswith('>'):
|
|
||||||
|
def _parse_key_command(self, modename, key, cmd):
|
||||||
|
"""Parse the keys and their command and store them in the object."""
|
||||||
|
if key.startswith('<') and key.endswith('>'):
|
||||||
keystr = utils.normalize_keystr(key[1:-1])
|
keystr = utils.normalize_keystr(key[1:-1])
|
||||||
self.special_bindings[keystr] = cmd
|
self.special_bindings[keystr] = cmd
|
||||||
elif self._supports_chains:
|
elif self._supports_chains:
|
||||||
@ -336,7 +339,8 @@ class BaseKeyParser(QObject):
|
|||||||
elif self._warn_on_keychains:
|
elif self._warn_on_keychains:
|
||||||
log.keyboard.warning(
|
log.keyboard.warning(
|
||||||
"Ignoring keychain '{}' in mode '{}' because "
|
"Ignoring keychain '{}' in mode '{}' because "
|
||||||
"keychains are not supported there.".format(key, modename))
|
"keychains are not supported there."
|
||||||
|
.format(key, modename))
|
||||||
|
|
||||||
def execute(self, cmdstr, keytype, count=None):
|
def execute(self, cmdstr, keytype, count=None):
|
||||||
"""Handle a completed keychain.
|
"""Handle a completed keychain.
|
||||||
|
@ -79,6 +79,13 @@ class TestReadConfig:
|
|||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
kp.read_config()
|
kp.read_config()
|
||||||
|
|
||||||
|
def test_read_config_no_modename(self):
|
||||||
|
"""Test reading config with _modename set."""
|
||||||
|
kp = basekeyparser.BaseKeyParser(0, supports_chains=True)
|
||||||
|
kp._modename = "normal"
|
||||||
|
kp.read_config(modename=None)
|
||||||
|
assert 'a' in kp.bindings
|
||||||
|
|
||||||
def test_read_config_valid(self):
|
def test_read_config_valid(self):
|
||||||
"""Test reading config."""
|
"""Test reading config."""
|
||||||
kp = basekeyparser.BaseKeyParser(0, supports_count=True,
|
kp = basekeyparser.BaseKeyParser(0, supports_count=True,
|
||||||
|
Loading…
Reference in New Issue
Block a user