@@ -25,7 +25,7 @@ def result(*args, **kwargs):
2525 functools .update_wrapper (result , qtest_method )
2626 return staticmethod (result )
2727 else :
28- return None # pragma: no cover
28+ return None # pragma: no cover
2929
3030 # inject methods from QTest into QtBot
3131 method_names = [
@@ -54,15 +54,16 @@ def result(*args, **kwargs):
5454
5555@_inject_qtest_methods
5656class QtBot (object ):
57+
5758 """
58- Instances of this class are responsible for sending events to `Qt` objects (usually widgets),
59- simulating user input.
60-
61- .. important:: Instances of this class should be accessed only by using a ``qtbot`` fixture,
59+ Instances of this class are responsible for sending events to `Qt` objects (usually widgets),
60+ simulating user input.
61+
62+ .. important:: Instances of this class should be accessed only by using a ``qtbot`` fixture,
6263 never instantiated directly.
63-
64+
6465 **Widgets**
65-
66+
6667 .. automethod:: addWidget
6768 .. automethod:: waitForWindowShown
6869 .. automethod:: stopForInteraction
@@ -72,155 +73,150 @@ class QtBot(object):
7273 .. automethod:: waitSignal
7374
7475 **Raw QTest API**
75-
76+
7677 Methods below provide very low level functions, as sending a single mouse click or a key event.
7778 Thos methods are just forwarded directly to the `QTest API`_. Consult the documentation for more
7879 information.
79-
80+
8081 ---
81-
82+
8283 Below are methods used to simulate sending key events to widgets:
83-
84+
8485 .. staticmethod:: keyPress(widget, key[, modifier=Qt.NoModifier[, delay=-1]])
8586 .. staticmethod:: keyClick (widget, key[, modifier=Qt.NoModifier[, delay=-1]])
8687 .. staticmethod:: keyClicks (widget, key sequence[, modifier=Qt.NoModifier[, delay=-1]])
8788 .. staticmethod:: keyEvent (action, widget, key[, modifier=Qt.NoModifier[, delay=-1]])
8889 .. staticmethod:: keyPress (widget, key[, modifier=Qt.NoModifier[, delay=-1]])
8990 .. staticmethod:: keyRelease (widget, key[, modifier=Qt.NoModifier[, delay=-1]])
90-
91+
9192 Sends one or more keyword events to a widget.
92-
93+
9394 :param QWidget widget: the widget that will receive the event
94-
95+
9596 :param str|int key: key to send, it can be either a Qt.Key_* constant or a single character string.
96-
97+
9798 .. _keyboard modifiers:
98-
99+
99100 :param Qt.KeyboardModifier modifier: flags OR'ed together representing other modifier keys
100101 also pressed. Possible flags are:
101-
102+
102103 * ``Qt.NoModifier``: No modifier key is pressed.
103104 * ``Qt.ShiftModifier``: A Shift key on the keyboard is pressed.
104105 * ``Qt.ControlModifier``: A Ctrl key on the keyboard is pressed.
105106 * ``Qt.AltModifier``: An Alt key on the keyboard is pressed.
106107 * ``Qt.MetaModifier``: A Meta key on the keyboard is pressed.
107108 * ``Qt.KeypadModifier``: A keypad button is pressed.
108109 * ``Qt.GroupSwitchModifier``: X11 only. A Mode_switch key on the keyboard is pressed.
109-
110+
110111 :param int delay: after the event, delay the test for this miliseconds (if > 0).
111-
112-
112+
113+
113114 .. staticmethod:: keyToAscii (key)
114-
115+
115116 Auxilliary method that converts the given constant ot its equivalent ascii.
116-
117+
117118 :param Qt.Key_* key: one of the constants for keys in the Qt namespace.
118-
119- :return type: str
119+
120+ :return type: str
120121 :returns: the equivalent character string.
121122
122123 .. note:: this method is not available in PyQt.
123-
124+
124125 ---
125-
126+
126127 Below are methods used to simulate sending mouse events to widgets.
127-
128+
128129 .. staticmethod:: mouseClick (widget, button[, stateKey=0[, pos=QPoint()[, delay=-1]]])
129130 .. staticmethod:: mouseDClick (widget, button[, stateKey=0[, pos=QPoint()[, delay=-1]]])
130131 .. staticmethod:: mouseEvent (action, widget, button, stateKey, pos[, delay=-1])
131132 .. staticmethod:: mouseMove (widget[, pos=QPoint()[, delay=-1]])
132133 .. staticmethod:: mousePress (widget, button[, stateKey=0[, pos=QPoint()[, delay=-1]]])
133134 .. staticmethod:: mouseRelease (widget, button[, stateKey=0[, pos=QPoint()[, delay=-1]]])
134-
135+
135136 Sends a mouse moves and clicks to a widget.
136-
137+
137138 :param QWidget widget: the widget that will receive the event
138-
139- :param Qt.MouseButton button: flags OR'ed together representing the button pressed.
139+
140+ :param Qt.MouseButton button: flags OR'ed together representing the button pressed.
140141 Possible flags are:
141-
142+
142143 * ``Qt.NoButton``: The button state does not refer to any button (see QMouseEvent.button()).
143144 * ``Qt.LeftButton``: The left button is pressed, or an event refers to the left button. (The left button may be the right button on left-handed mice.)
144145 * ``Qt.RightButton``: The right button.
145146 * ``Qt.MidButton``: The middle button.
146147 * ``Qt.MiddleButton``: The middle button.
147148 * ``Qt.XButton1``: The first X button.
148149 * ``Qt.XButton2``: The second X button.
149-
150+
150151 :param Qt.KeyboardModifier modifier: flags OR'ed together representing other modifier keys
151152 also pressed. See `keyboard modifiers`_.
152-
153+
153154 :param QPoint position: position of the mouse pointer.
154-
155+
155156 :param int delay: after the event, delay the test for this miliseconds (if > 0).
156-
157-
157+
158+
158159 .. _QTest API: http://doc.qt.digia.com/4.8/qtest.html
159-
160+
160161 """
161-
162+
162163 def __init__ (self , app ):
163164 """
164- :param QApplication app:
165+ :param QApplication app:
165166 The current QApplication instance.
166167 """
167168 self ._app = app
168169 self ._widgets = []
169-
170-
170+
171171 def _close (self ):
172172 """
173173 Clear up method. Called at the end of each test that uses a ``qtbot`` fixture.
174174 """
175175 for w in self ._widgets :
176176 w .close ()
177177 self ._widgets [:] = []
178-
179-
178+
180179 def addWidget (self , widget ):
181180 """
182181 Adds a widget to be tracked by this bot. This is not required, but will ensure that the
183182 widget gets closed by the end of the test, so it is highly recommended.
184-
185- :param QWidget widget:
183+
184+ :param QWidget widget:
186185 Widget to keep track of.
187186 """
188187 self ._widgets .append (widget )
189-
190-
188+
191189 def waitForWindowShown (self , widget ):
192190 """
193- Waits until the window is shown in the screen. This is mainly useful for asynchronous
194- systems like X11, where a window will be mapped to screen some time after being asked to
195- show itself on the screen.
196-
191+ Waits until the window is shown in the screen. This is mainly useful for asynchronous
192+ systems like X11, where a window will be mapped to screen some time after being asked to
193+ show itself on the screen.
194+
197195 :param QWidget widget:
198196 Widget to wait on.
199197 """
200198 QtTest .QTest .qWaitForWindowShown (widget )
201-
202-
199+
203200 def stopForInteraction (self ):
204201 """
205202 Stops the current test flow, letting the user interact with any visible widget.
206-
203+
207204 This is mainly useful so that you can verify the current state of the program while writing
208205 tests.
209-
206+
210207 Closing the windows should resume the test run, with ``qtbot`` attempting to restore visibility
211208 of the widgets as they were before this call.
212209
213210 .. note:: As a convenience, it is also aliased as `stop`.
214211 """
215212 widget_visibility = [widget .isVisible () for widget in self ._widgets ]
216-
217- self ._app .exec_ ()
213+
214+ self ._app .exec_ ()
218215
219216 for index , visible in enumerate (widget_visibility ):
220217 widget = self ._widgets [index ]
221218 widget .setVisible (visible )
222219
223-
224220 stop = stopForInteraction
225221
226222 def waitSignal (self , signal = None , timeout = 1000 ):
@@ -251,7 +247,7 @@ def waitSignal(self, signal=None, timeout=1000):
251247 ``SignalBlocker`` object. Call ``SignalBlocker.wait()`` to wait.
252248
253249 .. note::
254- Cannot have both ``signals`` and ``timeout`` equal ``None``, or
250+ Cannot have both ``signals`` and ``timeout`` equal ``None``, or
255251 else you will block indefinitely. We throw an error if this occurs.
256252
257253 """
@@ -262,6 +258,7 @@ def waitSignal(self, signal=None, timeout=1000):
262258
263259
264260class SignalBlocker (object ):
261+
265262 """
266263 Returned by :meth:`QtBot.waitSignal` method.
267264
@@ -373,8 +370,8 @@ def qapp():
373370@pytest .yield_fixture
374371def qtbot (qapp ):
375372 """
376- Fixture used to create a QtBot instance for using during testing.
377-
373+ Fixture used to create a QtBot instance for using during testing.
374+
378375 Make sure to call addWidget for each top-level widget you create to ensure
379376 that they are properly closed after the test ends.
380377 """
@@ -386,4 +383,3 @@ def qtbot(qapp):
386383 pytest .fail (format_captured_exceptions (exceptions ))
387384
388385 result ._close ()
389-
0 commit comments