input-remapper/tests/testcases/config.py

92 lines
3.0 KiB
Python
Raw Normal View History

2020-11-08 15:27:26 +00:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# key-mapper - GUI for device specific keyboard mappings
# Copyright (C) 2020 sezanzeb <proxima@hip70890b.de>
#
# This file is part of key-mapper.
#
# key-mapper is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# key-mapper is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with key-mapper. If not, see <https://www.gnu.org/licenses/>.
import os
import unittest
import shutil
2020-11-08 18:50:30 +00:00
from keymapper.X import mapping, generate_symbols_content, \
2020-11-08 15:27:26 +00:00
create_identity_mapping, create_setxkbmap_config, get_home_path
from keymapper.paths import KEYCODES_PATH, SYMBOLS_PATH, CONFIG_PATH
from test import tmp
class TestConfig(unittest.TestCase):
def setUp(self):
2020-11-08 18:50:30 +00:00
mapping.empty()
mapping.change(None, 10, 'a')
mapping.change(None, 11, 'KP_1')
mapping.change(None, 12, 3)
2020-11-08 15:27:26 +00:00
if os.path.exists(tmp):
shutil.rmtree(tmp)
def test_create_setxkbmap_config(self):
2020-11-08 18:50:30 +00:00
create_setxkbmap_config('device a', 'preset b')
2020-11-08 15:27:26 +00:00
self.assertTrue(os.path.exists(os.path.join(
CONFIG_PATH,
'device_a',
'preset_b'
)))
self.assertTrue(os.path.exists(os.path.join(
SYMBOLS_PATH,
'device_a',
'preset_b'
)))
self.assertTrue(os.path.exists(KEYCODES_PATH))
with open(get_home_path('device_a', 'preset_b'), 'r') as f:
content = f.read()
self.assertIn('key <10> { [ a ] };', content)
2020-11-08 17:51:35 +00:00
self.assertIn('key <11> { [ KP_1 ] };', content)
2020-11-08 15:27:26 +00:00
self.assertIn('key <12> { [ 3 ] };', content)
def test_generate_content(self):
self.assertRaises(
FileNotFoundError,
generate_symbols_content,
2020-11-08 18:50:30 +00:00
'device', 'preset'
2020-11-08 15:27:26 +00:00
)
# create the identity mapping, because it is required for
# generate_symbols_content
create_identity_mapping()
self.assertTrue(os.path.exists(KEYCODES_PATH))
with open(KEYCODES_PATH, 'r') as f:
keycodes = f.read()
2020-11-08 18:50:30 +00:00
self.assertNotIn('<9> = 9;', keycodes)
self.assertIn('<10> = 10;', keycodes)
self.assertIn('<11> = 11;', keycodes)
self.assertIn('<12> = 12;', keycodes)
self.assertNotIn('<13> = 13;', keycodes)
2020-11-08 15:27:26 +00:00
2020-11-08 18:50:30 +00:00
content = generate_symbols_content('device', 'preset')
2020-11-08 15:27:26 +00:00
self.assertIn('key <10> { [ a ] };', content)
2020-11-08 17:51:35 +00:00
self.assertIn('key <11> { [ KP_1 ] };', content)
2020-11-08 15:27:26 +00:00
self.assertIn('key <12> { [ 3 ] };', content)
if __name__ == "__main__":
unittest.main()