testing list_names

This commit is contained in:
sezanzeb 2020-12-06 12:54:14 +01:00 committed by sezanzeb
parent 74da396fd8
commit 453dd2c793
5 changed files with 18 additions and 4 deletions

View File

@ -86,7 +86,6 @@ if __name__ == '__main__':
log_info() log_info()
if options.key_names: if options.key_names:
# TODO test
print('\n'.join(system_mapping.list_names())) print('\n'.join(system_mapping.list_names()))
sys.exit(0) sys.exit(0)

View File

@ -34,7 +34,6 @@ from keymapper.paths import USER
def check_group(group): def check_group(group):
"""Check if the required group is active and log if not.""" """Check if the required group is active and log if not."""
# TODO test
try: try:
in_group = USER in grp.getgrnam(group).gr_mem in_group = USER in grp.getgrnam(group).gr_mem
except KeyError: except KeyError:

View File

@ -43,7 +43,6 @@ class SystemMapping:
def list_names(self): def list_names(self):
"""Return an array of all possible names in the mapping.""" """Return an array of all possible names in the mapping."""
# TODO test
return self._mapping.keys() return self._mapping.keys()
def populate(self): def populate(self):
@ -70,7 +69,7 @@ class SystemMapping:
self._set(name, int(keycode) - XKB_KEYCODE_OFFSET) self._set(name, int(keycode) - XKB_KEYCODE_OFFSET)
for name, ecode in evdev.ecodes.ecodes.items(): for name, ecode in evdev.ecodes.ecodes.items():
if name.startswith('KEY') or name.startswith('KEY'): if name.startswith('KEY') or name.startswith('BTN'):
self._set(name, ecode) self._set(name, ecode)
def _set(self, name, code): def _set(self, name, code):

View File

@ -35,5 +35,7 @@ class TestKeycodeMapper(unittest.TestCase):
# TODO test for macro holding # TODO test for macro holding
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

View File

@ -43,6 +43,8 @@ class TestMapping(unittest.TestCase):
self.assertEqual(system_mapping.get('kEY_LeFTSHIFT'), 42) self.assertEqual(system_mapping.get('kEY_LeFTSHIFT'), 42)
self.assertEqual(system_mapping.get('ShiFt_L'), 42) self.assertEqual(system_mapping.get('ShiFt_L'), 42)
self.assertEqual(system_mapping.get('BTN_left'), 272)
self.assertIsNotNone(system_mapping.get('kp_1')) self.assertIsNotNone(system_mapping.get('kp_1'))
self.assertIsNotNone(system_mapping.get('KP_1')) self.assertIsNotNone(system_mapping.get('KP_1'))
self.assertEqual( self.assertEqual(
@ -54,6 +56,19 @@ class TestMapping(unittest.TestCase):
system_mapping.get('KEY_KP4') system_mapping.get('KEY_KP4')
) )
names = system_mapping.list_names()
self.assertIn('key_kp1', names)
self.assertIn('key_nextsong', names)
self.assertIn('2', names)
self.assertIn('key_3', names)
self.assertIn('c', names)
self.assertIn('key_d', names)
self.assertIn('f4', names)
self.assertIn('key_f5', names)
self.assertIn('minus', names)
self.assertIn('btn_left', names)
self.assertIn('btn_right', names)
def test_clone(self): def test_clone(self):
mapping1 = Mapping() mapping1 = Mapping()
mapping1.change((EV_KEY, 1), 'a') mapping1.change((EV_KEY, 1), 'a')