Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b3c39f

Browse files
committed
TST: make the qt key tests match what OSX does
Due to some re-(re)-mapping of the modifier keys by the OSX keyboard, then by Qt, and then by us there is an inconsistency between the platforms. This change to the tests encodes what the Qt on OSX currently does (and to our understand have always done).
1 parent 27fa740 commit 2b3c39f

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,33 @@ def custom_handler(signum, frame):
166166

167167

168168
@pytest.mark.parametrize(
169-
'qt_key, qt_mods, answer',
169+
"qt_key, qt_mods, answer",
170170
[
171-
('Key_A', ['ShiftModifier'], 'A'),
172-
('Key_A', [], 'a'),
173-
('Key_A', ['ControlModifier'], 'ctrl+a'),
174-
('Key_Aacute', ['ShiftModifier'],
175-
'\N{LATIN CAPITAL LETTER A WITH ACUTE}'),
176-
('Key_Aacute', [],
177-
'\N{LATIN SMALL LETTER A WITH ACUTE}'),
178-
('Key_Control', ['AltModifier'], 'alt+control'),
179-
('Key_Alt', ['ControlModifier'], 'ctrl+alt'),
180-
('Key_Aacute', ['ControlModifier', 'AltModifier', 'MetaModifier'],
181-
'ctrl+alt+meta+\N{LATIN SMALL LETTER A WITH ACUTE}'),
171+
("Key_A", ["ShiftModifier"], "A"),
172+
("Key_A", [], "a"),
173+
("Key_A", ["ControlModifier"], ("ctrl+a")),
174+
(
175+
"Key_Aacute",
176+
["ShiftModifier"],
177+
"\N{LATIN CAPITAL LETTER A WITH ACUTE}",
178+
),
179+
("Key_Aacute", [], "\N{LATIN SMALL LETTER A WITH ACUTE}"),
180+
("Key_Control", ["AltModifier"], ("alt+control")),
181+
("Key_Alt", ["ControlModifier"], "ctrl+alt"),
182+
(
183+
"Key_Aacute",
184+
["ControlModifier", "AltModifier", "MetaModifier"],
185+
("ctrl+alt+meta+\N{LATIN SMALL LETTER A WITH ACUTE}"),
186+
),
182187
# We do not currently map the media keys, this may change in the
183188
# future. This means the callback will never fire
184-
('Key_Play', [], None),
185-
('Key_Backspace', [], 'backspace'),
186-
('Key_Backspace', ['ControlModifier'], 'ctrl+backspace'),
189+
("Key_Play", [], None),
190+
("Key_Backspace", [], "backspace"),
191+
(
192+
"Key_Backspace",
193+
["ControlModifier"],
194+
"ctrl+backspace",
195+
),
187196
],
188197
ids=[
189198
'shift',
@@ -216,6 +225,11 @@ def test_correct_key(backend, qt_core, qt_key, qt_mods, answer):
216225
Assert sent and caught keys are the same.
217226
"""
218227
from matplotlib.backends.qt_compat import _enum, _to_int
228+
229+
if sys.platform == "darwin" and answer is not None:
230+
answer = answer.replace("ctrl", "cmd")
231+
answer = answer.replace("control", "cmd")
232+
answer = answer.replace("meta", "ctrl")
219233
result = None
220234
qt_mod = _enum("QtCore.Qt.KeyboardModifier").NoModifier
221235
for mod in qt_mods:

0 commit comments

Comments
 (0)