mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-04 12:00:16 +00:00
some more tests
This commit is contained in:
parent
eceacb6b59
commit
beee72431f
@ -70,7 +70,6 @@ class KeycodeInjector:
|
|||||||
|
|
||||||
def stop_injecting(self):
|
def stop_injecting(self):
|
||||||
"""Stop injecting keycodes."""
|
"""Stop injecting keycodes."""
|
||||||
# TODO test
|
|
||||||
logger.info('Stopping injecting keycodes')
|
logger.info('Stopping injecting keycodes')
|
||||||
for i, process in enumerate(self.processes):
|
for i, process in enumerate(self.processes):
|
||||||
if process is None:
|
if process is None:
|
||||||
@ -82,7 +81,6 @@ class KeycodeInjector:
|
|||||||
|
|
||||||
def _start_injecting_worker(self, path, pipe):
|
def _start_injecting_worker(self, path, pipe):
|
||||||
"""Inject keycodes for one of the virtual devices."""
|
"""Inject keycodes for one of the virtual devices."""
|
||||||
# TODO test
|
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
device = evdev.InputDevice(path)
|
device = evdev.InputDevice(path)
|
||||||
@ -157,7 +155,6 @@ class KeycodeInjector:
|
|||||||
event.code + 8, event.value, target_keycode, character
|
event.code + 8, event.value, target_keycode, character
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO test for the stuff put into write
|
|
||||||
keymapper_device.write(
|
keymapper_device.write(
|
||||||
evdev.ecodes.EV_KEY,
|
evdev.ecodes.EV_KEY,
|
||||||
target_keycode - 8,
|
target_keycode - 8,
|
||||||
|
@ -24,14 +24,8 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
CONFIG = os.path.join('/home', os.getlogin(), '.config/key-mapper')
|
|
||||||
|
|
||||||
# the "identity mapping"
|
CONFIG = os.path.join('/home', os.getlogin(), '.config/key-mapper')
|
||||||
KEYCODES_PATH = '/usr/share/X11/xkb/keycodes/key-mapper'
|
|
||||||
# to make the device not write its default keys anymore
|
|
||||||
EMPTY_SYMBOLS = '/usr/share/X11/xkb/symbols/key-mapper-empty'
|
|
||||||
# to make key-mappers own /dev device have keys
|
|
||||||
SYMBOLS_PATH = '/usr/share/X11/xkb/symbols/key-mapper-dev'
|
|
||||||
|
|
||||||
|
|
||||||
def get_config_path(device=None, preset=None):
|
def get_config_path(device=None, preset=None):
|
||||||
|
@ -71,14 +71,7 @@ class Event:
|
|||||||
|
|
||||||
def patch_paths():
|
def patch_paths():
|
||||||
from keymapper import paths
|
from keymapper import paths
|
||||||
prefix = '/tmp/key-mapper-test/X11/'
|
paths.CONFIG = '/tmp/key-mapper-test/'
|
||||||
paths.X11_SYMBOLS = prefix + 'symbols'
|
|
||||||
paths.CONFIG = prefix + 'symbols/key-mapper/user'
|
|
||||||
paths.DEFAULT_SYMBOLS = prefix + 'symbols/key-mapper/user/default'
|
|
||||||
paths.KEYCODES_PATH = prefix + 'keycodes/key-mapper'
|
|
||||||
|
|
||||||
|
|
||||||
# TODO patch for the injector or something idk?
|
|
||||||
|
|
||||||
|
|
||||||
def patch_evdev():
|
def patch_evdev():
|
||||||
|
@ -29,6 +29,22 @@ class TestMapping(unittest.TestCase):
|
|||||||
self.mapping = Mapping()
|
self.mapping = Mapping()
|
||||||
self.assertFalse(self.mapping.changed)
|
self.assertFalse(self.mapping.changed)
|
||||||
|
|
||||||
|
def test_save_load(self):
|
||||||
|
self.mapping.change(10, '1')
|
||||||
|
self.mapping.change(11, '2')
|
||||||
|
self.mapping.change(12, '3')
|
||||||
|
self.mapping.save('device 1', 'test')
|
||||||
|
loaded = Mapping()
|
||||||
|
self.assertEqual(len(loaded), 0)
|
||||||
|
loaded.load('device 1', 'test')
|
||||||
|
self.assertEqual(len(loaded), 3)
|
||||||
|
self.assertEqual(loaded.get_character(10), '1')
|
||||||
|
self.assertEqual(loaded.get_character(11), '2')
|
||||||
|
self.assertEqual(loaded.get_character(12), '3')
|
||||||
|
self.assertEqual(loaded.get_keycode('1'), 10)
|
||||||
|
self.assertEqual(loaded.get_keycode('2'), 11)
|
||||||
|
self.assertEqual(loaded.get_keycode('3'), 12)
|
||||||
|
|
||||||
def test_change(self):
|
def test_change(self):
|
||||||
# 1 is not assigned yet, ignore it
|
# 1 is not assigned yet, ignore it
|
||||||
self.mapping.change(2, 'a', 1)
|
self.mapping.change(2, 'a', 1)
|
||||||
@ -78,20 +94,33 @@ class TestMapping(unittest.TestCase):
|
|||||||
# does nothing
|
# does nothing
|
||||||
self.mapping.clear(40)
|
self.mapping.clear(40)
|
||||||
self.assertFalse(self.mapping.changed)
|
self.assertFalse(self.mapping.changed)
|
||||||
|
self.assertEqual(len(self.mapping), 0)
|
||||||
|
|
||||||
self.mapping._mapping[40] = 'b'
|
self.mapping._mapping[40] = 'b'
|
||||||
|
self.assertEqual(len(self.mapping), 1)
|
||||||
self.mapping.clear(40)
|
self.mapping.clear(40)
|
||||||
|
self.assertEqual(len(self.mapping), 0)
|
||||||
self.assertTrue(self.mapping.changed)
|
self.assertTrue(self.mapping.changed)
|
||||||
|
|
||||||
self.mapping.change(10, 'KP_1', None)
|
self.mapping.change(10, 'KP_1', None)
|
||||||
self.assertTrue(self.mapping.changed)
|
self.assertTrue(self.mapping.changed)
|
||||||
self.mapping.change(20, 'KP_2', None)
|
self.mapping.change(20, 'KP_2', None)
|
||||||
self.mapping.change(30, 'KP_3', None)
|
self.mapping.change(30, 'KP_3', None)
|
||||||
|
self.assertEqual(len(self.mapping), 3)
|
||||||
self.mapping.clear(20)
|
self.mapping.clear(20)
|
||||||
|
self.assertEqual(len(self.mapping), 2)
|
||||||
self.assertEqual(self.mapping.get_character(10), 'KP_1')
|
self.assertEqual(self.mapping.get_character(10), 'KP_1')
|
||||||
self.assertIsNone(self.mapping.get_character(20))
|
self.assertIsNone(self.mapping.get_character(20))
|
||||||
self.assertEqual(self.mapping.get_character(30), 'KP_3')
|
self.assertEqual(self.mapping.get_character(30), 'KP_3')
|
||||||
|
|
||||||
|
def test_empty(self):
|
||||||
|
self.mapping.change(10, '1')
|
||||||
|
self.mapping.change(11, '2')
|
||||||
|
self.mapping.change(12, '3')
|
||||||
|
self.assertEqual(len(self.mapping), 3)
|
||||||
|
self.mapping.empty()
|
||||||
|
self.assertEqual(len(self.mapping), 0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user