@pytest.mark.parametrize('qt_key, qt_mods, answer', [('Key_A', ['ShiftModifier'], 'A'), ('Key_A', [], 'a'), ('Key_A', ['ControlModifier'], 'ctrl+a'), ('Key_Aacute', ['ShiftModifier'], 'Á'), ('Key_Aacute', [], 'á'), ('ControlKey', ['AltModifier'], 'alt+control'), ('AltKey', ['ControlModifier'], 'ctrl+alt'), ('Key_Aacute', ['ControlModifier', 'AltModifier', 'SuperModifier'], 'ctrl+alt+super+á'), ('Key_Backspace', [], 'backspace'), ('Key_Backspace', ['ControlModifier'], 'ctrl+backspace'), ('Key_Play', [], None)], indirect=['qt_key', 'qt_mods'], ids=['shift', 'lower', 'control', 'unicode_upper', 'unicode_lower', 'alt_control', 'control_alt', 'modifier_order', 'backspace', 'backspace_mod', 'non_unicode_key'])
@pytest.mark.parametrize('backend', [pytest.param('Qt4Agg', marks=pytest.mark.backend('Qt4Agg')), pytest.param('Qt5Agg', marks=pytest.mark.backend('Qt5Agg'))])
def test_correct_key(backend, qt_key, qt_mods, answer):
    '\n    Make a figure\n    Send a key_press_event event (using non-public, qtX backend specific api)\n    Catch the event\n    Assert sent and caught keys are the same\n    '
    qt_canvas = plt.figure().canvas
    event = mock.Mock()
    event.isAutoRepeat.return_value = False
    event.key.return_value = qt_key
    event.modifiers.return_value = qt_mods

    def receive(event):
        assert (event.key == answer)
    qt_canvas.mpl_connect('key_press_event', receive)
    qt_canvas.keyPressEvent(event)
Make a figure
Send a key_press_event event (using non-public, qtX backend specific api)
Catch the event
Assert sent and caught keys are the same
@pytest.mark.parametrize('qt_key, qt_mods, answer', [('Key_A', ['ShiftModifier'], 'A'), ('Key_A', [], 'a'), ('Key_A', ['ControlModifier'], 'ctrl+a'), ('Key_Aacute', ['ShiftModifier'], 'Á'), ('Key_Aacute', [], 'á'), ('ControlKey', ['AltModifier'], 'alt+control'), ('AltKey', ['ControlModifier'], 'ctrl+alt'), ('Key_Aacute', ['ControlModifier', 'AltModifier', 'SuperModifier'], 'ctrl+alt+super+á'), ('Key_Backspace', [], 'backspace'), ('Key_Backspace', ['ControlModifier'], 'ctrl+backspace'), ('Key_Play', [], None)], indirect=['qt_key', 'qt_mods'], ids=['shift', 'lower', 'control', 'unicode_upper', 'unicode_lower', 'alt_control', 'control_alt', 'modifier_order', 'backspace', 'backspace_mod', 'non_unicode_key'])
@pytest.mark.parametrize('backend', [pytest.param('Qt4Agg', marks=pytest.mark.backend('Qt4Agg')), pytest.param('Qt5Agg', marks=pytest.mark.backend('Qt5Agg'))])
def test_correct_key(backend, qt_key, qt_mods, answer):
    '\n    Make a figure\n    Send a key_press_event event (using non-public, qtX backend specific api)\n    Catch the event\n    Assert sent and caught keys are the same\n    '
    qt_canvas = plt.figure().canvas
    event = mock.Mock()
    event.isAutoRepeat.return_value = False
    event.key.return_value = qt_key
    event.modifiers.return_value = qt_mods

    def receive(event):
        assert (event.key == answer)
    qt_canvas.mpl_connect('key_press_event', receive)
    qt_canvas.keyPressEvent(event)