refactor Key and ModifierKey __call__ methods

- Add tests for ModifierKey chaining
- Rewrite ModifierKey.__call__ for correctness and readability
- __call__ now maintains handlers and meta, like clone()
This commit is contained in:
Ryan Rotter
2022-04-17 16:52:24 -05:00
committed by Kyle Brown
parent 7a51ce576f
commit 27a0bc1977
2 changed files with 115 additions and 32 deletions

87
tests/test_kmk_keys.py Normal file
View File

@@ -0,0 +1,87 @@
import unittest
from kmk.keys import KC, Key, ModifierKey
from tests.keyboard_test import KeyboardTest
class TestKmkKeys(unittest.TestCase):
def test_basic_kmk_keyboard(self):
keyboard = KeyboardTest(
[],
[
[
KC.HASH,
KC.RALT(KC.HASH),
KC.RALT(KC.LSFT)(KC.N3),
KC.RALT(KC.LSFT),
KC.RALT,
]
],
)
keyboard.test(
'Shifted key',
[(0, True), (0, False)],
[
{
KC.N3,
KC.LSFT,
},
{},
],
)
keyboard.test(
'Shift+AltGr+key',
[(1, True), (1, False)],
[
{
KC.N3,
KC.LSFT,
KC.RALT,
},
{},
],
)
keyboard.test(
'Shift+AltGr+key, alternate chaining',
[(2, True), (2, False)],
[
{
KC.N3,
KC.LSFT,
KC.RALT,
},
{},
],
)
keyboard.test(
'Shift+AltGr',
[(3, True), (3, False)],
[
{
KC.LSFT,
KC.RALT,
},
{},
],
)
keyboard.test(
'AltGr',
[(4, True), (4, False)],
[
{
KC.RALT,
},
{},
],
)
assert isinstance(KC.RGUI(no_press=True), ModifierKey)
assert isinstance(KC.RALT(KC.RGUI), ModifierKey)
assert isinstance(KC.Q(no_press=True), Key)
assert not isinstance(KC.Q(no_press=True), ModifierKey)
assert isinstance(KC.RALT(KC.Q), Key)
assert not isinstance(KC.RALT(KC.Q), ModifierKey)
if __name__ == '__main__':
unittest.main()