From d355806c5a1ffa700407e4349d97d923326d5abd Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Wed, 2 Dec 2020 21:24:35 +0100 Subject: [PATCH] using the offset constant everywhere --- tests/testcases/test_daemon.py | 14 +++++++------- tests/testcases/test_integration.py | 12 ++++++------ tests/testcases/test_reader.py | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/testcases/test_daemon.py b/tests/testcases/test_daemon.py index e9e159bf..953d05d9 100644 --- a/tests/testcases/test_daemon.py +++ b/tests/testcases/test_daemon.py @@ -31,7 +31,7 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk from keymapper.state import custom_mapping, system_mapping, \ - clear_system_mapping + clear_system_mapping, KEYCODE_OFFSET from keymapper.config import config from keymapper.daemon import Daemon, get_dbus_interface, BUS_NAME @@ -97,7 +97,7 @@ class TestDaemon(unittest.TestCase): config.set_autoload_preset('device 2', preset) pending_events['device 2'] = [ - Event(evdev.events.EV_KEY, keycode_from_1 - 8, 0), + Event(evdev.events.EV_KEY, keycode_from_1 - KEYCODE_OFFSET, 0), ] self.daemon = Daemon() @@ -108,15 +108,15 @@ class TestDaemon(unittest.TestCase): event = uinput_write_history_pipe[0].recv() self.assertEqual(event.type, evdev.events.EV_KEY) - self.assertEqual(event.code, keycode_to_1 - 8) + self.assertEqual(event.code, keycode_to_1 - KEYCODE_OFFSET) self.assertEqual(event.value, 0) self.daemon.stop_injecting('device 2') self.assertFalse(self.daemon.is_injecting('device 2')) pending_events['device 2'] = [ - Event(evdev.events.EV_KEY, keycode_from_2 - 8, 1), - Event(evdev.events.EV_KEY, keycode_from_2 - 8, 0), + Event(evdev.events.EV_KEY, keycode_from_2 - KEYCODE_OFFSET, 1), + Event(evdev.events.EV_KEY, keycode_from_2 - KEYCODE_OFFSET, 0), ] time.sleep(0.2) @@ -126,12 +126,12 @@ class TestDaemon(unittest.TestCase): event = uinput_write_history_pipe[0].recv() self.assertEqual(event.type, evdev.events.EV_KEY) - self.assertEqual(event.code, keycode_to_2 - 8) + self.assertEqual(event.code, keycode_to_2 - KEYCODE_OFFSET) self.assertEqual(event.value, 1) event = uinput_write_history_pipe[0].recv() self.assertEqual(event.type, evdev.events.EV_KEY) - self.assertEqual(event.code, keycode_to_2 - 8) + self.assertEqual(event.code, keycode_to_2 - KEYCODE_OFFSET) self.assertEqual(event.value, 0) diff --git a/tests/testcases/test_integration.py b/tests/testcases/test_integration.py index 454324a0..318da8a6 100644 --- a/tests/testcases/test_integration.py +++ b/tests/testcases/test_integration.py @@ -36,7 +36,7 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk from keymapper.state import custom_mapping, system_mapping, \ - clear_system_mapping + clear_system_mapping, KEYCODE_OFFSET from keymapper.paths import CONFIG, get_config_path from keymapper.config import config from keymapper.dev.reader import keycode_reader @@ -408,8 +408,8 @@ class TestIntegration(unittest.TestCase): system_mapping['a'] = keycode_to pending_events['device 2'] = [ - Event(evdev.events.EV_KEY, keycode_from - 8, 1), - Event(evdev.events.EV_KEY, keycode_from - 8, 0) + Event(evdev.events.EV_KEY, keycode_from - KEYCODE_OFFSET, 1), + Event(evdev.events.EV_KEY, keycode_from - KEYCODE_OFFSET, 0) ] custom_mapping.save('device 2', 'foo preset') @@ -428,12 +428,12 @@ class TestIntegration(unittest.TestCase): event = uinput_write_history_pipe[0].recv() self.assertEqual(event.type, evdev.events.EV_KEY) - self.assertEqual(event.code, keycode_to - 8) + self.assertEqual(event.code, keycode_to - KEYCODE_OFFSET) self.assertEqual(event.value, 1) event = uinput_write_history_pipe[0].recv() self.assertEqual(event.type, evdev.events.EV_KEY) - self.assertEqual(event.code, keycode_to - 8) + self.assertEqual(event.code, keycode_to - KEYCODE_OFFSET) self.assertEqual(event.value, 0) def test_stop_injecting(self): @@ -446,7 +446,7 @@ class TestIntegration(unittest.TestCase): # not all of those events should be processed, since that takes some # time due to time.sleep in the fakes and the injection is stopped. - pending_events['device 2'] = [Event(1, keycode_from - 8, 1)] * 100 + pending_events['device 2'] = [Event(1, keycode_from - KEYCODE_OFFSET, 1)] * 100 custom_mapping.save('device 2', 'foo preset') diff --git a/tests/testcases/test_reader.py b/tests/testcases/test_reader.py index 86e297e3..ef958cd1 100644 --- a/tests/testcases/test_reader.py +++ b/tests/testcases/test_reader.py @@ -21,11 +21,11 @@ import unittest -import evdev from evdev.events import EV_KEY import time from keymapper.dev.reader import keycode_reader +from keymapper.state import KEYCODE_OFFSET from tests.test import Event, pending_events, EVENT_READ_TIMEOUT @@ -58,7 +58,7 @@ class TestReader(unittest.TestCase): keycode_reader._pipe[0].send((EV_KEY, 1234)) time.sleep(EVENT_READ_TIMEOUT * 5) - self.assertEqual(keycode_reader.read(), (EV_KEY, CODE_3 + 8)) + self.assertEqual(keycode_reader.read(), (EV_KEY, CODE_3 + KEYCODE_OFFSET)) self.assertEqual(keycode_reader.read(), (None, None)) def test_wrong_device(self): @@ -106,7 +106,7 @@ class TestReader(unittest.TestCase): keycode_reader.start_reading('device 1') time.sleep(EVENT_READ_TIMEOUT * 5) - self.assertEqual(keycode_reader.read(), (EV_KEY, CODE_3 + 8)) + self.assertEqual(keycode_reader.read(), (EV_KEY, CODE_3 + KEYCODE_OFFSET)) self.assertEqual(keycode_reader.read(), (None, None))