def test_add_hotkey_single_step_nonsuppress_repeated(self): queue = hotkey._queue.Queue() hotkey.add_hotkey('ctrl+shift+a+b', lambda: queue.put(True), suppress=False) self.do(d_shift+d_ctrl+d_a+d_b) self.do(d_shift+d_ctrl+d_a+d_b) self.assertTrue(queue.get(timeout=0.5)) self.assertTrue(queue.get(timeout=0.5))
def test_remove_hotkey_internal_multistep_start(self): remove = hotkey.add_hotkey('shift+a, b', trigger, suppress=True) self.assertTrue(all(hotkey._listener.blocking_hotkeys.values())) self.assertTrue(all(hotkey._listener.filtered_modifiers.values())) self.assertNotEqual(hotkey._hotkeys, {}) remove() self.assertTrue(not any(hotkey._listener.filtered_modifiers.values())) self.assertTrue(not any(hotkey._listener.blocking_hotkeys.values())) self.assertEqual(hotkey._hotkeys, {})
def test_add_hotkey_single_step_suppress_args_allow(self): arg = object() hotkey.add_hotkey('a', lambda a: self.assertIs(a, arg) or trigger() or True, args=(arg,), suppress=True) self.do(d_a, triggered_event+d_a)
def test_add_hotkey_multi_step_suppress_regression_1(self): hotkey.add_hotkey('a, b', trigger, suppress=True) self.do(d_c+d_a+u_c+u_a+du_c, d_c+d_a+u_c+u_a+du_c)
def test_add_hotkey_multistep_suppress_repeated_prefix(self): hotkey.add_hotkey('a, a, c', trigger, suppress=True, trigger_on_release=True) self.do(du_a+du_a+du_c, triggered_event)
def test_add_hotkey_multistep_suppress_fail(self): hotkey.add_hotkey('a, b', trigger, suppress=True) self.do(du_a+du_c, du_a+du_c)
def test_add_hotkey_multistep_suppress_incomplete(self): hotkey.add_hotkey('a, b', trigger, suppress=True) self.do(du_a+du_b, triggered_event)
def test_add_hotkey_single_step_suppress_regression_1(self): hotkey.add_hotkey('a', trigger, suppress=True) self.do(d_c+d_a+u_c+u_a, d_c+d_a+u_c+u_a)
def test_add_hotkey_single_step_suppress_with_modifiers_release(self): hotkey.add_hotkey('ctrl+shift+a', trigger, suppress=True) self.do(d_ctrl+d_shift+du_b+d_a+u_ctrl+u_shift, d_shift+d_ctrl+du_b+triggered_event+u_ctrl+u_shift)
def test_add_hotkey_single_step_suppress_with_modifiers_unrelated_key(self): hotkey.add_hotkey('ctrl+shift+a', trigger, suppress=True) self.do(d_ctrl+d_shift+du_b+d_a, d_shift+d_ctrl+du_b+triggered_event)
def test_add_hotkey_single_step_suppress_with_modifiers_fail_unrelated_modifier(self): hotkey.add_hotkey('ctrl+shift+a', trigger, suppress=True) self.do(d_ctrl+d_shift+u_shift+d_a, d_shift+u_shift+d_ctrl+d_a)
def test_add_hotkey_single_step_suppress_removed(self): hotkey.remove_hotkey(hotkey.add_hotkey('ctrl+a', trigger, suppress=True)) self.do(d_ctrl+d_a, d_ctrl+d_a) self.assertEqual(hotkey._listener.filtered_modifiers[dummy_keys['left ctrl'][0][0]], 0)
def test_add_hotkey_single_step_suppress_removed(self): hotkey.remove_hotkey(hotkey.add_hotkey('a', trigger, suppress=True)) self.do(d_a, d_a)
def test_add_hotkey_single_step_suppress_single(self): hotkey.add_hotkey('a', trigger, suppress=True) self.do(d_a, triggered_event)
def test_add_hotkey_multi_step_suffix_timeout(self): hotkey.add_hotkey('a, b, a', trigger, timeout=0.01, suppress=True) self.do(du_a+du_b, []) time.sleep(0.05) self.do(du_a, du_a+du_b) self.do(du_b+du_a, triggered_event)
def test_add_hotkey_single_step_suppress_with_modifiers_out_of_order(self): hotkey.add_hotkey('ctrl+shift+a', trigger, suppress=True) self.do(d_shift+d_ctrl+d_a, triggered_event)
def test_add_hotkey_multi_step_allow(self): hotkey.add_hotkey('a, b', lambda: trigger() or True, suppress=True) self.do(du_a+du_b, triggered_event+du_a+du_b)
def test_add_hotkey_single_step_suppress_with_modifiers_release(self): hotkey.add_hotkey('ctrl+a', trigger, suppress=True, trigger_on_release=True) self.do(d_ctrl+du_a+du_b+du_a, triggered_event+d_ctrl+du_b+triggered_event)
def test_add_hotkey_single_step_nosuppress_with_modifiers_out_of_order(self): queue = hotkey._queue.Queue() hotkey.add_hotkey('ctrl+shift+a', lambda: queue.put(True), suppress=False) self.do(d_shift+d_ctrl+d_a) self.assertTrue(queue.get(timeout=0.5))
def test_add_hotkey_single_step_suppress_with_modifier_superset(self): hotkey.add_hotkey('ctrl+a', trigger, suppress=True) self.do(d_ctrl+d_shift+du_a+u_shift+u_ctrl, d_ctrl+d_shift+du_a+u_shift+u_ctrl)
def test_add_hotkey_multistep_suppress_incomplete(self): hotkey.add_hotkey('a, b', trigger, suppress=True) self.do(du_a, []) self.assertEqual(hotkey._listener.blocking_hotkeys[(1,)], []) self.assertEqual(len(hotkey._listener.blocking_hotkeys[(2,)]), 1)
def test_add_hotkey_single_step_timeout(self): hotkey.add_hotkey('a', trigger, timeout=1, suppress=True) self.do(du_a, triggered_event)
def test_add_hotkey_multistep_suppress_modifier(self): hotkey.add_hotkey('shift+a, b', trigger, suppress=True) self.do(d_shift+du_a+u_shift+du_b, triggered_event)
def test_add_hotkey_multi_step_first_timeout(self): hotkey.add_hotkey('a, b', trigger, timeout=0.01, suppress=True) time.sleep(0.03) self.do(du_a+du_b, triggered_event)
def test_add_hotkey_multistep_suppress_three_steps(self): hotkey.add_hotkey('a, b, c', trigger, suppress=True) self.do(du_a+du_b+du_c, triggered_event)
def test_add_hotkey_multi_step_last_timeout(self): hotkey.add_hotkey('a, b', trigger, timeout=0.01, suppress=True) self.do(du_a, []) time.sleep(0.05) self.do(du_b, du_a+du_b)
def test_add_hotkey_multistep_suppress_repeated_key(self): hotkey.add_hotkey('a, b', trigger, suppress=True) self.do(du_a+du_a+du_b, du_a+triggered_event) self.assertEqual(hotkey._listener.blocking_hotkeys[(2,)], []) self.assertEqual(len(hotkey._listener.blocking_hotkeys[(1,)]), 1)
def test_add_hotkey_multi_step_success_timeout(self): hotkey.add_hotkey('a, b', trigger, timeout=0.05, suppress=True) self.do(du_a, []) time.sleep(0.01) self.do(du_b, triggered_event)
def test_add_hotkey_multi_step_suppress_replays(self): hotkey.add_hotkey('a, b, c', trigger, suppress=True) self.do(du_a+du_b+du_a+du_b+du_space, du_a+du_b+du_a+du_b+du_space)
def test_add_hotkey_single_step_suppress_allow(self): hotkey.add_hotkey('a', lambda: trigger() or True, suppress=True) self.do(d_a, triggered_event+d_a)