diff --git a/qutebrowser/keyinput/keyutils.py b/qutebrowser/keyinput/keyutils.py index ddc78b2b4..fd973eb80 100644 --- a/qutebrowser/keyinput/keyutils.py +++ b/qutebrowser/keyinput/keyutils.py @@ -391,7 +391,7 @@ class KeySequence: return QKeySequence.ExactMatch elif len(self._sequences) < len(other._sequences): return QKeySequence.PartialMatch - else: + else: # pragma: no cover assert False, (self, other) def append_event(self, ev): diff --git a/scripts/dev/check_coverage.py b/scripts/dev/check_coverage.py index 0e79a6e02..b40188429 100644 --- a/scripts/dev/check_coverage.py +++ b/scripts/dev/check_coverage.py @@ -86,6 +86,8 @@ PERFECT_FILES = [ ('tests/unit/keyinput/test_basekeyparser.py', 'keyinput/basekeyparser.py'), + ('tests/unit/keyinput/test_keyutils.py', + 'keyinput/keyutils.py'), ('tests/unit/misc/test_autoupdate.py', 'misc/autoupdate.py'), diff --git a/tests/unit/keyinput/test_keyutils.py b/tests/unit/keyinput/test_keyutils.py index 0f13c762d..3f03f883d 100644 --- a/tests/unit/keyinput/test_keyutils.py +++ b/tests/unit/keyinput/test_keyutils.py @@ -320,6 +320,30 @@ class TestKeySequence: configured = keyutils.KeySequence.parse(configured) assert entered.matches(configured) == expected + @pytest.mark.parametrize('old, key, modifiers, text, expected', [ + ('a', Qt.Key_B, Qt.NoModifier, 'b', 'ab'), + ('a', Qt.Key_B, Qt.ShiftModifier, 'B', 'aB'), + ('a', Qt.Key_B, Qt.ControlModifier | Qt.ShiftModifier, 'B', + 'a'), + + # Modifier stripping with symbols + ('', Qt.Key_Colon, Qt.NoModifier, ':', ':'), + ('', Qt.Key_Colon, Qt.ShiftModifier, ':', ':'), + ('', Qt.Key_Colon, Qt.ControlModifier | Qt.ShiftModifier, ':', + ''), + + # Handling of Backtab + ('', Qt.Key_Backtab, Qt.NoModifier, '', ''), + ('', Qt.Key_Backtab, Qt.ShiftModifier, '', ''), + ('', Qt.Key_Backtab, Qt.ControlModifier | Qt.ShiftModifier, '', + ''), + ]) + def test_append_event(self, old, key, modifiers, text, expected): + seq = keyutils.KeySequence.parse(old) + event = QKeyEvent(QKeyEvent.KeyPress, key, modifiers, text) + new = seq.append_event(event) + assert new == keyutils.KeySequence.parse(expected) + @pytest.mark.parametrize('keystr, expected', [ ('', keyutils.KeySequence(Qt.ControlModifier | Qt.Key_X)), ('', keyutils.KeySequence(Qt.MetaModifier | Qt.Key_X)),