Fixed broken unit tests, fixed typos, and general cleanup for linting and consistency with main branch
Merges needed were:
* qutebrowser/keyinput/basekeyparser.py for the new count precaution (commit 51aa7ab)
This commit is contained in:
parent
975e2270f5
commit
907fa53806
|
|
@ -11,7 +11,7 @@ import traceback
|
|||
from typing import Optional, List
|
||||
from collections.abc import Mapping, MutableMapping, Sequence
|
||||
|
||||
from qutebrowser.qt.core import QObject, pyqtSignal, pyqtSlot
|
||||
from qutebrowser.qt.core import QObject, pyqtSignal
|
||||
from qutebrowser.qt.gui import QKeySequence, QKeyEvent
|
||||
|
||||
from qutebrowser.config import config
|
||||
|
|
@ -287,7 +287,7 @@ class BaseKeyParser(QObject):
|
|||
return True
|
||||
return False
|
||||
|
||||
def handle(self, e: QKeyEvent, *,
|
||||
def handle(self, e: QKeyEvent, *, # noqa: C901
|
||||
dry_run: bool = False) -> QKeySequence.SequenceMatch:
|
||||
"""Handle a new keypress.
|
||||
|
||||
|
|
@ -378,7 +378,7 @@ class BaseKeyParser(QObject):
|
|||
"key in the sequence and retry.".format(
|
||||
result.sequence))
|
||||
# Forward all the leading count keys
|
||||
while count_keyposs and (0 == count_keyposs[0]):
|
||||
while count_keyposs and (count_keyposs[0] == 0):
|
||||
self._debug_log("Hit a queued count key ('{}'). "
|
||||
"Forwarding.".format(count[0]))
|
||||
count = count[1:]
|
||||
|
|
@ -405,7 +405,11 @@ class BaseKeyParser(QObject):
|
|||
|
||||
if dry_run:
|
||||
return result.match_type
|
||||
self._handle_result(info, result)
|
||||
return result.match_type
|
||||
|
||||
def _handle_result(self, info: keyutils.KeyInfo, result: MatchResult) -> None:
|
||||
"""Handle a final MatchResult from handle()."""
|
||||
# Each of the three following blocks need to emit
|
||||
# self.keystring_updated, either directly (as PartialMatch does) or
|
||||
# indirectly (as ExactMatch and NoMatch do via self.clear_keystring)
|
||||
|
|
@ -414,7 +418,8 @@ class BaseKeyParser(QObject):
|
|||
self._debug_log("Definitive match for '{}'.".format(
|
||||
result.sequence))
|
||||
try:
|
||||
count_int = int(self._count) if self._count else None
|
||||
# note: this 'count' is an int, not a str
|
||||
count = int(self._count) if self._count else None
|
||||
flag_do_execute = True
|
||||
except ValueError as err:
|
||||
message.error(f"Failed to parse count: {err}",
|
||||
|
|
@ -423,7 +428,7 @@ class BaseKeyParser(QObject):
|
|||
self.clear_partial_keys.emit()
|
||||
self.clear_keystring()
|
||||
if flag_do_execute:
|
||||
self.execute(result.command, count_int)
|
||||
self.execute(result.command, count)
|
||||
elif result.match_type == QKeySequence.SequenceMatch.PartialMatch:
|
||||
self._debug_log("No match for '{}' (added {})".format(
|
||||
result.sequence, info))
|
||||
|
|
@ -436,8 +441,6 @@ class BaseKeyParser(QObject):
|
|||
raise utils.Unreachable("Invalid match value {!r}".format(
|
||||
result.match_type))
|
||||
|
||||
return result.match_type
|
||||
|
||||
@config.change_filter('bindings')
|
||||
def _on_config_changed(self) -> None:
|
||||
self._read_config()
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ class ModeManager(QObject):
|
|||
def __repr__(self) -> str:
|
||||
return utils.get_repr(self, mode=self.mode)
|
||||
|
||||
def _handle_keypress(self, event: QKeyEvent, *,
|
||||
def _handle_keypress(self, event: QKeyEvent, *, # noqa: C901
|
||||
dry_run: bool = False) -> bool:
|
||||
"""Handle filtering of KeyPress events.
|
||||
|
||||
|
|
@ -422,7 +422,7 @@ class ModeManager(QObject):
|
|||
(forward_unbound_keys == 'auto' and is_non_alnum))
|
||||
|
||||
@pyqtSlot(usertypes.KeyMode, str)
|
||||
def forward_partial_match_event(self, mode: usertypes.KeyMode,
|
||||
def forward_partial_match_event(self, mode: usertypes.KeyMode, # noqa: C901
|
||||
text: str = None) -> None:
|
||||
"""Forward the oldest partial match event for a given mode.
|
||||
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ class HintKeyParser(basekeyparser.BaseKeyParser):
|
|||
"empty queue: {}".format(e))
|
||||
self._partial_match_events.append(
|
||||
keyutils.QueuedKeyEventPair.from_event_press(e))
|
||||
self._debug_log("Staring partial timer.")
|
||||
self._debug_log("Starting partial timer.")
|
||||
self._start_partial_timer()
|
||||
return result
|
||||
elif not had_empty_queue:
|
||||
|
|
@ -278,7 +278,7 @@ class HintKeyParser(basekeyparser.BaseKeyParser):
|
|||
self._debug_log("Text mismatch (this is likely benign): '{}' != "
|
||||
"'{}'".format(text_actual, text))
|
||||
e = match_event.to_events()
|
||||
assert 1 == len(e)
|
||||
assert len(e) == 1
|
||||
self._handle_hint(e[0])
|
||||
|
||||
@pyqtSlot()
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ BINDINGS = {'prompt': {'<Ctrl-a>': 'message-info ctrla',
|
|||
'<Ctrl+X>': 'message-info ctrlx'},
|
||||
'normal': {'a': 'message-info a',
|
||||
'ba': 'message-info ba',
|
||||
'ccc': 'message-info ccc'}
|
||||
}
|
||||
'ccc': 'message-info ccc'}}
|
||||
MAPPINGS = {
|
||||
'x': 'a',
|
||||
'b': 'a',
|
||||
|
|
|
|||
|
|
@ -419,10 +419,10 @@ class TestHandle:
|
|||
}
|
||||
|
||||
result = keyparser.handle(
|
||||
keyutils.KeyInfo(Qt.Key_X, Qt.KeyboardModifier.NoModifier).to_event())
|
||||
keyutils.KeyInfo(Qt.Key.Key_X, Qt.KeyboardModifier.NoModifier).to_event())
|
||||
assert result == QKeySequence.SequenceMatch.PartialMatch
|
||||
result = keyparser.handle(
|
||||
keyutils.KeyInfo(Qt.Key_2, Qt.KeyboardModifier.NoModifier).to_event())
|
||||
keyutils.KeyInfo(Qt.Key.Key_2, Qt.KeyboardModifier.NoModifier).to_event())
|
||||
# Check that count is not evaluated when an expansive mapping occurs.
|
||||
# This behavior may change in the future.
|
||||
assert result == QKeySequence.SequenceMatch.NoMatch
|
||||
|
|
@ -452,7 +452,7 @@ class TestCount:
|
|||
assert not prompt_keyparser._sequence
|
||||
|
||||
def test_count_42_invalid(self, handle_text, prompt_keyparser):
|
||||
# Invalid call with ccx gets ignored
|
||||
# Invalid call with cce gets ignored
|
||||
handle_text(prompt_keyparser,
|
||||
Qt.Key.Key_4, Qt.Key.Key_2, Qt.Key.Key_C, Qt.Key.Key_C, Qt.Key.Key_E)
|
||||
assert not prompt_keyparser.execute.called
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ class FakeKeyparser(QObject):
|
|||
self.allow_forward = True
|
||||
self.forward_widget_name = None
|
||||
|
||||
def get_do_log(self):
|
||||
return True
|
||||
|
||||
def handle(
|
||||
self,
|
||||
evt: QKeyEvent,
|
||||
|
|
@ -78,11 +81,14 @@ class FakeKeyparserWithTimeout(QObject):
|
|||
self.forward_widget_name = None
|
||||
self.fake_clear_keystring_called = False
|
||||
|
||||
def get_do_log(self):
|
||||
return True
|
||||
|
||||
def handle(self, evt, *, dry_run=False):
|
||||
txt = str(keyutils.KeyInfo.from_event(evt))
|
||||
if 'a' == txt:
|
||||
if txt == 'a':
|
||||
return QKeySequence.SequenceMatch.ExactMatch
|
||||
elif 'b' == txt:
|
||||
elif txt == 'b':
|
||||
return QKeySequence.SequenceMatch.PartialMatch
|
||||
else:
|
||||
return QKeySequence.SequenceMatch.NoMatch
|
||||
|
|
@ -147,9 +153,11 @@ def test_partial_keychain_timeout(modeman_with_timeout, config_stub, qtbot, data
|
|||
else:
|
||||
pytest.fail('Unreachable')
|
||||
if behavior in ['timer_active', 'timer_reset']:
|
||||
# Now simulate a timeout and check the keystring has been cleared.
|
||||
with qtbot.wait_signal(modeman_with_timeout.keystring_updated) as blocker:
|
||||
timer.timeout.emit()
|
||||
# Wait for the timer to timeout and check the keystring has been cleared.
|
||||
# Only wait for up to 2*timeout, then raise an error.
|
||||
with qtbot.wait_signal(modeman_with_timeout.keystring_updated,
|
||||
timeout=2*timeout) as blocker:
|
||||
pass
|
||||
assert parser.fake_clear_keystring_called
|
||||
parser.fake_clear_keystring_called = False
|
||||
assert blocker.args == [mode, '']
|
||||
|
|
|
|||
|
|
@ -320,8 +320,10 @@ class TestHintKeyParser:
|
|||
else:
|
||||
pytest.fail('Unreachable')
|
||||
if behavior in ['timer_active', 'timer_reset']:
|
||||
# Now simulate a timeout and check the keystring has been forwarded.
|
||||
with qtbot.wait_signal(command_parser.keystring_updated) as blocker:
|
||||
timer.timeout.emit()
|
||||
# Wait for the timer to timeout and check the keystring has been forwarded.
|
||||
# Only wait for up to 2*timeout, then raise an error.
|
||||
with qtbot.wait_signal(command_parser.keystring_updated,
|
||||
timeout=2*timeout) as blocker:
|
||||
pass
|
||||
assert blocker.args == ['']
|
||||
assert hintmanager.keystr == ('b' * len(data_sequence))
|
||||
|
|
|
|||
Loading…
Reference in New Issue