2020-10-26 22:45:22 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2020-10-31 13:43:09 +00:00
|
|
|
# key-mapper - GUI for device specific keyboard mappings
|
2020-10-26 22:45:22 +00:00
|
|
|
# Copyright (C) 2020 sezanzeb <proxima@hip70890b.de>
|
|
|
|
#
|
2020-10-31 13:02:59 +00:00
|
|
|
# This file is part of key-mapper.
|
2020-10-26 22:45:22 +00:00
|
|
|
#
|
2020-10-31 13:02:59 +00:00
|
|
|
# key-mapper is free software: you can redistribute it and/or modify
|
2020-10-26 22:45:22 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2020-10-31 13:02:59 +00:00
|
|
|
# key-mapper is distributed in the hope that it will be useful,
|
2020-10-26 22:45:22 +00:00
|
|
|
# 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
|
2020-10-31 13:02:59 +00:00
|
|
|
# along with key-mapper. If not, see <https://www.gnu.org/licenses/>.
|
2020-10-26 22:45:22 +00:00
|
|
|
|
|
|
|
|
2020-10-31 13:02:59 +00:00
|
|
|
"""Sets up key-mapper for the tests and runs them."""
|
2020-10-26 22:45:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
2020-11-07 23:54:19 +00:00
|
|
|
# quickly fake some stuff before any other file gets a chance to import
|
|
|
|
# the original version
|
2020-11-02 00:25:43 +00:00
|
|
|
from keymapper import paths
|
2020-11-15 11:11:35 +00:00
|
|
|
paths.X11_SYMBOLS = '/tmp/key-mapper-test/X11/symbols'
|
2020-11-10 22:14:28 +00:00
|
|
|
paths.USERS_SYMBOLS = '/tmp/key-mapper-test/X11/symbols/key-mapper/user'
|
2020-11-15 11:11:35 +00:00
|
|
|
paths.DEFAULT_SYMBOLS = '/tmp/key-mapper-test/user/.config/default'
|
2020-11-10 22:14:28 +00:00
|
|
|
paths.HOME_PATH = '/tmp/key-mapper-test/user/.config'
|
|
|
|
paths.KEYCODES_PATH = '/tmp/key-mapper-test/X11/keycodes/key-mapper'
|
2020-11-02 00:25:43 +00:00
|
|
|
|
2020-11-07 23:54:19 +00:00
|
|
|
from keymapper import linux
|
|
|
|
linux._devices = {
|
2020-11-02 20:57:28 +00:00
|
|
|
'device 1': {
|
|
|
|
'paths': [
|
|
|
|
'/dev/input/event10',
|
|
|
|
'/dev/input/event11',
|
|
|
|
'/dev/input/event13'
|
|
|
|
],
|
|
|
|
'names': [
|
|
|
|
'device 1 something',
|
|
|
|
'device 1',
|
|
|
|
'device 1'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'device 2': {
|
|
|
|
'paths': ['/dev/input/event3'],
|
|
|
|
'names': ['device 2']
|
|
|
|
}
|
2020-11-07 23:54:19 +00:00
|
|
|
}
|
|
|
|
linux.get_devices = lambda: linux._devices
|
2020-11-02 00:25:43 +00:00
|
|
|
|
2020-11-14 23:27:45 +00:00
|
|
|
# don't block tests
|
|
|
|
from keymapper.gtk import unsaved
|
|
|
|
unsaved.unsaved_changes_dialog = lambda: unsaved.CONTINUE
|
|
|
|
|
2020-11-02 01:17:58 +00:00
|
|
|
from keymapper.logger import update_verbosity
|
2020-11-02 00:25:43 +00:00
|
|
|
|
2020-11-07 23:54:19 +00:00
|
|
|
# some class function stubs.
|
|
|
|
# can be overwritten in tests as well at any time.
|
|
|
|
linux.KeycodeReader.start_reading = lambda *args: None
|
|
|
|
linux.KeycodeReader.read = lambda *args: None
|
|
|
|
|
|
|
|
tmp = '/tmp/key-mapper-test'
|
|
|
|
|
2020-10-26 22:45:22 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-11-02 00:25:43 +00:00
|
|
|
update_verbosity(True)
|
|
|
|
|
2020-10-26 22:45:22 +00:00
|
|
|
modules = sys.argv[1:]
|
|
|
|
# discoverer is really convenient, but it can't find a specific test
|
|
|
|
# in all of the available tests like unittest.main() does...,
|
|
|
|
# so provide both options.
|
|
|
|
if len(modules) > 0:
|
2020-11-14 23:27:45 +00:00
|
|
|
# for example `tests/test.py integration.Integration.test_can_start`
|
2020-10-26 22:45:22 +00:00
|
|
|
testsuite = unittest.defaultTestLoader.loadTestsFromNames(
|
|
|
|
[f'testcases.{module}' for module in modules]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
# run all tests by default
|
|
|
|
testsuite = unittest.defaultTestLoader.discover(
|
|
|
|
'testcases', pattern='*.py'
|
|
|
|
)
|
|
|
|
testrunner = unittest.TextTestRunner(verbosity=1).run(testsuite)
|