more macro tests

This commit is contained in:
sezanzeb 2020-11-29 00:28:46 +01:00
parent 68f2de3978
commit ea5b2fc049
5 changed files with 23 additions and 10 deletions

View File

@ -44,7 +44,7 @@ For a list of supported keystrokes and their names, check the output of
`xmodmap -pke` `xmodmap -pke`
Maybe you shouldn't use this feature in online PVP though. Might even get Maybe you shouldn't use this feature in online PVP though. Might even get
detected by the game. detected by your game.
## Git Installation ## 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] highlight changes and alert before discarding unsaved changes
- [x] automatically load presets on login for plugged in devices - [x] automatically load presets on login for plugged in devices
- [x] make sure it works on wayland - [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 - [ ] add to the AUR, provide .deb and .appimage files
- [ ] automatically load presets when devices get plugged in after login - [ ] automatically load presets when devices get plugged in after login

View File

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

View File

@ -217,6 +217,14 @@ def patch_dbus():
dbus.Interface = lambda *args: Daemon() 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 # quickly fake some stuff before any other file gets a chance to import
# the original versions # the original versions
patch_paths() patch_paths()

View File

@ -28,7 +28,8 @@ from keymapper.dev.injector import is_numlock_on, toggle_numlock,\
from keymapper.state import custom_mapping, system_mapping from keymapper.state import custom_mapping, system_mapping
from keymapper.mapping import 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): class TestInjector(unittest.TestCase):
@ -54,6 +55,7 @@ class TestInjector(unittest.TestCase):
evdev.InputDevice.grab = self.grab evdev.InputDevice.grab = self.grab
if pending_events.get('device 2') is not None: if pending_events.get('device 2') is not None:
del pending_events['device 2'] del pending_events['device 2']
clear_write_history()
def test_modify_capabilities(self): def test_modify_capabilities(self):
class FakeDevice: class FakeDevice:
@ -157,7 +159,7 @@ class TestInjector(unittest.TestCase):
] ]
self.injector = KeycodeInjector('device 2', custom_mapping) 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.injector._start_injecting()
self.assertEqual(len(uinput_write_history), 7) self.assertEqual(len(uinput_write_history), 7)

View File

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