def test_count_0(self):
     """Test with count=0."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_0, text='0'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='b'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='a'))
     self.kp.execute.assert_called_once_with('ba', self.kp.Type.chain, 0)
     self.assertEqual(self.kp._keystring, '')
Beispiel #2
0
 def test_count_0(self):
     """Test with count=0."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_0, text='0'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='b'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='a'))
     self.kp.execute.assert_called_once_with('ba', self.kp.Type.chain, 0)
     self.assertEqual(self.kp._keystring, '')
 def test_keychain(self):
     """Test valid keychain."""
     # Press 'x' which is ignored because of no match
     self.kp.handle(helpers.fake_keyevent(Qt.Key_X, text='x'))
     # Then start the real chain
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='b'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='a'))
     self.kp.execute.assert_called_once_with('ba', self.kp.Type.chain, None)
     self.assertEqual(self.kp._keystring, '')
Beispiel #4
0
 def test_keychain(self):
     """Test valid keychain."""
     # Press 'x' which is ignored because of no match
     self.kp.handle(helpers.fake_keyevent(Qt.Key_X, text='x'))
     # Then start the real chain
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='b'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='a'))
     self.kp.execute.assert_called_once_with('ba', self.kp.Type.chain, None)
     self.assertEqual(self.kp._keystring, '')
Beispiel #5
0
 def test_invalid_special_key(self):
     """Test invalid special key."""
     self.kp.handle(
         helpers.fake_keyevent(Qt.Key_A,
                               (Qt.ControlModifier | Qt.AltModifier)))
     self.assertFalse(self.kp.execute.called)
     self.assertEqual(self.kp._keystring, '')
Beispiel #6
0
 def test_ambiguous_keychain(self):
     """Test ambiguous keychain."""
     timer = self.kp._ambiguous_timer
     self.assertFalse(timer.isActive())
     # We start with 'a' where the keychain gives us an ambiguous result.
     # Then we check if the timer has been set up correctly
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='a'))
     self.assertFalse(self.kp.execute.called)
     self.assertTrue(timer.isSingleShot())
     self.assertEqual(timer.interval(), 100)
     self.assertTrue(timer.isActive())
     # Now we type an 'x' and check 'ax' has been executed and the timer
     # stopped.
     self.kp.handle(helpers.fake_keyevent(Qt.Key_X, text='x'))
     self.kp.execute.assert_called_once_with('ax', self.kp.Type.chain, None)
     self.assertFalse(timer.isActive())
     self.assertEqual(self.kp._keystring, '')
Beispiel #7
0
 def test_count_42_invalid(self):
     """Test with count=42 and invalid command."""
     # Invalid call with ccx gets ignored
     self.kp.handle(helpers.fake_keyevent(Qt.Key_4, text='4'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_2, text='2'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='c'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='c'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='x'))
     self.assertFalse(self.kp.execute.called)
     self.assertEqual(self.kp._keystring, '')
     # Valid call with ccc gets the correct count
     self.kp.handle(helpers.fake_keyevent(Qt.Key_4, text='2'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_2, text='3'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='c'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='c'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='c'))
     self.kp.execute.assert_called_once_with('ccc', self.kp.Type.chain, 23)
     self.assertEqual(self.kp._keystring, '')
 def test_count_42_invalid(self):
     """Test with count=42 and invalid command."""
     # Invalid call with ccx gets ignored
     self.kp.handle(helpers.fake_keyevent(Qt.Key_4, text='4'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_2, text='2'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='c'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='c'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='x'))
     self.assertFalse(self.kp.execute.called)
     self.assertEqual(self.kp._keystring, '')
     # Valid call with ccc gets the correct count
     self.kp.handle(helpers.fake_keyevent(Qt.Key_4, text='2'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_2, text='3'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='c'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='c'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='c'))
     self.kp.execute.assert_called_once_with('ccc', self.kp.Type.chain, 23)
     self.assertEqual(self.kp._keystring, '')
Beispiel #9
0
 def test_ambigious_keychain(self):
     """Test ambigious keychain."""
     basekeyparser.config = stubs.ConfigStub(CONFIG)
     # We start with 'a' where the keychain gives us an ambigious result.
     # Then we check if the timer has been set up correctly
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='a'))
     self.assertFalse(self.kp.execute.called)
     basekeyparser.usertypes.Timer.assert_called_once_with(
         self.kp, 'ambigious_match')
     self.timermock.setSingleShot.assert_called_once_with(True)
     self.timermock.setInterval.assert_called_once_with(100)
     self.assertTrue(self.timermock.timeout.connect.called)
     self.assertFalse(self.timermock.stop.called)
     self.timermock.start.assert_called_once_with()
     # Now we type an 'x' and check 'ax' has been executed and the timer
     # stopped.
     self.kp.handle(helpers.fake_keyevent(Qt.Key_X, text='x'))
     self.kp.execute.assert_called_once_with('ax', self.kp.Type.chain, None)
     self.timermock.stop.assert_called_once_with()
     self.assertEqual(self.kp._keystring, '')
Beispiel #10
0
 def test_key_and_modifiers(self):
     """Test with key and multiple modifier pressed."""
     evt = helpers.fake_keyevent(
         key=Qt.Key_A, modifiers=(Qt.ControlModifier | Qt.AltModifier |
                                  Qt.MetaModifier | Qt.ShiftModifier))
     if sys.platform == 'darwin':
         self.assertEqual(utils.keyevent_to_string(evt),
                          'Ctrl+Alt+Shift+A')
     else:
         self.assertEqual(utils.keyevent_to_string(evt),
                          'Ctrl+Alt+Meta+Shift+A')
Beispiel #11
0
 def test_key_and_modifiers(self):
     """Test with key and multiple modifier pressed."""
     evt = helpers.fake_keyevent(
         key=Qt.Key_A,
         modifiers=(Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier
                    | Qt.ShiftModifier))
     if sys.platform == 'darwin':
         self.assertEqual(utils.keyevent_to_string(evt), 'Ctrl+Alt+Shift+A')
     else:
         self.assertEqual(utils.keyevent_to_string(evt),
                          'Ctrl+Alt+Meta+Shift+A')
 def test_ambigious_keychain(self):
     """Test ambigious keychain."""
     basekeyparser.config = stubs.ConfigStub(CONFIG)
     # We start with 'a' where the keychain gives us an ambigious result.
     # Then we check if the timer has been set up correctly
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='a'))
     self.assertFalse(self.kp.execute.called)
     basekeyparser.usertypes.Timer.assert_called_once_with(
         self.kp, 'ambigious_match')
     self.timermock.setSingleShot.assert_called_once_with(True)
     self.timermock.setInterval.assert_called_once_with(100)
     self.assertTrue(self.timermock.timeout.connect.called)
     self.assertFalse(self.timermock.stop.called)
     self.timermock.start.assert_called_once_with()
     # Now we type an 'x' and check 'ax' has been executed and the timer
     # stopped.
     self.kp.handle(helpers.fake_keyevent(Qt.Key_X, text='x'))
     self.kp.execute.assert_called_once_with('ax', self.kp.Type.chain, None)
     self.timermock.stop.assert_called_once_with()
     self.assertEqual(self.kp._keystring, '')
Beispiel #13
0
    def test_partial_keychain_timeout(self):
        """Test partial keychain timeout."""
        timer = self.kp._partial_timer
        self.assertFalse(timer.isActive())
        # Press 'b' for a partial match.
        # Then we check if the timer has been set up correctly
        self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='b'))
        self.assertTrue(timer.isSingleShot())
        self.assertEqual(timer.interval(), 100)
        self.assertTrue(timer.isActive())

        self.assertFalse(self.kp.execute.called)
        self.assertEqual(self.kp._keystring, 'b')
        # Now simulate a timeout and check the keystring has been cleared.
        keystring_updated_mock = mock.Mock()
        self.kp.keystring_updated.connect(keystring_updated_mock)
        timer.timeout.emit()
        self.assertFalse(self.kp.execute.called)
        self.assertEqual(self.kp._keystring, '')
        keystring_updated_mock.assert_called_once_with('')
Beispiel #14
0
 def test_valid_special_key(self):
     """Test valid special key."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, Qt.ControlModifier))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_X, Qt.ControlModifier))
     self.kp.execute.assert_called_once_with('ctrla', self.kp.Type.special)
     self.assertEqual(self.kp._keystring, '')
 def test_no_count(self):
     """Test with no count added."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='b'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='a'))
     self.kp.execute.assert_called_once_with('ba', self.kp.Type.chain, None)
     self.assertEqual(self.kp._keystring, '')
 def test_invalid_keychain(self):
     """Test invalid keychain."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='b'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_C, text='c'))
     self.assertEqual(self.kp._keystring, '')
Beispiel #17
0
 def test_only_control(self):
     """Test keyeevent when only control is pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_Control,
                                 modifiers=Qt.ControlModifier)
     self.assertIsNone(utils.keyevent_to_string(evt))
Beispiel #18
0
 def test_key_and_modifier(self):
     """Test with key and modifier pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_A, modifiers=Qt.ControlModifier)
     self.assertEqual(utils.keyevent_to_string(evt), 'Ctrl+A')
Beispiel #19
0
 def test_only_hyper_l(self):
     """Test keyeevent when only Hyper_L is pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_Hyper_L,
                                 modifiers=Qt.MetaModifier)
     self.assertIsNone(utils.keyevent_to_string(evt))
 def test_keychain(self):
     """Test a keychain."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A))
     self.assertFalse(self.kp.execute.called)
 def test_invalid_key(self):
     """Test an invalid special keyevent."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, (Qt.ControlModifier |
                                                     Qt.AltModifier)))
     self.assertFalse(self.kp.execute.called)
Beispiel #22
0
 def test_invalid_key(self):
     """Test an invalid special keyevent."""
     self.kp.handle(
         helpers.fake_keyevent(Qt.Key_A,
                               (Qt.ControlModifier | Qt.AltModifier)))
     self.assertFalse(self.kp.execute.called)
Beispiel #23
0
 def test_key_and_modifier(self):
     """Test with key and modifier pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_A, modifiers=Qt.ControlModifier)
     self.assertEqual(utils.keyevent_to_string(evt), 'Ctrl+A')
Beispiel #24
0
 def test_only_key(self):
     """Test with a simple key pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_A)
     self.assertEqual(utils.keyevent_to_string(evt), 'A')
Beispiel #25
0
 def test_only_hyper_l(self):
     """Test keyeevent when only Hyper_L is pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_Hyper_L,
                                 modifiers=Qt.MetaModifier)
     self.assertIsNone(utils.keyevent_to_string(evt))
Beispiel #26
0
 def test_keychain(self):
     """Test a keychain."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A))
     self.assertFalse(self.kp.execute.called)
Beispiel #27
0
 def test_only_control(self):
     """Test keyeevent when only control is pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_Control,
                                 modifiers=Qt.ControlModifier)
     self.assertIsNone(utils.keyevent_to_string(evt))
 def test_valid_special_key(self):
     """Test valid special key."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, Qt.ControlModifier))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_X, Qt.ControlModifier))
     self.kp.execute.assert_called_once_with('ctrla', self.kp.Type.special)
     self.assertEqual(self.kp._keystring, '')
Beispiel #29
0
 def test_only_key(self):
     """Test with a simple key pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_A)
     self.assertEqual(utils.keyevent_to_string(evt), 'A')
 def test_invalid_special_key(self):
     """Test invalid special key."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, (Qt.ControlModifier |
                                                     Qt.AltModifier)))
     self.assertFalse(self.kp.execute.called)
     self.assertEqual(self.kp._keystring, '')
Beispiel #31
0
 def test_invalid_keychain(self):
     """Test invalid keychain."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='b'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_C, text='c'))
     self.assertEqual(self.kp._keystring, '')
Beispiel #32
0
 def test_no_count(self):
     """Test with no count added."""
     self.kp.handle(helpers.fake_keyevent(Qt.Key_B, text='b'))
     self.kp.handle(helpers.fake_keyevent(Qt.Key_A, text='a'))
     self.kp.execute.assert_called_once_with('ba', self.kp.Type.chain, None)
     self.assertEqual(self.kp._keystring, '')