testutils: Qt test utilities

Helper class to write Qt widget unittests.

silx.gui.testutils.qWaitForWindowExposed(window, timeout=None)[source]

Mimic QTest.qWaitForWindowExposed for Qt4.

silx.gui.testutils.qWaitForWindowExposedAndActivate(window, timeout=None)[source]

Waits until the window is shown in the screen.

It also activates the window and raises it.

See QTest.qWaitForWindowExposed for details.

class silx.gui.testutils.TestCaseQt(methodName='runTest')[source]

Base class to write test for Qt stuff.

It creates a QApplication before running the tests. WARNING: The QApplication is shared by all tests, which might have side effects.

After each test, this class is checking for widgets remaining alive. To allow some widgets to remain alive at the end of a test, set the allowedLeakingWidgets attribute to the number of widgets that can remain alive at the end of the test. With PySide, this test is not run for now as it seems PySide is leaking widgets internally.

DEFAULT_TIMEOUT_WAIT = 100

Default timeout for qWait

TIMEOUT_WAIT = 0

Extra timeout in millisecond to add to qSleep, qWait and qWaitForWindowExposed.

Intended purpose is for debugging, to add extra time to waits in order to allow to view the tested widgets.

classmethod setUpClass()[source]

Makes sure Qt is inited

setUp()[source]

Get the list of existing widgets.

tearDown()[source]

Test fixture checking that no more widgets exists.

qapp[source]

The QApplication currently running.

Press = 0

Key press action code

Release = 1

Key release action code

Click = 2

Key click action code

QTest

The Qt QTest class from the used Qt binding.

static keyClick(widget, key, modifier=0, delay=-1)[source]

Simulate clicking a key.

See QTest.keyClick for details.

static keyClicks(widget, sequence, modifier=0, delay=-1)[source]

Simulate clicking a sequence of keys.

See QTest.keyClick for details.

static keyEvent(action, widget, key, modifier=0, delay=-1)[source]

Sends a Qt key event.

See QTest.keyEvent for details.

static keyPress(widget, key, modifier=0, delay=-1)[source]

Sends a Qt key press event.

See QTest.keyPress for details.

static keyRelease(widget, key, modifier=0, delay=-1)[source]

Sends a Qt key release event.

See QTest.keyRelease for details.

static mouseClick(widget, button, modifier=None, pos=None, delay=-1)[source]

Simulate clicking a mouse button.

See QTest.mouseClick for details.

static mouseDClick(widget, button, modifier=None, pos=None, delay=-1)[source]

Simulate double clicking a mouse button.

See QTest.mouseDClick for details.

static mouseMove(widget, pos=None, delay=-1)[source]

Simulate moving the mouse.

See QTest.mouseMove for details.

static mousePress(widget, button, modifier=None, pos=None, delay=-1)[source]

Simulate pressing a mouse button.

See QTest.mousePress for details.

static mouseRelease(widget, button, modifier=None, pos=None, delay=-1)[source]

Simulate releasing a mouse button.

See QTest.mouseRelease for details.

qSleep(ms)[source]

Sleep for ms milliseconds, blocking the execution of the test.

See QTest.qSleep for details.

qWait(ms=None)[source]

Waits for ms milliseconds, events will be processed.

See QTest.qWait for details.

qWaitForWindowExposed(window, timeout=None)[source]

Waits until the window is shown in the screen.

See QTest.qWaitForWindowExposed for details.

silx.gui.testutils.getQToolButtonFromAction(action)[source]

Return a visible QToolButton corresponding to a QAction.

Parameters:action (QAction) – The QAction from which to get QToolButton.
Returns:A visible QToolButton associated to action or None.

Previous topic

console: IPython console widgets

Next topic

Using silx widgets in Qt Designer

This Page