Add unit tests for KeyInput.BaseKeyParser
This commit is contained in:
parent
355074f248
commit
193a8d5242
@ -186,9 +186,6 @@ class BaseKeyParser(QObject):
|
||||
|
||||
match, binding = self._match_key(cmd_input)
|
||||
|
||||
if not isinstance(match, self.Match):
|
||||
raise TypeError("Value {} is no Match member!".format(match))
|
||||
|
||||
if match == self.Match.definitive:
|
||||
self._debug_log("Definitive match for '{}'.".format(
|
||||
self._keystring))
|
||||
@ -205,6 +202,8 @@ class BaseKeyParser(QObject):
|
||||
self._debug_log("Giving up with '{}', no matches".format(
|
||||
self._keystring))
|
||||
self._keystring = ''
|
||||
else:
|
||||
raise AssertionError("Invalid match value {!r}".format(match))
|
||||
return match
|
||||
|
||||
def _match_key(self, cmd_input):
|
||||
|
@ -27,9 +27,11 @@ from PyQt5.QtCore import Qt
|
||||
import pytest
|
||||
|
||||
from qutebrowser.keyinput import basekeyparser
|
||||
from qutebrowser.utils import utils
|
||||
|
||||
|
||||
CONFIG = {'input': {'timeout': 100}}
|
||||
CONFIG_NO_TIMEOUT = {'input': {'timeout': 0}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -131,6 +133,15 @@ class TestSpecialKeys:
|
||||
self.kp.handle(fake_keyevent_factory(Qt.Key_A))
|
||||
assert not self.kp.execute.called
|
||||
|
||||
def test_no_binding(self, monkeypatch, fake_keyevent_factory):
|
||||
"""Test special key with no binding."""
|
||||
def none_return(binding):
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(utils, 'keyevent_to_string', none_return)
|
||||
self.kp.handle(fake_keyevent_factory(Qt.Key_A, Qt.NoModifier))
|
||||
assert not self.kp.execute.called
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('mock_timer')
|
||||
class TestKeyChain:
|
||||
@ -205,6 +216,17 @@ class TestKeyChain:
|
||||
assert not timer.isActive()
|
||||
assert self.kp._keystring == ''
|
||||
|
||||
def test_ambiguous_keychain_no_timeout(self, fake_keyevent_factory,
|
||||
config_stub, monkeypatch):
|
||||
"""Test ambiguous keychain with timeout equal to 0."""
|
||||
config_stub.data = CONFIG_NO_TIMEOUT
|
||||
monkeypatch.setattr('qutebrowser.keyinput.basekeyparser.config',
|
||||
config_stub)
|
||||
self.kp.handle(fake_keyevent_factory(Qt.Key_A, text='a'))
|
||||
assert self.kp.execute.called
|
||||
timer = self.kp._ambiguous_timer
|
||||
assert not timer.isActive()
|
||||
|
||||
def test_invalid_keychain(self, fake_keyevent_factory):
|
||||
"""Test invalid keychain."""
|
||||
self.kp.handle(fake_keyevent_factory(Qt.Key_B, text='b'))
|
||||
|
Loading…
Reference in New Issue
Block a user