From 3fcc5af310c66470014c739c10b6bf02072f3e52 Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Thu, 19 Nov 2020 11:40:15 +0100 Subject: [PATCH] testing the injector constructor --- keymapper/injector.py | 1 + tests/test.py | 4 ++++ tests/testcases/injector.py | 14 +++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/keymapper/injector.py b/keymapper/injector.py index 77adc5a6..ca39c809 100644 --- a/keymapper/injector.py +++ b/keymapper/injector.py @@ -104,6 +104,7 @@ def _start_injecting_worker(path, pipe): device = _grab(path) if device is None: + print('lakjdsflakdsjfa') pipe.send(FAILED) return diff --git a/tests/test.py b/tests/test.py index 927008c9..399cead2 100644 --- a/tests/test.py +++ b/tests/test.py @@ -23,6 +23,7 @@ import sys +import time import unittest import evdev @@ -145,6 +146,9 @@ def patch_evdev(): while len(pending_events[self.name]) > 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): return fixtures[self.path]['capabilities'] diff --git a/tests/testcases/injector.py b/tests/testcases/injector.py index 4ffbdc47..9ac3d328 100644 --- a/tests/testcases/injector.py +++ b/tests/testcases/injector.py @@ -24,7 +24,8 @@ import unittest import evdev 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.state import custom_mapping, system_mapping @@ -97,6 +98,17 @@ class TestInjector(unittest.TestCase): toggle_numlock() 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): device = get_devices()['device 2']