vtkmodules.test.Testing#

This module attempts to make it easy to create VTK-Python unittests. The module uses unittest for the test interface. For more documentation on what unittests are and how to use them, please read these:

http://www.python.org/doc/current/lib/module-unittest.html

http://www.diveintopython.org/roman_divein.html

This VTK-Python test module supports image based tests with multiple images per test suite and multiple images per individual test as well. It also prints information appropriate for CDash (http://open.kitware.com/).

This module defines several useful classes and functions to make writing tests easy. The most important of these are:

class vtkTest: Subclass this for your tests. It also has a few useful internal functions that can be used to do some simple blackbox testing.

compareImage(renwin, img_fname, threshold=0.15): Compares renwin with image and generates image if it does not exist. The threshold determines how closely the images must match. The function also handles multiple images and finds the best matching image.

compareImageWithSavedImage(src_img, img_fname, threshold=0.15): Compares given source image (in the form of a vtkImageData) with saved image and generates the image if it does not exist. The threshold determines how closely the images must match. The function also handles multiple images and finds the best matching image.

getAbsImagePath(img_basename): Returns the full path to the image given the basic image name.

main(cases): Does the testing given a list of tuples containing test classes and the starting string of the functions used for testing.

interact(): Interacts with the user if necessary. The behavior of this is rather trivial and works best when using Tkinter. It does not do anything by default and stops to interact with the user when given the appropriate command line arguments.

isInteractive(): If interact() is not good enough, use this to find if the mode is interactive or not and do whatever is necessary to generate an interactive view.

Examples:

The best way to learn on how to use this module is to look at a few examples. The end of this file contains a trivial example. Please also look at the following examples:

Rendering/Testing/Python/TestTkRenderWidget.py,
Rendering/Testing/Python/TestTkRenderWindowInteractor.py

Created: September, 2002

Prabhu Ramachandran prabhu@aero.iitb.ac.in

Module Contents#

Classes#

vtkTest

A simple default VTK test class that defines a few useful blackbox tests that can be readily used. Derive your test cases from this class and use the following if you’d like to.

Functions#

skip

Cause the test to be skipped due to insufficient requirements.

interact

Interacts with the user if necessary.

isInteractive

Returns if the currently chosen mode is interactive or not based on command line options.

getAbsImagePath

Returns the full path to the image given the basic image name.

_getTempImagePath

compareImageWithSavedImage

Compares a source image (src_img, which is a vtkImageData) with the saved image file whose name is given in the second argument. If the image file does not exist the image is generated and stored. If not the source image is compared to that of the figure. This function also handles multiple images and finds the best matching image.

compareImage

Compares renwin’s (a vtkRenderWindow) contents with the image file whose name is given in the second argument. If the image file does not exist the image is generated and stored. If not the image in the render window is compared to that of the figure. This function also handles multiple images and finds the best matching image.

_printCDashImageError

Prints the XML data necessary for CDash.

_printCDashImageNotFoundError

Prints the XML data necessary for Dart when the baseline image is not found.

_printCDashImageSuccess

Prints XML data for Dart when image test succeeded.

_handleFailedImage

Writes all the necessary images when an image comparison failed.

main

Pass a list of tuples containing test classes and the starting string of the functions used for testing.

test

Pass a list of tuples containing test classes and the functions used for testing.

usage

parseCmdLine

processCmdLine

Data#

API#

vtkmodules.test.Testing.VTK_DATA_ROOT = <Multiline-String>#
vtkmodules.test.Testing.VTK_DATA_PATHS#

[]

vtkmodules.test.Testing.VTK_BASELINE_ROOT = <Multiline-String>#
vtkmodules.test.Testing.VTK_TEMP_DIR = <Multiline-String>#
vtkmodules.test.Testing.VTK_BASELINE_PATHS#

[]

vtkmodules.test.Testing._VERBOSE#

0

vtkmodules.test.Testing._INTERACT#

0

vtkmodules.test.Testing._NO_IMAGE#

0

vtkmodules.test.Testing.skip()#

Cause the test to be skipped due to insufficient requirements.

class vtkmodules.test.Testing.vtkTest(methodName='runTest')#

Bases: unittest.TestCase

A simple default VTK test class that defines a few useful blackbox tests that can be readily used. Derive your test cases from this class and use the following if you’d like to.

Note: Unittest instantiates this class (or your subclass) each time it tests a method. So if you do not want that to happen when generating VTK pipelines you should create the pipeline in the class definition as done below for _blackbox.

Initialization

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

_blackbox#

‘Tester(…)’

dl#

‘vtkDebugLeaks(…)’

_testParse(obj)#

Does a blackbox test by attempting to parse the class for its various methods using vtkMethodParser. This is a useful test because it gets all the methods of the vtkObject, parses them and sorts them into different classes of objects.

_testGetSet(obj, excluded_methods=[])#

Checks the Get/Set method pairs by setting the value using the current state and making sure that it equals the value it was originally. This effectively calls _testParse internally.

_testBoolean(obj, excluded_methods=[])#

Checks the Boolean methods by setting the value on and off and making sure that the GetMethod returns the set value. This effectively calls _testParse internally.

pathToData(filename)#

Given a filename with no path (i.e., no leading directories prepended), return the full path to a file as specified on the command line with a ‘-D’ option.

As an example, if a test is run with “-D /path/to/grid.vtu” then calling

self.pathToData('grid.vtu')

in your test will return “/path/to/grid.vtu”. This is useful in combination with ExternalData, where data may be staged by CTest to a user-configured directory at build time.

In order for this method to work, you must specify the JUST_VALID option for your test in CMake.

pathToValidatedOutput(filename)#

Given a filename with no path (i.e., no leading directories prepended), return the full path to a file as specified on the command line with a ‘-V’ option.

As an example, if a test is run with “-V /path/to/validImage.png” then calling

self.pathToData('validImage.png')

in your test will return “/path/to/validImage.png”. This is useful in combination with ExternalData, where data may be staged by CTest to a user-configured directory at build time.

In order for this method to work, you must specify the JUST_VALID option for your test in CMake.

prepareTestImage(interactor, **kwargs)#
assertImageMatch(renwin, baseline, **kwargs)#

Throw an error if a rendering in the render window does not match the baseline image.

This method accepts a threshold keyword argument (with a default of 0.15) that specifies how different a baseline may be before causing a failure.

vtkmodules.test.Testing.interact()#

Interacts with the user if necessary.

vtkmodules.test.Testing.isInteractive()#

Returns if the currently chosen mode is interactive or not based on command line options.

vtkmodules.test.Testing.getAbsImagePath(img_basename)#

Returns the full path to the image given the basic image name.

vtkmodules.test.Testing._getTempImagePath(img_fname)#
vtkmodules.test.Testing.compareImageWithSavedImage(src_img, img_fname, threshold=0.15)#

Compares a source image (src_img, which is a vtkImageData) with the saved image file whose name is given in the second argument. If the image file does not exist the image is generated and stored. If not the source image is compared to that of the figure. This function also handles multiple images and finds the best matching image.

vtkmodules.test.Testing.compareImage(renwin, img_fname, threshold=0.15)#

Compares renwin’s (a vtkRenderWindow) contents with the image file whose name is given in the second argument. If the image file does not exist the image is generated and stored. If not the image in the render window is compared to that of the figure. This function also handles multiple images and finds the best matching image.

vtkmodules.test.Testing._printCDashImageError(img_err, err_index, img_base)#

Prints the XML data necessary for CDash.

vtkmodules.test.Testing._printCDashImageNotFoundError(img_fname)#

Prints the XML data necessary for Dart when the baseline image is not found.

vtkmodules.test.Testing._printCDashImageSuccess(img_err, err_index)#

Prints XML data for Dart when image test succeeded.

vtkmodules.test.Testing._handleFailedImage(idiff, pngr, img_fname)#

Writes all the necessary images when an image comparison failed.

vtkmodules.test.Testing.main(cases)#

Pass a list of tuples containing test classes and the starting string of the functions used for testing.

Example:

main ([(vtkTestClass, ‘test’), (vtkTestClass1, ‘test’)])

vtkmodules.test.Testing.test(cases)#

Pass a list of tuples containing test classes and the functions used for testing.

It returns a unittest._TextTestResult object.

Example:

test = test_suite([(vtkTestClass, ‘test’), (vtkTestClass1, ‘test’)])

vtkmodules.test.Testing.usage()#
vtkmodules.test.Testing.parseCmdLine()#
vtkmodules.test.Testing.processCmdLine()#