1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
# SPDX-FileCopyrightText: Florian Bruhin (The Compiler) <mail@qutebrowser.org>:
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""pytest fixtures for tests.keyinput."""
import pytest
import contextlib
from qutebrowser.keyinput import keyutils
BINDINGS = {'prompt': {'<Ctrl-a>': 'message-info ctrla',
'a': 'message-info a',
'ba': 'message-info ba',
'ax': 'message-info ax',
'ccc': 'message-info ccc',
'yY': 'yank -s',
'0': 'message-info 0',
'1': 'message-info 1'},
'command': {'foo': 'message-info bar',
'<Ctrl+X>': 'message-info ctrlx'},
'normal': {'a': 'message-info a', 'ba': 'message-info ba'}}
MAPPINGS = {
'x': 'a',
'b': 'a',
}
@pytest.fixture
def keyinput_bindings(config_stub, key_config_stub):
"""Register some test bindings."""
config_stub.val.bindings.default = {}
config_stub.val.bindings.commands = dict(BINDINGS)
config_stub.val.bindings.key_mappings = dict(MAPPINGS)
@pytest.fixture
def pyqt_enum_workaround():
"""Get a context manager to ignore invalid key errors and skip the test.
WORKAROUND for
https://www.riverbankcomputing.com/pipermail/pyqt/2022-April/044607.html
"""
@contextlib.contextmanager
def _pyqt_enum_workaround(exctype=keyutils.InvalidKeyError):
try:
yield
except exctype as e:
pytest.skip(f"PyQt enum workaround: {e}")
return _pyqt_enum_workaround
|