diff options
author | Florian Bruhin <me@the-compiler.org> | 2022-04-10 19:01:01 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2022-08-23 18:31:38 +0200 |
commit | 0877fb0d78635692e481c8bde224fac5ad0dd430 (patch) | |
tree | 4ba23ec5a361bbefa09e8b145bf8125d2e3be2e7 /tests/unit/keyinput/test_keyutils.py | |
parent | a11f1d34d3784b170fbc3f5a0e04d5c96ab06b74 (diff) | |
download | qutebrowser-0877fb0d78635692e481c8bde224fac5ad0dd430.tar.gz qutebrowser-0877fb0d78635692e481c8bde224fac5ad0dd430.zip |
Run scripts/dev/rewrite_enums.py
Diffstat (limited to 'tests/unit/keyinput/test_keyutils.py')
-rw-r--r-- | tests/unit/keyinput/test_keyutils.py | 314 |
1 files changed, 157 insertions, 157 deletions
diff --git a/tests/unit/keyinput/test_keyutils.py b/tests/unit/keyinput/test_keyutils.py index 22b4816c2..386811fb8 100644 --- a/tests/unit/keyinput/test_keyutils.py +++ b/tests/unit/keyinput/test_keyutils.py @@ -73,7 +73,7 @@ def test_key_data_modifiers(): mod_names = {name[:-len("Modifier")] for name, value in sorted(vars(Qt).items()) if isinstance(value, Qt.KeyboardModifier) and - value not in [Qt.NoModifier, Qt.KeyboardModifierMask]} + value not in [Qt.KeyboardModifier.NoModifier, Qt.KeyboardModifier.KeyboardModifierMask]} mod_data_names = {mod.attribute for mod in sorted(key_data.MODIFIERS)} diff = mod_names - mod_data_names assert not diff @@ -106,7 +106,7 @@ class TestKeyInfoText: See key_data.py for inputs and expected values. """ - modifiers = Qt.ShiftModifier if upper else Qt.KeyboardModifiers() + modifiers = Qt.KeyboardModifier.ShiftModifier if upper else Qt.KeyboardModifiers() info = keyutils.KeyInfo(qt_key.member, modifiers=modifiers) expected = qt_key.uppertext if upper else qt_key.text assert info.text() == expected @@ -143,45 +143,45 @@ class TestKeyToString: 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' + assert keyutils._key_to_string(Qt.Key.Key_A) == 'A' @pytest.mark.parametrize('key, modifiers, expected', [ - (Qt.Key_A, Qt.NoModifier, 'a'), - (Qt.Key_A, Qt.ShiftModifier, 'A'), - - (Qt.Key_Space, Qt.NoModifier, '<Space>'), - (Qt.Key_Space, Qt.ShiftModifier, '<Shift+Space>'), - (Qt.Key_Tab, Qt.ShiftModifier, '<Shift+Tab>'), - (Qt.Key_A, Qt.ControlModifier, '<Ctrl+a>'), - (Qt.Key_A, Qt.ControlModifier | Qt.ShiftModifier, '<Ctrl+Shift+a>'), - (Qt.Key_A, - Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier | Qt.ShiftModifier, + (Qt.Key.Key_A, Qt.KeyboardModifier.NoModifier, 'a'), + (Qt.Key.Key_A, Qt.KeyboardModifier.ShiftModifier, 'A'), + + (Qt.Key.Key_Space, Qt.KeyboardModifier.NoModifier, '<Space>'), + (Qt.Key.Key_Space, Qt.KeyboardModifier.ShiftModifier, '<Shift+Space>'), + (Qt.Key.Key_Tab, Qt.KeyboardModifier.ShiftModifier, '<Shift+Tab>'), + (Qt.Key.Key_A, Qt.KeyboardModifier.ControlModifier, '<Ctrl+a>'), + (Qt.Key.Key_A, Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.ShiftModifier, '<Ctrl+Shift+a>'), + (Qt.Key.Key_A, + Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.AltModifier | Qt.KeyboardModifier.MetaModifier | Qt.KeyboardModifier.ShiftModifier, '<Meta+Ctrl+Alt+Shift+a>'), - (ord('Œ'), Qt.NoModifier, '<Œ>'), - (ord('Œ'), Qt.ShiftModifier, '<Shift+Œ>'), - (ord('Œ'), Qt.GroupSwitchModifier, '<AltGr+Œ>'), - (ord('Œ'), Qt.GroupSwitchModifier | Qt.ShiftModifier, '<AltGr+Shift+Œ>'), - - (Qt.Key_Shift, Qt.ShiftModifier, '<Shift>'), - (Qt.Key_Shift, Qt.ShiftModifier | Qt.ControlModifier, '<Ctrl+Shift>'), - (Qt.Key_Alt, Qt.AltModifier, '<Alt>'), - (Qt.Key_Shift, Qt.GroupSwitchModifier | Qt.ShiftModifier, '<AltGr+Shift>'), - (Qt.Key_AltGr, Qt.GroupSwitchModifier, '<AltGr>'), + (ord('Œ'), Qt.KeyboardModifier.NoModifier, '<Œ>'), + (ord('Œ'), Qt.KeyboardModifier.ShiftModifier, '<Shift+Œ>'), + (ord('Œ'), Qt.KeyboardModifier.GroupSwitchModifier, '<AltGr+Œ>'), + (ord('Œ'), Qt.KeyboardModifier.GroupSwitchModifier | Qt.KeyboardModifier.ShiftModifier, '<AltGr+Shift+Œ>'), + + (Qt.Key.Key_Shift, Qt.KeyboardModifier.ShiftModifier, '<Shift>'), + (Qt.Key.Key_Shift, Qt.KeyboardModifier.ShiftModifier | Qt.KeyboardModifier.ControlModifier, '<Ctrl+Shift>'), + (Qt.Key.Key_Alt, Qt.KeyboardModifier.AltModifier, '<Alt>'), + (Qt.Key.Key_Shift, Qt.KeyboardModifier.GroupSwitchModifier | Qt.KeyboardModifier.ShiftModifier, '<AltGr+Shift>'), + (Qt.Key.Key_AltGr, Qt.KeyboardModifier.GroupSwitchModifier, '<AltGr>'), ]) def test_key_info_str(key, modifiers, expected): assert str(keyutils.KeyInfo(key, modifiers)) == expected @pytest.mark.parametrize('info1, info2, equal', [ - (keyutils.KeyInfo(Qt.Key_A, Qt.NoModifier), - keyutils.KeyInfo(Qt.Key_A, Qt.NoModifier), + (keyutils.KeyInfo(Qt.Key.Key_A, Qt.KeyboardModifier.NoModifier), + keyutils.KeyInfo(Qt.Key.Key_A, Qt.KeyboardModifier.NoModifier), True), - (keyutils.KeyInfo(Qt.Key_A, Qt.NoModifier), - keyutils.KeyInfo(Qt.Key_B, Qt.NoModifier), + (keyutils.KeyInfo(Qt.Key.Key_A, Qt.KeyboardModifier.NoModifier), + keyutils.KeyInfo(Qt.Key.Key_B, Qt.KeyboardModifier.NoModifier), False), - (keyutils.KeyInfo(Qt.Key_A, Qt.NoModifier), - keyutils.KeyInfo(Qt.Key_B, Qt.ControlModifier), + (keyutils.KeyInfo(Qt.Key.Key_A, Qt.KeyboardModifier.NoModifier), + keyutils.KeyInfo(Qt.Key.Key_B, Qt.KeyboardModifier.ControlModifier), False), ]) def test_hash(info1, info2, equal): @@ -189,9 +189,9 @@ def test_hash(info1, info2, equal): @pytest.mark.parametrize('key, modifiers, text, expected', [ - (0xd83c, Qt.NoModifier, '🏻', '<🏻>'), - (0xd867, Qt.NoModifier, '𩷶', '<𩷶>'), - (0xd867, Qt.ShiftModifier, '𩷶', '<Shift+𩷶>'), + (0xd83c, Qt.KeyboardModifier.NoModifier, '🏻', '<🏻>'), + (0xd867, Qt.KeyboardModifier.NoModifier, '𩷶', '<𩷶>'), + (0xd867, Qt.KeyboardModifier.ShiftModifier, '𩷶', '<Shift+𩷶>'), ]) def test_surrogates(key, modifiers, text, expected): evt = QKeyEvent(QKeyEvent.KeyPress, key, modifiers, text) @@ -201,7 +201,7 @@ def test_surrogates(key, modifiers, text, expected): @pytest.mark.parametrize('keys, expected', [ ([0x1f3fb], '<🏻>'), ([0x29df6], '<𩷶>'), - ([Qt.Key_Shift, 0x29df6], '<Shift><𩷶>'), + ([Qt.Key.Key_Shift, 0x29df6], '<Shift><𩷶>'), ([0x1f468, 0x200d, 0x1f468, 0x200d, 0x1f466], '<👨><><👨><><👦>'), ]) def test_surrogate_sequences(keys, expected): @@ -211,7 +211,7 @@ def test_surrogate_sequences(keys, expected): # This shouldn't happen, but if it does we should handle it well def test_surrogate_error(): - evt = QKeyEvent(QKeyEvent.KeyPress, 0xd83e, Qt.NoModifier, '🤞🏻') + evt = QKeyEvent(QKeyEvent.KeyPress, 0xd83e, Qt.KeyboardModifier.NoModifier, '🤞🏻') with pytest.raises(keyutils.KeyParseError): keyutils.KeyInfo.from_event(evt) @@ -246,8 +246,8 @@ def test_parse_keystr(keystr, parts): class TestKeySequence: def test_init(self): - seq = keyutils.KeySequence(Qt.Key_A, Qt.Key_B, Qt.Key_C, Qt.Key_D, - Qt.Key_E) + seq = keyutils.KeySequence(Qt.Key.Key_A, Qt.Key.Key_B, Qt.Key.Key_C, Qt.Key.Key_D, + Qt.Key.Key_E) assert len(seq._sequences) == 2 assert len(seq._sequences[0]) == 4 assert len(seq._sequences[1]) == 1 @@ -256,7 +256,7 @@ class TestKeySequence: seq = keyutils.KeySequence() assert not seq - @pytest.mark.parametrize('key', [Qt.Key_unknown, -1, 0]) + @pytest.mark.parametrize('key', [Qt.Key.Key_unknown, -1, 0]) def test_init_unknown(self, key): with pytest.raises(keyutils.KeyParseError): keyutils.KeySequence(key) @@ -283,21 +283,21 @@ class TestKeySequence: assert str(keyutils.KeySequence.parse(orig)) == normalized def test_iter(self): - seq = keyutils.KeySequence(Qt.Key_A | Qt.ControlModifier, - Qt.Key_B | Qt.ShiftModifier, - Qt.Key_C, - Qt.Key_D, - Qt.Key_E) - expected = [keyutils.KeyInfo(Qt.Key_A, Qt.ControlModifier), - keyutils.KeyInfo(Qt.Key_B, Qt.ShiftModifier), - keyutils.KeyInfo(Qt.Key_C, Qt.NoModifier), - keyutils.KeyInfo(Qt.Key_D, Qt.NoModifier), - keyutils.KeyInfo(Qt.Key_E, Qt.NoModifier)] + seq = keyutils.KeySequence(Qt.Key.Key_A | Qt.KeyboardModifier.ControlModifier, + Qt.Key.Key_B | Qt.KeyboardModifier.ShiftModifier, + Qt.Key.Key_C, + Qt.Key.Key_D, + Qt.Key.Key_E) + expected = [keyutils.KeyInfo(Qt.Key.Key_A, Qt.KeyboardModifier.ControlModifier), + keyutils.KeyInfo(Qt.Key.Key_B, Qt.KeyboardModifier.ShiftModifier), + keyutils.KeyInfo(Qt.Key.Key_C, Qt.KeyboardModifier.NoModifier), + keyutils.KeyInfo(Qt.Key.Key_D, Qt.KeyboardModifier.NoModifier), + keyutils.KeyInfo(Qt.Key.Key_E, Qt.KeyboardModifier.NoModifier)] assert list(seq) == expected def test_repr(self): - seq = keyutils.KeySequence(Qt.Key_A | Qt.ControlModifier, - Qt.Key_B | Qt.ShiftModifier) + seq = keyutils.KeySequence(Qt.Key.Key_A | Qt.KeyboardModifier.ControlModifier, + Qt.Key.Key_B | Qt.KeyboardModifier.ShiftModifier) assert repr(seq) == ("<qutebrowser.keyinput.keyutils.KeySequence " "keys='<Ctrl+a>B'>") @@ -369,7 +369,7 @@ class TestKeySequence: def test_getitem(self): seq = keyutils.KeySequence.parse('ab') - expected = keyutils.KeyInfo(Qt.Key_B, Qt.NoModifier) + expected = keyutils.KeyInfo(Qt.Key.Key_B, Qt.KeyboardModifier.NoModifier) assert seq[1] == expected def test_getitem_slice(self): @@ -382,27 +382,27 @@ class TestKeySequence: MATCH_TESTS = [ # config: abcd - ('abc', 'abcd', QKeySequence.PartialMatch), - ('abcd', 'abcd', QKeySequence.ExactMatch), - ('ax', 'abcd', QKeySequence.NoMatch), - ('abcdef', 'abcd', QKeySequence.NoMatch), + ('abc', 'abcd', QKeySequence.SequenceMatch.PartialMatch), + ('abcd', 'abcd', QKeySequence.SequenceMatch.ExactMatch), + ('ax', 'abcd', QKeySequence.SequenceMatch.NoMatch), + ('abcdef', 'abcd', QKeySequence.SequenceMatch.NoMatch), # config: abcd ef - ('abc', 'abcdef', QKeySequence.PartialMatch), - ('abcde', 'abcdef', QKeySequence.PartialMatch), - ('abcd', 'abcdef', QKeySequence.PartialMatch), - ('abcdx', 'abcdef', QKeySequence.NoMatch), - ('ax', 'abcdef', QKeySequence.NoMatch), - ('abcdefg', 'abcdef', QKeySequence.NoMatch), - ('abcdef', 'abcdef', QKeySequence.ExactMatch), + ('abc', 'abcdef', QKeySequence.SequenceMatch.PartialMatch), + ('abcde', 'abcdef', QKeySequence.SequenceMatch.PartialMatch), + ('abcd', 'abcdef', QKeySequence.SequenceMatch.PartialMatch), + ('abcdx', 'abcdef', QKeySequence.SequenceMatch.NoMatch), + ('ax', 'abcdef', QKeySequence.SequenceMatch.NoMatch), + ('abcdefg', 'abcdef', QKeySequence.SequenceMatch.NoMatch), + ('abcdef', 'abcdef', QKeySequence.SequenceMatch.ExactMatch), # other examples - ('ab', 'a', QKeySequence.NoMatch), + ('ab', 'a', QKeySequence.SequenceMatch.NoMatch), # empty strings - ('', '', QKeySequence.ExactMatch), - ('', 'a', QKeySequence.PartialMatch), - ('a', '', QKeySequence.NoMatch)] + ('', '', QKeySequence.SequenceMatch.ExactMatch), + ('', 'a', QKeySequence.SequenceMatch.PartialMatch), + ('a', '', QKeySequence.SequenceMatch.NoMatch)] @pytest.mark.parametrize('entered, configured, match_type', MATCH_TESTS) def test_matches(self, entered, configured, match_type): @@ -411,33 +411,33 @@ class TestKeySequence: assert entered.matches(configured) == match_type @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.AltModifier | Qt.ShiftModifier, 'B', + ('a', Qt.Key.Key_B, Qt.KeyboardModifier.NoModifier, 'b', 'ab'), + ('a', Qt.Key.Key_B, Qt.KeyboardModifier.ShiftModifier, 'B', 'aB'), + ('a', Qt.Key.Key_B, Qt.KeyboardModifier.AltModifier | Qt.KeyboardModifier.ShiftModifier, 'B', 'a<Alt+Shift+b>'), # Modifier stripping with symbols - ('', Qt.Key_Colon, Qt.NoModifier, ':', ':'), - ('', Qt.Key_Colon, Qt.ShiftModifier, ':', ':'), - ('', Qt.Key_Colon, Qt.AltModifier | Qt.ShiftModifier, ':', + ('', Qt.Key.Key_Colon, Qt.KeyboardModifier.NoModifier, ':', ':'), + ('', Qt.Key.Key_Colon, Qt.KeyboardModifier.ShiftModifier, ':', ':'), + ('', Qt.Key.Key_Colon, Qt.KeyboardModifier.AltModifier | Qt.KeyboardModifier.ShiftModifier, ':', '<Alt+Shift+:>'), # Swapping Control/Meta on macOS - ('', Qt.Key_A, Qt.ControlModifier, '', + ('', Qt.Key.Key_A, Qt.KeyboardModifier.ControlModifier, '', '<Meta+A>' if utils.is_mac else '<Ctrl+A>'), - ('', Qt.Key_A, Qt.ControlModifier | Qt.ShiftModifier, '', + ('', Qt.Key.Key_A, Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.ShiftModifier, '', '<Meta+Shift+A>' if utils.is_mac else '<Ctrl+Shift+A>'), - ('', Qt.Key_A, Qt.MetaModifier, '', + ('', Qt.Key.Key_A, Qt.KeyboardModifier.MetaModifier, '', '<Ctrl+A>' if utils.is_mac else '<Meta+A>'), # Handling of Backtab - ('', Qt.Key_Backtab, Qt.NoModifier, '', '<Backtab>'), - ('', Qt.Key_Backtab, Qt.ShiftModifier, '', '<Shift+Tab>'), - ('', Qt.Key_Backtab, Qt.AltModifier | Qt.ShiftModifier, '', + ('', Qt.Key.Key_Backtab, Qt.KeyboardModifier.NoModifier, '', '<Backtab>'), + ('', Qt.Key.Key_Backtab, Qt.KeyboardModifier.ShiftModifier, '', '<Shift+Tab>'), + ('', Qt.Key.Key_Backtab, Qt.KeyboardModifier.AltModifier | Qt.KeyboardModifier.ShiftModifier, '', '<Alt+Shift+Tab>'), - # Stripping of Qt.GroupSwitchModifier - ('', Qt.Key_A, Qt.GroupSwitchModifier, 'a', 'a'), + # Stripping of Qt.KeyboardModifier.GroupSwitchModifier + ('', Qt.Key.Key_A, Qt.KeyboardModifier.GroupSwitchModifier, 'a', 'a'), ]) def test_append_event(self, old, key, modifiers, text, expected): seq = keyutils.KeySequence.parse(old) @@ -447,39 +447,39 @@ class TestKeySequence: @pytest.mark.fake_os('mac') @pytest.mark.parametrize('modifiers, expected', [ - (Qt.ControlModifier, - Qt.MetaModifier), - (Qt.MetaModifier, - Qt.ControlModifier), - (Qt.ControlModifier | Qt.MetaModifier, - Qt.ControlModifier | Qt.MetaModifier), - (Qt.ControlModifier | Qt.ShiftModifier, - Qt.MetaModifier | Qt.ShiftModifier), - (Qt.MetaModifier | Qt.ShiftModifier, - Qt.ControlModifier | Qt.ShiftModifier), - (Qt.ShiftModifier, Qt.ShiftModifier), + (Qt.KeyboardModifier.ControlModifier, + Qt.KeyboardModifier.MetaModifier), + (Qt.KeyboardModifier.MetaModifier, + Qt.KeyboardModifier.ControlModifier), + (Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.MetaModifier, + Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.MetaModifier), + (Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.ShiftModifier, + Qt.KeyboardModifier.MetaModifier | Qt.KeyboardModifier.ShiftModifier), + (Qt.KeyboardModifier.MetaModifier | Qt.KeyboardModifier.ShiftModifier, + Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.ShiftModifier), + (Qt.KeyboardModifier.ShiftModifier, Qt.KeyboardModifier.ShiftModifier), ]) def test_fake_mac(self, modifiers, expected): """Make sure Control/Meta are swapped with a simulated Mac.""" seq = keyutils.KeySequence() - info = keyutils.KeyInfo(key=Qt.Key_A, modifiers=modifiers) + info = keyutils.KeyInfo(key=Qt.Key.Key_A, modifiers=modifiers) new = seq.append_event(info.to_event()) - assert new[0] == keyutils.KeyInfo(Qt.Key_A, expected) + assert new[0] == keyutils.KeyInfo(Qt.Key.Key_A, expected) - @pytest.mark.parametrize('key', [Qt.Key_unknown, 0x0]) + @pytest.mark.parametrize('key', [Qt.Key.Key_unknown, 0x0]) def test_append_event_invalid(self, key): seq = keyutils.KeySequence() - event = QKeyEvent(QKeyEvent.KeyPress, key, Qt.NoModifier, '') + event = QKeyEvent(QKeyEvent.KeyPress, key, Qt.KeyboardModifier.NoModifier, '') with pytest.raises(keyutils.KeyParseError): seq.append_event(event) def test_strip_modifiers(self): - seq = keyutils.KeySequence(Qt.Key_0, - Qt.Key_1 | Qt.KeypadModifier, - Qt.Key_A | Qt.ControlModifier) - expected = keyutils.KeySequence(Qt.Key_0, - Qt.Key_1, - Qt.Key_A | Qt.ControlModifier) + seq = keyutils.KeySequence(Qt.Key.Key_0, + Qt.Key.Key_1 | Qt.KeyboardModifier.KeypadModifier, + Qt.Key.Key_A | Qt.KeyboardModifier.ControlModifier) + expected = keyutils.KeySequence(Qt.Key.Key_0, + Qt.Key.Key_1, + Qt.Key.Key_A | Qt.KeyboardModifier.ControlModifier) assert seq.strip_modifiers() == expected @pytest.mark.parametrize('inp, mappings, expected', [ @@ -497,31 +497,31 @@ class TestKeySequence: @pytest.mark.parametrize('keystr, expected', [ ('<Ctrl-Alt-y>', - keyutils.KeySequence(Qt.ControlModifier | Qt.AltModifier | Qt.Key_Y)), - ('x', keyutils.KeySequence(Qt.Key_X)), - ('X', keyutils.KeySequence(Qt.ShiftModifier | Qt.Key_X)), - ('<Escape>', keyutils.KeySequence(Qt.Key_Escape)), - ('xyz', keyutils.KeySequence(Qt.Key_X, Qt.Key_Y, Qt.Key_Z)), + keyutils.KeySequence(Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.AltModifier | Qt.Key.Key_Y)), + ('x', keyutils.KeySequence(Qt.Key.Key_X)), + ('X', keyutils.KeySequence(Qt.KeyboardModifier.ShiftModifier | Qt.Key.Key_X)), + ('<Escape>', keyutils.KeySequence(Qt.Key.Key_Escape)), + ('xyz', keyutils.KeySequence(Qt.Key.Key_X, Qt.Key.Key_Y, Qt.Key.Key_Z)), ('<Control-x><Meta-y>', - keyutils.KeySequence(Qt.ControlModifier | Qt.Key_X, - Qt.MetaModifier | Qt.Key_Y)), - - ('<Shift-x>', keyutils.KeySequence(Qt.ShiftModifier | Qt.Key_X)), - ('<Alt-x>', keyutils.KeySequence(Qt.AltModifier | Qt.Key_X)), - ('<Control-x>', keyutils.KeySequence(Qt.ControlModifier | Qt.Key_X)), - ('<Meta-x>', keyutils.KeySequence(Qt.MetaModifier | Qt.Key_X)), - ('<Num-x>', keyutils.KeySequence(Qt.KeypadModifier | Qt.Key_X)), - - ('>', keyutils.KeySequence(Qt.Key_Greater)), - ('<', keyutils.KeySequence(Qt.Key_Less)), - ('a>', keyutils.KeySequence(Qt.Key_A, Qt.Key_Greater)), - ('a<', keyutils.KeySequence(Qt.Key_A, Qt.Key_Less)), - ('>a', keyutils.KeySequence(Qt.Key_Greater, Qt.Key_A)), - ('<a', keyutils.KeySequence(Qt.Key_Less, Qt.Key_A)), + keyutils.KeySequence(Qt.KeyboardModifier.ControlModifier | Qt.Key.Key_X, + Qt.KeyboardModifier.MetaModifier | Qt.Key.Key_Y)), + + ('<Shift-x>', keyutils.KeySequence(Qt.KeyboardModifier.ShiftModifier | Qt.Key.Key_X)), + ('<Alt-x>', keyutils.KeySequence(Qt.KeyboardModifier.AltModifier | Qt.Key.Key_X)), + ('<Control-x>', keyutils.KeySequence(Qt.KeyboardModifier.ControlModifier | Qt.Key.Key_X)), + ('<Meta-x>', keyutils.KeySequence(Qt.KeyboardModifier.MetaModifier | Qt.Key.Key_X)), + ('<Num-x>', keyutils.KeySequence(Qt.KeyboardModifier.KeypadModifier | Qt.Key.Key_X)), + + ('>', keyutils.KeySequence(Qt.Key.Key_Greater)), + ('<', keyutils.KeySequence(Qt.Key.Key_Less)), + ('a>', keyutils.KeySequence(Qt.Key.Key_A, Qt.Key.Key_Greater)), + ('a<', keyutils.KeySequence(Qt.Key.Key_A, Qt.Key.Key_Less)), + ('>a', keyutils.KeySequence(Qt.Key.Key_Greater, Qt.Key.Key_A)), + ('<a', keyutils.KeySequence(Qt.Key.Key_Less, Qt.Key.Key_A)), ('<alt+greater>', - keyutils.KeySequence(Qt.Key_Greater | Qt.AltModifier)), + keyutils.KeySequence(Qt.Key.Key_Greater | Qt.KeyboardModifier.AltModifier)), ('<alt+less>', - keyutils.KeySequence(Qt.Key_Less | Qt.AltModifier)), + keyutils.KeySequence(Qt.Key.Key_Less | Qt.KeyboardModifier.AltModifier)), ('<alt+<>', keyutils.KeyParseError), ('<alt+>>', keyutils.KeyParseError), @@ -547,66 +547,66 @@ class TestKeySequence: def test_key_info_from_event(): - ev = QKeyEvent(QEvent.KeyPress, Qt.Key_A, Qt.ShiftModifier, 'A') + ev = QKeyEvent(QEvent.Type.KeyPress, Qt.Key.Key_A, Qt.KeyboardModifier.ShiftModifier, 'A') info = keyutils.KeyInfo.from_event(ev) - assert info.key == Qt.Key_A - assert info.modifiers == Qt.ShiftModifier + assert info.key == Qt.Key.Key_A + assert info.modifiers == Qt.KeyboardModifier.ShiftModifier def test_key_info_to_event(): - info = keyutils.KeyInfo(Qt.Key_A, Qt.ShiftModifier) + info = keyutils.KeyInfo(Qt.Key.Key_A, Qt.KeyboardModifier.ShiftModifier) ev = info.to_event() - assert ev.key() == Qt.Key_A - assert ev.modifiers() == Qt.ShiftModifier + assert ev.key() == Qt.Key.Key_A + assert ev.modifiers() == Qt.KeyboardModifier.ShiftModifier assert ev.text() == 'A' def test_key_info_to_int(): - info = keyutils.KeyInfo(Qt.Key_A, Qt.ShiftModifier) - assert info.to_int() == Qt.Key_A | Qt.ShiftModifier + info = keyutils.KeyInfo(Qt.Key.Key_A, Qt.KeyboardModifier.ShiftModifier) + assert info.to_int() == Qt.Key.Key_A | Qt.KeyboardModifier.ShiftModifier @pytest.mark.parametrize('key, printable', [ - (Qt.Key_Control, False), - (Qt.Key_Escape, False), - (Qt.Key_Tab, False), - (Qt.Key_Backtab, False), - (Qt.Key_Backspace, False), - (Qt.Key_Return, False), - (Qt.Key_Enter, False), - (Qt.Key_Space, False), + (Qt.Key.Key_Control, False), + (Qt.Key.Key_Escape, False), + (Qt.Key.Key_Tab, False), + (Qt.Key.Key_Backtab, False), + (Qt.Key.Key_Backspace, False), + (Qt.Key.Key_Return, False), + (Qt.Key.Key_Enter, False), + (Qt.Key.Key_Space, False), (0x0, False), # Used by Qt for unknown keys - (Qt.Key_ydiaeresis, True), - (Qt.Key_X, True), + (Qt.Key.Key_ydiaeresis, True), + (Qt.Key.Key_X, True), ]) def test_is_printable(key, printable): assert keyutils._is_printable(key) == printable - assert keyutils.is_special(key, Qt.NoModifier) != printable + assert keyutils.is_special(key, Qt.KeyboardModifier.NoModifier) != printable @pytest.mark.parametrize('key, modifiers, special', [ - (Qt.Key_Escape, Qt.NoModifier, True), - (Qt.Key_Escape, Qt.ShiftModifier, True), - (Qt.Key_Escape, Qt.ControlModifier, True), - (Qt.Key_X, Qt.ControlModifier, True), - (Qt.Key_X, Qt.NoModifier, False), - (Qt.Key_2, Qt.KeypadModifier, True), - (Qt.Key_2, Qt.NoModifier, False), - (Qt.Key_Shift, Qt.ShiftModifier, True), - (Qt.Key_Control, Qt.ControlModifier, True), - (Qt.Key_Alt, Qt.AltModifier, True), - (Qt.Key_Meta, Qt.MetaModifier, True), - (Qt.Key_Mode_switch, Qt.GroupSwitchModifier, True), + (Qt.Key.Key_Escape, Qt.KeyboardModifier.NoModifier, True), + (Qt.Key.Key_Escape, Qt.KeyboardModifier.ShiftModifier, True), + (Qt.Key.Key_Escape, Qt.KeyboardModifier.ControlModifier, True), + (Qt.Key.Key_X, Qt.KeyboardModifier.ControlModifier, True), + (Qt.Key.Key_X, Qt.KeyboardModifier.NoModifier, False), + (Qt.Key.Key_2, Qt.KeyboardModifier.KeypadModifier, True), + (Qt.Key.Key_2, Qt.KeyboardModifier.NoModifier, False), + (Qt.Key.Key_Shift, Qt.KeyboardModifier.ShiftModifier, True), + (Qt.Key.Key_Control, Qt.KeyboardModifier.ControlModifier, True), + (Qt.Key.Key_Alt, Qt.KeyboardModifier.AltModifier, True), + (Qt.Key.Key_Meta, Qt.KeyboardModifier.MetaModifier, True), + (Qt.Key.Key_Mode_switch, Qt.KeyboardModifier.GroupSwitchModifier, True), ]) def test_is_special(key, modifiers, special): assert keyutils.is_special(key, modifiers) == special @pytest.mark.parametrize('key, ismodifier', [ - (Qt.Key_Control, True), - (Qt.Key_X, False), - (Qt.Key_Super_L, False), # Modifier but not in _MODIFIER_MAP + (Qt.Key.Key_Control, True), + (Qt.Key.Key_X, False), + (Qt.Key.Key_Super_L, False), # Modifier but not in _MODIFIER_MAP ]) def test_is_modifier_key(key, ismodifier): assert keyutils.is_modifier_key(key) == ismodifier @@ -622,4 +622,4 @@ def test_is_modifier_key(key, ismodifier): ]) def test_non_plain(func): with pytest.raises(AssertionError): - func(Qt.Key_X | Qt.ControlModifier) + func(Qt.Key.Key_X | Qt.KeyboardModifier.ControlModifier) |