tested reverse mapping

This commit is contained in:
sezanzeb 2020-11-23 23:41:13 +01:00
parent 36c2ae1be0
commit b1fff0c286
2 changed files with 8 additions and 1 deletions

View File

@ -33,7 +33,6 @@ def parse_xmodmap(mapping):
"""Read the output of xmodmap into a mapping.""" """Read the output of xmodmap into a mapping."""
xmodmap = subprocess.check_output(['xmodmap', '-pke']).decode() + '\n' xmodmap = subprocess.check_output(['xmodmap', '-pke']).decode() + '\n'
mappings = re.findall(r'(\d+) = (.+)\n', xmodmap) mappings = re.findall(r'(\d+) = (.+)\n', xmodmap)
# TODO is this tested?
for keycode, characters in mappings: for keycode, characters in mappings:
# this is the "array" format needed for symbols files # this is the "array" format needed for symbols files
character = ', '.join(characters.split()) character = ', '.join(characters.split())

View File

@ -22,6 +22,7 @@
import unittest import unittest
from keymapper.mapping import Mapping from keymapper.mapping import Mapping
from keymapper.state import parse_xmodmap
class TestMapping(unittest.TestCase): class TestMapping(unittest.TestCase):
@ -29,6 +30,13 @@ class TestMapping(unittest.TestCase):
self.mapping = Mapping() self.mapping = Mapping()
self.assertFalse(self.mapping.changed) self.assertFalse(self.mapping.changed)
def test_parse_xmodmap(self):
parse_xmodmap(self.mapping)
self.assertGreater(len(self.mapping), 100)
# keycode 10 is typically mapped to '1'
self.assertEqual(self.mapping.get_keycode('1'), 10)
self.assertTrue(self.mapping.get_character(10).startswith('1'))
def test_save_load(self): def test_save_load(self):
self.mapping.change(10, '1') self.mapping.change(10, '1')
self.mapping.change(11, '2') self.mapping.change(11, '2')