silx.test:

silx.test

Full silx test suite.

It is possible to disable tests depending on Qt by setting WITH_QT_TEST environment variable to ‘False’. It will skip all tests from silx.test.gui.

silx.test.run_tests()[source]

Run test complete test_suite

silx.test.utils

Utilities for writting tests.

  • ParametricTestCase provides a TestCase.subTest() replacement for Python < 3.4
  • TestLogging with context or the test_logging() decorator enables testing the number of logging messages of different levels.
  • temp_dir() provides a with context to create/delete a temporary directory.
class silx.test.utils.ParametricTestCase(methodName='runTest')[source]

TestCase with subTest support for Python < 3.4.

Add subTest method to support parametric tests. API is the same, but behavior differs: If a subTest fails, the following ones are not run.

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

Use as unittest.TestCase.subTest method in Python >= 3.4.

class silx.test.utils.TestLogging(logger=None, critical=None, error=None, warning=None, info=None, debug=None, notset=None)[source]

Context checking the number of logging messages from a specified Logger.

It disables propagation of logging message while running.

This is meant to be used as a with statement, for example:

>>> with TestLogging(logger, error=2, warning=0):
>>>     pass  # Run tests here expecting 2 ERROR and no WARNING from logger
...
Parameters:
  • logger (str or logging.Logger) – Name or instance of the logger to test. (Default: root logger)
  • critical (int) – Expected number of CRITICAL messages. Default: Do not check.
  • error (int) – Expected number of ERROR messages. Default: Do not check.
  • warning (int) – Expected number of WARNING messages. Default: Do not check.
  • info (int) – Expected number of INFO messages. Default: Do not check.
  • debug (int) – Expected number of DEBUG messages. Default: Do not check.
  • notset (int) – Expected number of NOTSET messages. Default: Do not check.
Raises RuntimeError:
 

If the message counts are the expected ones.

emit(record)[source]

Override logging.Handler.emit()

silx.test.utils.test_logging(logger=None, critical=None, error=None, warning=None, info=None, debug=None, notset=None)[source]

Decorator checking number of logging messages.

Propagation of logging messages is disabled by this decorator.

In case the expected number of logging messages is not found, it raises a RuntimeError.

>>> class Test(unittest.TestCase):
...     @test_logging('module_logger_name', error=2, warning=0)
...     def test(self):
...         pass  # Test expecting 2 ERROR and 0 WARNING messages
Parameters:
  • logger (str or logging.Logger) – Name or instance of the logger to test. (Default: root logger)
  • critical (int) – Expected number of CRITICAL messages. Default: Do not check.
  • error (int) – Expected number of ERROR messages. Default: Do not check.
  • warning (int) – Expected number of WARNING messages. Default: Do not check.
  • info (int) – Expected number of INFO messages. Default: Do not check.
  • debug (int) – Expected number of DEBUG messages. Default: Do not check.
  • notset (int) – Expected number of NOTSET messages. Default: Do not check.
silx.test.utils.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
silx.test.utils.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

silx.test.utils.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
silx.test.utils.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.test.utils

Helper class to write Qt widget unittests.

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

Mimic QTest.qWaitForWindowExposed for Qt4.

silx.gui.test.utils.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.test.utils.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

setUp()[source]

Get the list of existing widgets.

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.

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

Simulate clicking a key.

See QTest.keyClick for details.

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

Simulate clicking a sequence of keys.

See QTest.keyClick for details.

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

Sends a Qt key event.

See QTest.keyEvent for details.

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

Sends a Qt key press event.

See QTest.keyPress for details.

keyRelease(widget, key, modifier=0, 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.

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.

class silx.gui.test.utils.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.

silx.gui.test.utils.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.

Table Of Contents

Previous topic

weakref

Next topic

Change Log

This Page