Esempio n. 1
0
 def test_valid_key_count(self, prompt_keyparser):
     infos = [
         keyutils.KeyInfo(Qt.Key_5, Qt.NoModifier),
         keyutils.KeyInfo(Qt.Key_A, Qt.ControlModifier),
     ]
     for info in infos:
         prompt_keyparser.handle(info.to_event())
     prompt_keyparser.execute.assert_called_once_with(
         'message-info ctrla', 5)
    def test_dry_run(self, prompt_keyparser):
        b_info = keyutils.KeyInfo(Qt.Key_B, Qt.NoModifier)
        prompt_keyparser.handle(b_info.to_event())

        a_info = keyutils.KeyInfo(Qt.Key_A, Qt.NoModifier)
        prompt_keyparser.handle(a_info.to_event(), dry_run=True)

        assert not prompt_keyparser.execute.called
        assert prompt_keyparser._sequence
Esempio n. 3
0
    def test_valid_key(self, prompt_keyparser, handle_text):
        infos = [
            keyutils.KeyInfo(Qt.Key_A, Qt.ControlModifier),
            keyutils.KeyInfo(Qt.Key_X, Qt.ControlModifier),
        ]
        for info in infos:
            prompt_keyparser.handle(info.to_event())

        prompt_keyparser.execute.assert_called_once_with(
            'message-info ctrla', None)
        assert not prompt_keyparser._sequence
Esempio n. 4
0
 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)]
     assert list(seq) == expected
    def test_mapping_keypad(self, config_stub, keyparser):
        """Make sure falling back to non-numpad keys works with mappings."""
        config_stub.val.bindings.commands = {'normal': {'a': 'nop'}}
        config_stub.val.bindings.key_mappings = {'1': 'a'}

        info = keyutils.KeyInfo(Qt.Key_1, Qt.KeypadModifier)
        keyparser.handle(info.to_event())
        keyparser.execute.assert_called_once_with('nop', None)
Esempio n. 6
0
    def test_text(self, qt_key, upper):
        """Test KeyInfo.text() with all possible keys.

        See key_data.py for inputs and expected values.
        """
        modifiers = Qt.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
 def test_numpad(self, prompt_keyparser):
     """Make sure we can enter a count via numpad."""
     for key, modifiers in [(Qt.Key_4, Qt.KeypadModifier),
                            (Qt.Key_2, Qt.KeypadModifier),
                            (Qt.Key_B, Qt.NoModifier),
                            (Qt.Key_A, Qt.NoModifier)]:
         info = keyutils.KeyInfo(key, modifiers)
         prompt_keyparser.handle(info.to_event())
     prompt_keyparser.execute.assert_called_once_with('message-info ba', 42)
Esempio n. 8
0
def test_respect_config_when_matching_counts(keyparser, config_stub):
    """Don't match counts if disabled in the config."""
    config_stub.val.input.match_counts = False

    info = keyutils.KeyInfo(Qt.Key_1, Qt.NoModifier)
    keyparser.handle(info.to_event())

    assert not keyparser._sequence
    assert not keyparser._count
    def test_binding_with_shift(self, prompt_keyparser):
        """Simulate a binding which involves shift."""
        for key, modifiers in [(Qt.Key_Y, Qt.NoModifier),
                               (Qt.Key_Shift, Qt.ShiftModifier),
                               (Qt.Key_Y, Qt.ShiftModifier)]:
            info = keyutils.KeyInfo(key, modifiers)
            prompt_keyparser.handle(info.to_event())

        prompt_keyparser.execute.assert_called_once_with('yank -s', None)
Esempio n. 10
0
 def test_number_press_keypad(self, keyparser, config_stub,
                              modifiers, text):
     """Make sure a <Num+2> binding overrides the 2 binding."""
     config_stub.val.bindings.commands = {'normal': {
         '2': 'message-info 2',
         '<Num+2>': 'message-info num-2'}}
     keyparser.handle(keyutils.KeyInfo(Qt.Key_2, modifiers).to_event())
     command = 'message-info {}'.format(text)
     keyparser.execute.assert_called_once_with(command, None)
     assert not keyparser._sequence
Esempio n. 11
0
 def test_partial_before_full_match(self, keyparser, config_stub):
     """Make sure full matches always take precedence over partial ones."""
     config_stub.val.bindings.commands = {
         'normal': {
             'ab': 'message-info bar',
             'a': 'message-info foo'
         }
     }
     info = keyutils.KeyInfo(Qt.Key_A, Qt.NoModifier)
     keyparser.handle(info.to_event())
     keyparser.execute.assert_called_once_with('message-info foo', None)
Esempio n. 12
0
    def test_text_qtest(self, qtest_key, qtbot, key_tester):
        """Make sure KeyInfo.text() lines up with QTest::keyToAscii.

        See key_data.py for inputs and expected values.
        """
        with qtbot.wait_signal(key_tester.got_text):
            qtbot.keyPress(key_tester, qtest_key.member)

        info = keyutils.KeyInfo(qtest_key.member,
                                modifiers=Qt.KeyboardModifiers())
        assert info.text() == key_tester.text.lower()
Esempio n. 13
0
    def test_command(self, keyparser, config_stub, hintmanager, commandrunner):
        config_stub.val.bindings.commands = {
            'hint': {'abc': 'message-info abc'}
        }

        keyparser.update_bindings(['xabcy'])

        steps = [
            (Qt.Key_X, QKeySequence.PartialMatch, 'x'),
            (Qt.Key_A, QKeySequence.PartialMatch, ''),
            (Qt.Key_B, QKeySequence.PartialMatch, ''),
            (Qt.Key_C, QKeySequence.ExactMatch, ''),
        ]
        for key, expected_match, keystr in steps:
            info = keyutils.KeyInfo(key, Qt.NoModifier)
            match = keyparser.handle(info.to_event())
            assert match == expected_match
            assert hintmanager.keystr == keystr
            if key != Qt.Key_C:
                assert not commandrunner.commands

        assert commandrunner.commands == [('message-info abc', None)]
Esempio n. 14
0
    def test_partial_keychain_timeout(self, keyparser, config_stub,
                                      qtbot, commandrunner):
        """Test partial keychain timeout."""
        config_stub.val.input.partial_timeout = 100
        timer = keyparser._partial_timer
        assert not timer.isActive()

        # Press 'b' for a partial match.
        # Then we check if the timer has been set up correctly
        keyparser.handle(keyutils.KeyInfo(Qt.Key_B, Qt.NoModifier).to_event())
        assert timer.isSingleShot()
        assert timer.interval() == 100
        assert timer.isActive()

        assert not commandrunner.commands
        assert keyparser._sequence == keyutils.KeySequence.parse('b')

        # Now simulate a timeout and check the keystring has been cleared.
        with qtbot.wait_signal(keyparser.keystring_updated) as blocker:
            timer.timeout.emit()

        assert not commandrunner.commands
        assert not keyparser._sequence
        assert blocker.args == ['']
Esempio n. 15
0
 def test_fake_mac(self, fake_keyevent, modifiers, expected):
     """Make sure Control/Meta are swapped with a simulated Mac."""
     seq = keyutils.KeySequence()
     event = fake_keyevent(key=Qt.Key_A, modifiers=modifiers)
     new = seq.append_event(event)
     assert new[0] == keyutils.KeyInfo(Qt.Key_A, expected)
Esempio n. 16
0
 def func(kp, *args):
     for key in args:
         info = keyutils.KeyInfo(key, Qt.NoModifier)
         kp.handle(info.to_event())
Esempio n. 17
0
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'
Esempio n. 18
0
 def test_invalid_keys(self, prompt_keyparser, keys):
     for key, modifiers in keys:
         info = keyutils.KeyInfo(key, modifiers)
         prompt_keyparser.handle(info.to_event())
     assert not prompt_keyparser.execute.called
     assert not prompt_keyparser._sequence
Esempio n. 19
0
    (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>'),
])
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), True),
    (keyutils.KeyInfo(Qt.Key_A, Qt.NoModifier),
     keyutils.KeyInfo(Qt.Key_B, Qt.NoModifier), False),
    (keyutils.KeyInfo(Qt.Key_A, Qt.NoModifier),
     keyutils.KeyInfo(Qt.Key_B, Qt.ControlModifier), False),
])
def test_hash(info1, info2, equal):
    assert (hash(info1) == hash(info2)) == equal


@pytest.mark.parametrize('key, modifiers, text, expected', [
    (0xd83c, Qt.NoModifier, '🏻', '<🏻>'),
    (0xd867, Qt.NoModifier, '𩷶', '<𩷶>'),
    (0xd867, Qt.ShiftModifier, '𩷶', '<Shift+𩷶>'),
])
Esempio n. 20
0
def test_non_alphanumeric(key, modifiers, filtered, modeman):
    """Make sure non-alphanumeric keys are passed through correctly."""
    evt = keyutils.KeyInfo(key=key, modifiers=modifiers).to_event()
    assert modeman.handle_event(evt) == filtered
Esempio n. 21
0
 def func(key, modifiers=Qt.NoModifier, typ=QEvent.KeyPress):
     """Generate a new fake QKeyPressEvent."""
     text = keyutils.KeyInfo(key, modifiers).text()
     return QKeyEvent(QKeyEvent.KeyPress, key, modifiers, text)
Esempio n. 22
0
def test_key_info_str(key, modifiers, expected):
    assert str(keyutils.KeyInfo(key, modifiers)) == expected
Esempio n. 23
0
 def test_dry_run_count(self, prompt_keyparser):
     info = keyutils.KeyInfo(Qt.Key_9, Qt.NoModifier)
     prompt_keyparser.handle(info.to_event(), dry_run=True)
     assert not prompt_keyparser._count
Esempio n. 24
0
 def test_getitem(self):
     seq = keyutils.KeySequence.parse('ab')
     expected = keyutils.KeyInfo(Qt.Key_B, Qt.NoModifier)
     assert seq[1] == expected
Esempio n. 25
0
 def test_invalid_key(self, prompt_keyparser):
     keys = [Qt.Key_B, 0x0]
     for key in keys:
         info = keyutils.KeyInfo(key, Qt.NoModifier)
         prompt_keyparser.handle(info.to_event())
     assert not prompt_keyparser._sequence
Esempio n. 26
0
def test_key_info_to_int():
    info = keyutils.KeyInfo(Qt.Key_A, Qt.ShiftModifier)
    assert info.to_int() == Qt.Key_A | Qt.ShiftModifier
Esempio n. 27
0
 def test_number_press(self, prompt_keyparser, key, modifiers, number):
     prompt_keyparser.handle(keyutils.KeyInfo(key, modifiers).to_event())
     command = 'message-info {}'.format(number)
     prompt_keyparser.execute.assert_called_once_with(command, None)
     assert not prompt_keyparser._sequence