more macro tests

pull/14/head
sezanzeb 4 years ago
parent 68f2de3978
commit ea5b2fc049

@ -44,7 +44,7 @@ For a list of supported keystrokes and their names, check the output of
`xmodmap -pke`
Maybe you shouldn't use this feature in online PVP though. Might even get
detected by the game.
detected by your game.
## Git Installation
@ -84,6 +84,6 @@ sudo python3 setup.py install && python3 tests/test.py
- [x] highlight changes and alert before discarding unsaved changes
- [x] automatically load presets on login for plugged in devices
- [x] make sure it works on wayland
- [ ] support timed macros, maybe using some sort of syntax
- [x] support timed macros, maybe using some sort of syntax
- [ ] add to the AUR, provide .deb and .appimage files
- [ ] automatically load presets when devices get plugged in after login

@ -225,7 +225,10 @@ class KeycodeInjector:
def _macro_write(self, character, value, keymapper_device):
"""Handler for macros."""
keycode = system_mapping.get_keycode(character)
logger.spam('macro writes code:%s char:%s', keycode, character)
logger.spam(
'macro writes code:%s value:%d char:%s',
keycode, value, character
)
self._write(keymapper_device, keycode, value)
async def _injection_loop(self, device, keymapper_device):
@ -271,8 +274,7 @@ class KeycodeInjector:
if character is None:
# unknown keycode, forward it
target_keycode = input_keycode
elif '(' in character:
# must be a macro
elif macros.get(input_keycode) is not None:
if event.value == 0:
continue
@ -283,7 +285,6 @@ class KeycodeInjector:
character
)
macro = macros.get(input_keycode)
# TODO test if m(SHIFT_L, k(a)) prints A in injector tests
if macro is not None:
asyncio.ensure_future(macro.run())
continue

@ -217,6 +217,14 @@ def patch_dbus():
dbus.Interface = lambda *args: Daemon()
def clear_write_history():
"""Empty the history in preparation for the next test."""
while len(uinput_write_history) > 0:
uinput_write_history.pop()
while uinput_write_history_pipe[0].poll():
uinput_write_history_pipe[0].recv()
# quickly fake some stuff before any other file gets a chance to import
# the original versions
patch_paths()

@ -28,7 +28,8 @@ from keymapper.dev.injector import is_numlock_on, toggle_numlock,\
from keymapper.state import custom_mapping, system_mapping
from keymapper.mapping import Mapping
from test import uinput_write_history, Event, pending_events, fixtures
from test import uinput_write_history, Event, pending_events, fixtures, \
clear_write_history
class TestInjector(unittest.TestCase):
@ -54,6 +55,7 @@ class TestInjector(unittest.TestCase):
evdev.InputDevice.grab = self.grab
if pending_events.get('device 2') is not None:
del pending_events['device 2']
clear_write_history()
def test_modify_capabilities(self):
class FakeDevice:
@ -157,7 +159,7 @@ class TestInjector(unittest.TestCase):
]
self.injector = KeycodeInjector('device 2', custom_mapping)
# don't start the process for coverage testing purposes
# don't start as process for coverage testing purposes
self.injector._start_injecting()
self.assertEqual(len(uinput_write_history), 7)

@ -37,7 +37,8 @@ from keymapper.state import custom_mapping, system_mapping
from keymapper.paths import CONFIG
from keymapper.config import config
from test import tmp, pending_events, Event, uinput_write_history_pipe
from test import tmp, pending_events, Event, uinput_write_history_pipe, \
clear_write_history
def gtk_iteration():
@ -101,6 +102,7 @@ class Integration(unittest.TestCase):
self.window.window.destroy()
gtk_iteration()
shutil.rmtree('/tmp/key-mapper-test')
clear_write_history()
def get_rows(self):
return self.window.get('key_list').get_children()
@ -285,7 +287,7 @@ class Integration(unittest.TestCase):
def test_start_injecting(self):
keycode_from = 9
keycode_to = 100
keycode_to = 200
self.change_empty_row(keycode_from, 'a')
system_mapping.empty()

Loading…
Cancel
Save