8000 Parametrize Qt key tests. · adrn/matplotlib@58624ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 58624ff

Browse files
committed
Parametrize Qt key tests.
1 parent 476be29 commit 58624ff

File tree

2 files changed

+68
-159
lines changed

2 files changed

+68
-159
lines changed
Lines changed: 34 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
import six
5-
from six import unichr
64
from matplotlib import pyplot as plt
75
from matplotlib.testing.decorators import cleanup, switch_backend
86
from matplotlib._pylab_helpers import Gcf
@@ -54,8 +52,41 @@ def test_fig_close():
5452
assert(init_figs == Gcf.figs)
5553

5654

55+
@pytest.mark.parametrize(
56+
'qt_key, qt_mods, answer',
57+
[
58+
(QtCore.Qt.Key_A, ShiftModifier, 'A'),
59+
(QtCore.Qt.Key_A, QtCore.Qt.NoModifier, 'a'),
60+
(QtCore.Qt.Key_A, ControlModifier, 'ctrl+a'),
61+
(QtCore.Qt.Key_Aacute, ShiftModifier,
62+
'\N{LATIN CAPITAL LETTER A WITH ACUTE}'),
63+
(QtCore.Qt.Key_Aacute, QtCore.Qt.NoModifier,
64+
'\N{LATIN SMALL LETTER A WITH ACUTE}'),
65+
(ControlKey, AltModifier, 'alt+control'),
66+
(AltKey, ControlModifier, 'ctrl+alt'),
67+
(QtCore.Qt.Key_Aacute, (ControlModifier | AltModifier | SuperModifier),
68+
'ctrl+alt+super+\N{LATIN SMALL LETTER A WITH ACUTE}'),
69+
(QtCore.Qt.Key_Backspace, QtCore.Qt.NoModifier, 'backspace'),
70+
(QtCore.Qt.Key_Backspace, ControlModifier, 'ctrl+backspace'),
71+
(QtCore.Qt.Key_Play, QtCore.Qt.NoModifier, None),
72+
],
73+
ids=[
74+
'shift',
75+
'lower',
76+
'control',
77+
'unicode_upper',
78+
'unicode_lower',
79+
'alt_control',
80+
'control_alt',
81+
'modifier_order',
82+
'backspace',
83+
'backspace_mod',
84+
'non_unicode_key',
85+
]
86+
)
87+
@cleanup
5788
@switch_backend('Qt4Agg')
58-
def assert_correct_key(qt_key, qt_mods, answer):
89+
def test_correct_key(qt_key, qt_mods, answer):
5990
"""
6091
Make a figure
6192
Send a key_press_event event (using non-public, qt4 backend specific api)
@@ -74,80 +105,3 @@ def receive(event):
74105

75106
qt_canvas.mpl_connect('key_press_event', receive)
76107
qt_canvas.keyPressEvent(event)
77-
78-
79-
@cleanup
80-
def test_shift():
81-
assert_correct_key(QtCore.Qt.Key_A,
82-
ShiftModifier,
83-
'A')
84-
85-
86-
@cleanup
87-
def test_lower():
88-
assert_correct_key(QtCore.Qt.Key_A,
89-
QtCore.Qt.NoModifier,
90-
'a')
91-
92-
93-
@cleanup
94-
def test_control():
95-
assert_correct_key(QtCore.Qt.Key_A,
96-
ControlModifier,
97-
'ctrl+a')
98-
99-
100-
@cleanup
101-
def test_unicode_upper():
102-
assert_correct_key(QtCore.Qt.Key_Aacute,
103-
ShiftModifier,
104-
unichr(193))
105-
106-
107-
@cleanup
108-
def test_unicode_lower():
109-
assert_correct_key(QtCore.Qt.Key_Aacute,
110-
QtCore.Qt.NoModifier,
111-
unichr(225))
112-
113-
114-
@cleanup
115-
def test_alt_control():
116-
assert_correct_key(ControlKey,
117-
AltModifier,
118-
'alt+control')
119-
120-
121-
@cleanup
122-
def test_control_alt():
123-
assert_correct_key(AltKey,
124-
ControlModifier,
125-
'ctrl+alt')
126-
127-
128-
@cleanup
129-
def test_modifier_order():
130-
assert_correct_key(QtCore.Qt.Key_Aacute,
131-
(ControlModifier | AltModifier | SuperModifier),
132-
'ctrl+alt+super+' + unichr(225))
133-
134-
135-
@cleanup
136-
def test_backspace():
137-
assert_correct_key(QtCore.Qt.Key_Backspace,
138-
QtCore.Qt.NoModifier,
139-
'backspace')
140-
141-
142-
@cleanup
143-
def test_backspace_mod():
144-
assert_correct_key(QtCore.Qt.Key_Backspace,
145-
ControlModifier,
146-
'ctrl+backspace')
147-
148-
149-
@cleanup
150-
def test_non_unicode_key():
151-
assert_correct_key(QtCore.Qt.Key_Play,
152-
QtCore.Qt.NoModifier,
153-
None)
Lines changed: 34 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
3-
import six
43

54
from matplotlib import pyplot as plt
65
from matplotlib.testing.decorators import cleanup, switch_backend
@@ -46,8 +45,41 @@ def test_fig_close():
4645
assert(init_figs == Gcf.figs)
4746

4847

48+
@pytest.mark.parametrize(
49+
'qt_key, qt_mods, answer',
50+
[
51+
(QtCore.Qt.Key_A, ShiftModifier, 'A'),
52+
(QtCore.Qt.Key_A, QtCore.Qt.NoModifier, 'a'),
53+
(QtCore.Qt.Key_A, ControlModifier, 'ctrl+a'),
54+
(QtCore.Qt.Key_Aacute, ShiftModifier,
55+
'\N{LATIN CAPITAL LETTER A WITH ACUTE}'),
56+
(QtCore.Qt.Key_Aacute, QtCore.Qt.NoModifier,
57+
'\N{LATIN SMALL LETTER A WITH ACUTE}'),
58+
(ControlKey, AltModifier, 'alt+control'),
59+
(AltKey, ControlModifier, 'ctrl+alt'),
60+
(QtCore.Qt.Key_Aacute, (ControlModifier | AltModifier | SuperModifier),
61+
'ctrl+alt+super+\N{LATIN SMALL LETTER A WITH ACUTE}'),
62+
(QtCore.Qt.Key_Backspace, QtCore.Qt.NoModifier, 'backspace'),
63+
(QtCore.Qt.Key_Backspace, ControlModifier, 'ctrl+backspace'),
64+
(QtCore.Qt.Key_Play, QtCore.Qt.NoModifier, None),
65+
],
66+
ids=[
67+
'shift',
68+
'lower',
69+
'control',
70+
'unicode_upper',
71+
'unicode_lower',
72+
'alt_control',
73+
'control_alt',
74+
'modifier_order',
75+
'backspace',
76+
'backspace_mod',
77+
'non_unicode_key',
78+
]
79+
)
80+
@cleanup
4981
@switch_backend('Qt5Agg')
50-
def assert_correct_key(qt_key, qt_mods, answer):
82+
def test_correct_key(qt_key, qt_mods, answer):
5183
"""
5284
Make a figure
5385
Send a key_press_event event (using non-public, qt5 backend specific api)
@@ -66,80 +98,3 @@ def receive(event):
6698

6799
qt_canvas.mpl_connect('key_press_event', receive)
68100
qt_canvas.keyPressEvent(event)
69-
70-
71-
@cleanup
72-
def test_shift():
73-
assert_correct_key(QtCore.Qt.Key_A,
74-
ShiftModifier,
75-
'A')
76-
77-
78-
@cleanup
79-
def test_lower():
80-
assert_correct_key(QtCore.Qt.Key_A,
81-
QtCore.Qt.NoModifier,
82-
'a')
83-
84-
85-
@cleanup
86-
def test_control():
87-
assert_correct_key(QtCore.Qt.Key_A,
88-
ControlModifier,
89-
'ctrl+a')
90-
91-
92-
@cleanup
93-
def test_unicode_upper():
94-
assert_correct_key(QtCore.Qt.Key_Aacute,
95-
ShiftModifier,
96-
six.unichr(193))
97-
98-
99-
@cleanup
100-
def test_unicode_lower():
101-
assert_correct_key(QtCore.Qt.Key_Aacute,
102-
QtCore.Qt.NoModifier,
103-
six.unichr(225))
104-
105-
106-
@cleanup
107-
def test_alt_control():
108-
assert_correct_key(ControlKey,
109-
AltModifier,
110-
'alt+control')
111-
112-
113-
@cleanup
114-
def test_control_alt():
115-
assert_correct_key(AltKey,
116-
ControlModifier,
117-
'ctrl+alt')
118-
119-
120-
@cleanup
121-
def test_modifier_order():
122-
assert_correct_key(QtCore.Qt.Key_Aacute,
123-
(ControlModifier | AltModifier | SuperModifier),
124-
'ctrl+alt+super+' + six.unichr(225))
125-
126-
127-
@cleanup
128-
def test_backspace():
129-
assert_correct_key(QtCore.Qt.Key_Backspace,
130-
QtCore.Qt.NoModifier,
131-
'backspace')
132-
133-
134-
@cleanup
135-
def test_backspace_mod():
136-
assert_correct_key(QtCore.Qt.Key_Backspace,
137-
ControlModifier,
138-
'ctrl+backspace')
139-
140-
141-
@cleanup
142-
def test_non_unicode_key():
143-
assert_correct_key(QtCore.Qt.Key_Play,
144-
QtCore.Qt.NoModifier,
145-
None)

0 commit comments

Comments
 (0)
0