Beispiel #1
0
    def test_xmodmap_file(self):
        system_mapping = SystemMapping()
        path = os.path.join(tmp, XMODMAP_FILENAME)
        os.remove(path)

        system_mapping.populate()
        self.assertTrue(os.path.exists(path))
        with open(path, 'r') as file:
            content = json.load(file)
            self.assertEqual(content['a'], KEY_A)
            # only xmodmap stuff should be present
            self.assertNotIn('key_a', content)
            self.assertNotIn('KEY_A', content)
            self.assertNotIn('disable', content)
Beispiel #2
0
    def test_system_mapping(self):
        system_mapping = SystemMapping()
        self.assertGreater(len(system_mapping._mapping), 100)

        # this is case-insensitive
        self.assertEqual(system_mapping.get('1'), 2)
        self.assertEqual(system_mapping.get('KeY_1'), 2)

        self.assertEqual(system_mapping.get('AlT_L'), 56)
        self.assertEqual(system_mapping.get('KEy_LEFtALT'), 56)

        self.assertEqual(system_mapping.get('kEY_LeFTSHIFT'), 42)
        self.assertEqual(system_mapping.get('ShiFt_L'), 42)

        self.assertEqual(system_mapping.get('BTN_left'), 272)

        self.assertIsNotNone(system_mapping.get('KEY_KP4'))
        self.assertEqual(system_mapping.get('KP_Left'),
                         system_mapping.get('KEY_KP4'))

        # this only lists the correct casing,
        # includes linux constants and xmodmap symbols
        names = system_mapping.list_names()
        self.assertIn('2', names)
        self.assertIn('c', names)
        self.assertIn('KEY_3', names)
        self.assertNotIn('key_3', names)
        self.assertIn('KP_Down', names)
        self.assertNotIn('kp_down', names)
        names = system_mapping._mapping.keys()
        self.assertIn('F4', names)
        self.assertNotIn('f4', names)
        self.assertIn('BTN_RIGHT', names)
        self.assertNotIn('btn_right', names)
        self.assertIn('KEY_KP7', names)
        self.assertIn('KP_Home', names)
        self.assertNotIn('kp_home', names)

        self.assertEqual(system_mapping.get('disable'), -1)
Beispiel #3
0
    def test_correct_case(self):
        system_mapping = SystemMapping()
        system_mapping.clear()
        system_mapping._set('A', 31)
        system_mapping._set('a', 32)
        system_mapping._set('abcd_B', 33)

        self.assertEqual(system_mapping.correct_case('a'), 'a')
        self.assertEqual(system_mapping.correct_case('A'), 'A')
        self.assertEqual(system_mapping.correct_case('ABCD_b'), 'abcd_B')
        # unknown stuff is returned as is
        self.assertEqual(system_mapping.correct_case('FOo'), 'FOo')

        self.assertEqual(system_mapping.get('A'), 31)
        self.assertEqual(system_mapping.get('a'), 32)
        self.assertEqual(system_mapping.get('ABCD_b'), 33)
        self.assertEqual(system_mapping.get('abcd_B'), 33)
Beispiel #4
0
 def test_update(self):
     system_mapping = SystemMapping()
     system_mapping.update({'foo1': 101, 'bar1': 102})
     system_mapping.update({'foo2': 201, 'bar2': 202})
     self.assertEqual(system_mapping.get('foo1'), 101)
     self.assertEqual(system_mapping.get('bar2'), 202)
Beispiel #5
0
    def test_system_mapping(self):
        system_mapping = SystemMapping()
        self.assertGreater(len(system_mapping._mapping), 100)
        self.assertEqual(system_mapping.get('1'), 2)
        self.assertEqual(system_mapping.get('KeY_1'), 2)

        self.assertEqual(system_mapping.get('AlT_L'), 56)
        self.assertEqual(system_mapping.get('KEy_LEFtALT'), 56)

        self.assertEqual(system_mapping.get('kEY_LeFTSHIFT'), 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.assertEqual(system_mapping.get('KP_Left'),
                         system_mapping.get('KP_4'))
        self.assertEqual(system_mapping.get('KP_Left'),
                         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)

        self.assertEqual(system_mapping.get('disable'), -1)