testing the injector constructor

This commit is contained in:
sezanzeb 2020-11-19 11:40:15 +01:00
parent 6def1dcc54
commit 3fcc5af310
3 changed files with 18 additions and 1 deletions

View File

@ -104,6 +104,7 @@ def _start_injecting_worker(path, pipe):
device = _grab(path) device = _grab(path)
if device is None: if device is None:
print('lakjdsflakdsjfa')
pipe.send(FAILED) pipe.send(FAILED)
return return

View File

@ -23,6 +23,7 @@
import sys import sys
import time
import unittest import unittest
import evdev import evdev
@ -145,6 +146,9 @@ def patch_evdev():
while len(pending_events[self.name]) > 0: while len(pending_events[self.name]) > 0:
yield pending_events[self.name].pop(0) yield pending_events[self.name].pop(0)
# give tests some time to test stuff while the process
# is still running
time.sleep(0.01)
def capabilities(self, absinfo=True): def capabilities(self, absinfo=True):
return fixtures[self.path]['capabilities'] return fixtures[self.path]['capabilities']

View File

@ -24,7 +24,8 @@ import unittest
import evdev import evdev
from keymapper.injector import _start_injecting_worker, _grab, \ from keymapper.injector import _start_injecting_worker, _grab, \
is_numlock_on, toggle_numlock, ensure_numlock, _modify_capabilities is_numlock_on, toggle_numlock, ensure_numlock, _modify_capabilities, \
KeycodeInjector
from keymapper.getdevices import get_devices from keymapper.getdevices import get_devices
from keymapper.state import custom_mapping, system_mapping from keymapper.state import custom_mapping, system_mapping
@ -97,6 +98,17 @@ class TestInjector(unittest.TestCase):
toggle_numlock() toggle_numlock()
self.assertEqual(before, is_numlock_on()) self.assertEqual(before, is_numlock_on())
def test_injector_constructor(self):
global pending_events
# this buys some time to test if the process is alive. 2 (20ms) would
# already be enough
pending_events['device 2'] = [Event(1, 1, 1)] * 10
injector2 = KeycodeInjector('device 2')
self.assertEqual(len(injector2.processes), 1)
self.assertEqual(injector2.processes[0].is_alive(), True)
injector2.processes[0].join()
def test_injector(self): def test_injector(self):
device = get_devices()['device 2'] device = get_devices()['device 2']