Bases: obspy.core.util.base.NamedTemporaryFile
Handles the comparison against a baseline image in an image test.
Parameters: |
---|
The class should be used with Python’s “with” statement. When setting up, the matplotlib rcdefaults are set to ensure consistent image testing. After the plotting is completed, the ImageComparison.compare() method is called automatically at the end of the “with” block, comparing against the previously specified baseline image. This raises an exception (if the test fails) with the message string from matplotlib.testing.compare.compare_images(). Afterwards all temporary files are deleted automatically.
Note
If images created during the testrun should be kept after the test, set environment variable OBSPY_KEEP_IMAGES to any value before executing the test (e.g. with $ OBSPY_KEEP_IMAGES= obspy-runtests or $ OBSPY_KEEP_IMAGES= python test_sometest.py). For obspy-runtests the option “keep-images” can also be used instead of setting an environment variable. Created images and diffs for failing tests are then stored in a subfolder “testrun” under the baseline image’s directory.
Example
>>> from obspy import read
>>> with ImageComparison("/my/baseline/folder", 'plot.png') as ic:
... st = read()
... st.plot(outfile=ic.name)
... # image is compared against baseline image automatically
Attributes
__dict__ | |
__doc__ | str(object=’‘) -> string |
__module__ | str(object=’‘) -> string |
__weakref__ | list of weak references to the object (if defined) |
Public Methods
compare | Run matplotlib.testing.compare.compare_images() and raise an |
Private Methods
_copy_tempfiles | Copies created images from tempfiles to a subfolder of baseline images. |
Special Methods
__enter__ | Set matplotlib defaults. |
__exit__ | Remove tempfiles and store created images if OBSPY_KEEP_IMAGES |
__getattr__ | |
__init__ |