schrodinger.test.qt_utils module

class schrodinger.test.qt_utils.SlotMockManager(q_object)[source]

Bases: object

A helper class to create slot mocks for every signal on an object.

Slots will be attributes with the same name as the signal.

Example:

class SomeObject(QtCore.QObject):

    changed = QtCore.pyqtSignal()

    def change(self):
        self.changed.emit()


my_obj = SomeObject()
some_object_slot_mgr = SlotMockManager(my_obj)

my_obj.change()
some_object_slot_mgr.changed.assert_called_once()
__init__(q_object)[source]

Create and connect slot mocks for each signal on q_object

Parameters

q_object (QtCore.QObject) – The object with signals

reset()[source]

Reset all of the slot mocks

assertSlotsCalledExclusive(*expected_slots)[source]

Check that only the specified slots were called

Example:

mgr = SlotMockManager(my_obj)
my_obj.emitChanged()  # emits "changed"
my_obj.emitCleared()  # emits "cleared"
mgr.assertSlotsCalledExclusive("changed", "cleared")
Parameters

expected_slots (str) – Name(s) of slots. Call with no arguments to assert that no slots were called.

schrodinger.test.qt_utils.mouse_press(widget, button=1, modifier=0, pos=None)[source]

Press a mouse button over a widget. (Note that this function only presses the mouse, it doesn’t release it to complete a click. Use mouse_click instead if you want a complete mouse click.)

Parameters
  • widget (QtWidgets.QWidget) – The widget to press the mouse on.

  • button (Qt.MouseButton) – The mouse button to press.

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the mouse press.

  • pos (QtCore.QPoint) – Where to press the mouse button. If None, the center of widget will be used.

schrodinger.test.qt_utils.mouse_release(widget, button=1, modifier=0, pos=None)[source]

Release a mouse button over a widget.

Parameters
  • widget (QtWidgets.QWidget) – The widget to release the mouse on.

  • button (Qt.MouseButton) – The mouse button to release.

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the mouse release.

  • pos (QtCore.QPoint) – Where to release the mouse button. If None, the center of widget will be used.

schrodinger.test.qt_utils.mouse_click(widget, button=1, modifier=0, pos=None)[source]

Click a mouse button on a widget.

Parameters
  • widget (QtWidgets.QWidget) – The widget to click the mouse on

  • button (Qt.MouseButton) – The mouse button to click

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the mouse click.

  • pos (QtCore.QPoint) – Where to click the mouse button. If None, the center of widget will be used.

schrodinger.test.qt_utils.mouse_double_click(widget, button=1, modifier=0, pos=None)[source]

Double-click a mouse button on a widget. Note that the widget will receive mouse press and release events for both clicks in addition to the double- click event.

Parameters
  • widget (QtWidgets.QWidget) – The widget to click the mouse on

  • button (Qt.MouseButton) – The mouse button to click

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the mouse clicks.

  • pos (QtCore.QPoint) – Where to click the mouse button. If None, the center of widget will be used.

schrodinger.test.qt_utils.mouse_click_on_cell(view, row=0, column=0, button=1, modifier=0)[source]

Click a mouse button on the specified cell of a view.

Parameters
  • widget (QtWidgets.QAbstractItemView) – The view to click the mouse on

  • row (int) – The row to click on.

  • column (int) – The column to click on.

  • button (Qt.MouseButton) – The mouse button to click

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the mouse click.

schrodinger.test.qt_utils.mouse_double_click_on_cell(view, row=0, column=0, button=1, modifier=0)[source]

Double-click a mouse button on the specified cell of a view.

Parameters
  • widget (QtWidgets.QAbstractItemView) – The view to click the mouse on

  • row (int) – The row to click on.

  • column (int) – The column to click on.

  • button (Qt.MouseButton) – The mouse button to click

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the mouse click.

schrodinger.test.qt_utils.mouse_click_on_index(view, index, button=1, modifier=0)[source]

Click a mouse button on the specified index of a view.

Parameters
  • widget (QtWidgets.QAbstractItemView) – The view to click the mouse on

  • index (QtCore.QModelIndex) – The index to click on.

  • button (Qt.MouseButton) – The mouse button to click

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the mouse click.

schrodinger.test.qt_utils.mouse_double_click_on_index(view, index, button=1, modifier=0)[source]

Double-click a mouse button on the specified index of a view.

Parameters
  • widget (QtWidgets.QAbstractItemView) – The view to click the mouse on

  • index (QtCore.QModelIndex) – The index to click on.

  • button (Qt.MouseButton) – The mouse button to click

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the mouse click.

schrodinger.test.qt_utils.mouse_move(widget, pos=None, buttons=0, modifier=0)[source]

Move the mouse over a widget.

Parameters
  • widget (QtWidgets.QWidget) – The widget to move the mouse over.

  • pos (QtCore.QPoint) – Where to move the mouse to. If None, the center of widget will be used.

  • buttons (Qt.MouseButtons) – Any mouse buttons to be held down during the move.

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys to be held down during the move.

schrodinger.test.qt_utils.mouse_drag(widget, from_pos, to_pos, button=1, modifier=0)[source]

Click and drag the mouse on a widget.

Parameters
  • widget (QtWidgets.QWidget) – The widget to click and drag on.

  • from_pos (QtCore.QPoint) – Where to press the mouse. If None, the center of widget will be used.

  • to_pos (QtCore.QPoint) – Where to release the mouse. If None, the center of widget will be used.

  • button (Qt.MouseButton) – The mouse button to click

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the click and drag.

schrodinger.test.qt_utils.mouse_drag_indices(view, from_index, to_index, button=1, modifier=0)[source]

Click and drag the mouse on a widget.

Parameters
  • widget (QtWidgets.QWidget) – The widget to click and drag on.

  • from_index (QtCore.QModelIndex) – The index to press the mouse on.

  • to_index (QtCore.QModelIndex) – The index to release the mouse on.

  • button (Qt.MouseButton) – The mouse button to click

  • modifier (Qt.KeyboardModifier) – Any keyboard modifier keys that should affect the click and drag.

schrodinger.test.qt_utils.key_press(widget, key, modifier=0)[source]

Send a key press to the specified widget. (Note that this function only presses the key, it doesn’t release it to complete a click. Use key_click instead if you want a complete key click.)

Parameters
  • widget (QtWidgets.QWidget) – The widget to send the key press to.

  • key (str or Qt.Key) – The key for the event.

  • modifier (Qt.KeyboardModifier) – Any keyboard modifiers that should affect the event.

schrodinger.test.qt_utils.key_release(widget, key, modifier=0)[source]

Send a key release to the specified widget.

Parameters
  • widget (QtWidgets.QWidget) – The widget to send the key release to.

  • key (str or Qt.Key) – The key for the event.

  • modifier (Qt.KeyboardModifier) – Any keyboard modifiers that should affect the event.

schrodinger.test.qt_utils.key_click(widget, key, modifier=0)[source]

Send a key click to the specified widget.

Parameters
  • widget (QtWidgets.QWidget) – The widget to send the key click to.

  • key (str or Qt.Key) – The key for the event.

  • modifier (Qt.KeyboardModifier) – Any keyboard modifiers that should affect the event.

schrodinger.test.qt_utils.key_clicks(widget, keys, modifier=0)[source]

Send multiple key clicks to the specified widget.

Parameters
  • widget (QtWidgets.QWidget) – The widget to send the key clicks to.

  • key (Iterable(str or Qt.Key)) – The keys to send.

  • modifier (Qt.KeyboardModifier) – Any keyboard modifiers that should affect the events.