silx.test:

silx.test

This package provides access to the full silx test suite.

It is possible to disable tests depending on Qt by setting silx.test.utils.test_options.WITH_QT_TEST = False It will skip all tests from silx.test.gui.

run_tests()[source]

Run test complete test_suite

silx.test.utils

Utilities for writing tests.

  • temp_dir() provides a with context to create/delete a temporary directory.
utilstest = <silx.resources.ExternalResources object>

This is the instance to be used. Singleton-like feature provided by module

test_options = <silx.test.utils._TestOptions object>

Singleton providing configuration information for all the tests

temp_dir(*args, **kwds)[source]

with context providing a temporary directory.

>>> import os.path
>>> with temp_dir() as tmp:
...     print(os.path.isdir(tmp))  # Use tmp directory
add_gaussian_noise(y, stdev=1.0, mean=0.0)[source]

Add random gaussian noise to synthetic data.

Parameters:
  • y (ndarray) – Array of synthetic data
  • mean (float) – Mean of the gaussian distribution of noise.
  • stdev (float) – Standard deviation of the gaussian distribution of noise.
Returns:

Array of data with noise added

add_poisson_noise(y)[source]

Add random noise from a poisson distribution to synthetic data.

Parameters:y (ndarray) – Array of synthetic data
Returns:Array of data with noise added
add_relative_noise(y, max_noise=5.0)[source]

Add relative random noise to synthetic data. The maximum noise level is given in percents.

An array of noise in the interval [-max_noise, max_noise] (continuous uniform distribution) is generated, and applied to the data the following way:

\(yn = y * (1. + noise / 100.)\)

Parameters:
  • y (ndarray) – Array of synthetic data
  • max_noise (float) – Maximum percentage of noise
Returns:

Array of data with noise added

silx.gui.utils.testutils

Helper class to write Qt widget unittests.

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 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.

All keyboard and mouse event simulation methods call qWait(20) after simulating the event (as QTest does on Mac OSX). This was introduced to fix issues with continuous integration tests running with Xvfb on Linux.

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

classmethod tearDownClass()[source]

Hook method for deconstructing the class fixture after running all tests in the class.

setUp()[source]

Get the list of existing widgets.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

qapp

The QApplication currently running.

Press = PySide2.QtTest.QTest.KeyAction.Press

Key press action code

Release = PySide2.QtTest.QTest.KeyAction.Release

Key release action code

Click = PySide2.QtTest.QTest.KeyAction.Click

Key click action code

QTest

The Qt QTest class from the used Qt binding.

keyClick(widget, key, modifier=PySide2.QtCore.Qt.KeyboardModifier.NoModifier, delay=-1)[source]

Simulate clicking a key.

See QTest.keyClick for details.

keyClicks(widget, sequence, modifier=PySide2.QtCore.Qt.KeyboardModifier.NoModifier, delay=-1)[source]

Simulate clicking a sequence of keys.

See QTest.keyClick for details.

keyEvent(action, widget, key, modifier=PySide2.QtCore.Qt.KeyboardModifier.NoModifier, delay=-1)[source]

Sends a Qt key event.

See QTest.keyEvent for details.

keyPress(widget, key, modifier=PySide2.QtCore.Qt.KeyboardModifier.NoModifier, delay=-1)[source]

Sends a Qt key press event.

See QTest.keyPress for details.

keyRelease(widget, key, modifier=PySide2.QtCore.Qt.KeyboardModifier.NoModifier, delay=-1)[source]

Sends a Qt key release event.

See QTest.keyRelease for details.

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

Simulate clicking a mouse button.

See QTest.mouseClick for details.

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

Simulate double clicking a mouse button.

See QTest.mouseDClick for details.

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

Simulate moving the mouse.

See QTest.mouseMove for details.

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

Simulate pressing a mouse button.

See QTest.mousePress for details.

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.

classmethod 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.

classmethod qWaitForDestroy(ref)[source]

Wait for Qt object destruction.

Use a weakref as parameter to avoid any strong references to the object.

It have to be used as following. Removing the reference to the object before calling the function looks to be expected, else deleteLater() will not work.

ref = weakref.ref(self.obj)
self.obj = None
self.qWaitForDestroy(ref)
Parameters:ref (weakref) – A weakref to an object to avoid any reference
Returns:True if the object was destroyed
Return type:bool
logScreenShot(level=40)[source]

Take a screenshot and log it into the logging system if the logger is enabled for the expected level.

The screenshot is stored in the directory “./build/test-debug”, and the logging system only log the path to this file.

Parameters:level – Logging level
class SignalListener[source]

Util to listen a Qt event and store parameters

clear()[source]

Clear stored data

callCount()[source]

Returns how many times the listener was called.

Return type:int
arguments(callIndex=None, argumentIndex=None)[source]

Returns positional arguments optionally filtered by call count id or argument index.

Parameters:
  • callIndex (int) – Index of the called data
  • argumentIndex (int) – Index of the positional argument.
karguments(callIndex=None, argumentName=None)[source]

Returns positional arguments optionally filtered by call count id or name of the keyword argument.

Parameters:
  • callIndex (int) – Index of the called data
  • argumentName (int) – Name of the keyword argument.
partial(*args, **kargs)[source]

Returns a new partial object which when called will behave like this listener called with the positional arguments args and keyword arguments keywords. If more arguments are supplied to the call, they are appended to args. If additional keyword arguments are supplied, they extend and override keywords.

getQToolButtonFromAction(action)[source]

Return a QToolButton corresponding to a QAction.

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