From fb7c75a09092c5f7980f01d2af97f5a8c0030abe Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 3 Mar 2018 23:29:16 +0100 Subject: [PATCH] Improve keyutils tests --- qutebrowser/keyinput/keyutils.py | 3 +-- tests/unit/keyinput/test_keyutils.py | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/qutebrowser/keyinput/keyutils.py b/qutebrowser/keyinput/keyutils.py index 1741fbe33..6dbebfef0 100644 --- a/qutebrowser/keyinput/keyutils.py +++ b/qutebrowser/keyinput/keyutils.py @@ -157,8 +157,7 @@ def _parse_keystring(keystr): special = False else: yield '>' - for c in key: - yield 'Shift+' + c if c.isupper() else c + assert not key, key elif c == '<': special = True elif special: diff --git a/tests/unit/keyinput/test_keyutils.py b/tests/unit/keyinput/test_keyutils.py index f8b8382cd..b9d770c5c 100644 --- a/tests/unit/keyinput/test_keyutils.py +++ b/tests/unit/keyinput/test_keyutils.py @@ -18,7 +18,8 @@ # along with qutebrowser. If not, see . import pytest -from PyQt5.QtCore import Qt, pyqtSignal +from PyQt5.QtCore import Qt, QEvent, pyqtSignal +from PyQt5.QtGui import QKeyEvent from PyQt5.QtWidgets import QWidget from tests.unit.keyinput import key_data @@ -112,7 +113,7 @@ class TestKeyToString: assert keyutils._key_to_string(qt_key.member) == qt_key.name def test_missing(self, monkeypatch): - monkeypatch.delattr(keyutils.Qt, 'Key_Blue') + monkeypatch.delattr(keyutils.Qt, 'Key_AltGr') # We don't want to test the key which is actually missing - we only # want to know if the mapping still behaves properly. assert keyutils._key_to_string(Qt.Key_A) == 'A' @@ -199,6 +200,21 @@ def test_normalize_keystr(orig, normalized): assert str(keyutils.KeySequence.parse(orig)) == normalized +def test_key_info_from_event(): + ev = QKeyEvent(QEvent.KeyPress, Qt.Key_A, Qt.ShiftModifier, 'A') + info = keyutils.KeyInfo.from_event(ev) + assert info.key == Qt.Key_A + assert info.modifiers == Qt.ShiftModifier + + +def test_key_info_to_event(): + info = keyutils.KeyInfo(Qt.Key_A, Qt.ShiftModifier) + ev = info.to_event() + assert ev.key() == Qt.Key_A + assert ev.modifiers() == Qt.ShiftModifier + assert ev.text() == 'A' + + @pytest.mark.parametrize('key, printable', [ (Qt.Key_Control, False), (Qt.Key_Escape, False),