From 8c4ad696f66310aa884b3c5aef52865f40472a48 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 20 Aug 2021 14:02:03 -0400 Subject: [PATCH 1/2] TST: Check assertion not in callback Otherwise we ignore the failures --- lib/matplotlib/tests/test_backend_qt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_backend_qt.py b/lib/matplotlib/tests/test_backend_qt.py index 044e720c3e76..d0053aeb8b1f 100644 --- a/lib/matplotlib/tests/test_backend_qt.py +++ b/lib/matplotlib/tests/test_backend_qt.py @@ -107,6 +107,8 @@ def CustomHandler(signum, frame): ('Key_Alt', ['ControlModifier'], 'ctrl+alt'), ('Key_Aacute', ['ControlModifier', 'AltModifier', 'MetaModifier'], 'ctrl+alt+super+\N{LATIN SMALL LETTER A WITH ACUTE}'), + # We do not currently map the media keys, this may change in the + # future. This means the callback will never fire ('Key_Play', [], None), ('Key_Backspace', [], 'backspace'), ('Key_Backspace', ['ControlModifier'], 'ctrl+backspace'), @@ -142,6 +144,7 @@ def test_correct_key(backend, qt_core, qt_key, qt_mods, answer): Assert sent and caught keys are the same. """ from matplotlib.backends.qt_compat import _enum, _to_int + result = None qt_mod = _enum("QtCore.Qt.KeyboardModifier").NoModifier for mod in qt_mods: qt_mod |= getattr(_enum("QtCore.Qt.KeyboardModifier"), mod) @@ -152,11 +155,13 @@ def key(self): return _to_int(getattr(_enum("QtCore.Qt.Key"), qt_key)) def modifiers(self): return qt_mod def on_key_press(event): - assert event.key == answer + nonlocal result + result = event.key qt_canvas = plt.figure().canvas qt_canvas.mpl_connect('key_press_event', on_key_press) qt_canvas.keyPressEvent(_Event()) + assert result == answer @pytest.mark.backend('QtAgg', skip_on_importerror=True) From 86be6bce182b71d109e1a422a3808290045a4224 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 20 Aug 2021 14:23:21 -0400 Subject: [PATCH 2/2] FIX: match the expected answer to actual result. As part of a4c504c00d1c6d026049d8174f4aa23c1a57f490 the modified was changed from SuperModifer to MetaModifier. Under the new scheme of testing the keys we were correctly noting that SuperModifier is not in the Qt Modifier enum (the super keys come in through "SpecialKeys"). However, because the failures were happening in a callback and being ignored, we did not notice this change. It is likely that this test never worked for the same reason. --- lib/matplotlib/tests/test_backend_qt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_backend_qt.py b/lib/matplotlib/tests/test_backend_qt.py index d0053aeb8b1f..80a2cc7533a5 100644 --- a/lib/matplotlib/tests/test_backend_qt.py +++ b/lib/matplotlib/tests/test_backend_qt.py @@ -106,7 +106,7 @@ def CustomHandler(signum, frame): ('Key_Control', ['AltModifier'], 'alt+control'), ('Key_Alt', ['ControlModifier'], 'ctrl+alt'), ('Key_Aacute', ['ControlModifier', 'AltModifier', 'MetaModifier'], - 'ctrl+alt+super+\N{LATIN SMALL LETTER A WITH ACUTE}'), + 'ctrl+alt+meta+\N{LATIN SMALL LETTER A WITH ACUTE}'), # We do not currently map the media keys, this may change in the # future. This means the callback will never fire ('Key_Play', [], None),