Version 3.0.2
matplotlib

matplotlib.testing

matplotlib.testing

matplotlib.testing.is_called_from_pytest()[source]

Returns whether the call was done from pytest

matplotlib.testing.set_font_settings_for_testing()[source]
matplotlib.testing.set_reproducibility_for_testing()[source]
matplotlib.testing.setup()[source]

matplotlib.testing.compare

Provides a collection of utilities for comparing (image) results.

matplotlib.testing.compare.compare_float(expected, actual, relTol=None, absTol=None)[source]

Deprecated since version 3.0: The compare_float function was deprecated in Matplotlib 3.0 and will be removed in 3.2.

Fail if the floating point values are not close enough, with the given message.

You can specify a relative tolerance, absolute tolerance, or both.

matplotlib.testing.compare.compare_images(expected, actual, tol, in_decorator=False)[source]

Compare two "image" files checking differences within a tolerance.

The two given filenames may point to files which are convertible to PNG via the converter dictionary. The underlying RMS is calculated with the calculate_rms function.

Parameters:

expected : str

The filename of the expected image.

actual :str

The filename of the actual image.

tol : float

The tolerance (a color value difference, where 255 is the maximal difference). The test fails if the average pixel difference is greater than this value.

in_decorator : bool

If called from image_comparison decorator, this should be True. (default=False)

Examples

img1 = "./baseline/plot.png" img2 = "./output/plot.png" compare_images(img1, img2, 0.001):

matplotlib.testing.compare.comparable_formats()[source]

Returns the list of file formats that compare_images can compare on this system.

matplotlib.testing.decorators

class matplotlib.testing.decorators.CleanupTest(**kwargs)[source]

Bases: object

Deprecated since version 3.0: The CleanupTest class was deprecated in Matplotlib 3.0 and will be removed in 3.2.

classmethod setup_class()
classmethod teardown_class()
test()[source]
class matplotlib.testing.decorators.CleanupTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

A wrapper for unittest.TestCase that includes cleanup operations.

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.

classmethod setUpClass()[source]

Hook method for setting up class fixture before running tests in the class.

classmethod tearDownClass()[source]

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

class matplotlib.testing.decorators.ImageComparisonTest(**kwargs)[source]

Bases: matplotlib.testing.decorators.CleanupTest, matplotlib.testing.decorators._ImageComparisonBase

Deprecated since version 3.0: The ImageComparisonTest class was deprecated in Matplotlib 3.0 and will be removed in 3.2.

Nose-based image comparison class

This class generates tests for a nose-based testing framework. Ideally, this class would not be public, and the only publicly visible API would be the image_comparison() decorator. Unfortunately, there are existing downstream users of this class (e.g., pytest-mpl) so it cannot yet be removed.

nose_runner()[source]
setup()[source]
teardown()[source]
matplotlib.testing.decorators.check_figures_equal(*, extensions=('png', 'pdf', 'svg'), tol=0)[source]

Decorator for test cases that generate and compare two figures.

The decorated function must take two arguments, fig_test and fig_ref, and draw the test and reference images on them. After the function returns, the figures are saved and compared.

matplotlib.testing.decorators.check_freetype_version(ver)[source]
matplotlib.testing.decorators.cleanup(style=None)[source]

A decorator to ensure that any global state is reset before running a test.

Parameters:

style : str, optional

The name of the style to apply.

matplotlib.testing.decorators.image_comparison(baseline_images, extensions=None, tol=0.306, freetype_version=None, remove_text=False, savefig_kwarg=None, style='_classic_test')[source]

Compare images generated by the test with those specified in baseline_images, which must correspond else an ImageComparisonFailure exception will be raised.

matplotlib.testing.decorators.remove_ticks_and_titles(figure)[source]
matplotlib.testing.decorators.skip_if_command_unavailable(cmd)[source]

Deprecated since version 3.0: The skip_if_command_unavailable function was deprecated in Matplotlib 3.0 and will be removed in 3.2.

skips a test if a command is unavailable.

Parameters:

cmd : list of str

must be a complete command which should not return a non zero exit code, something like ["latex", "-version"]

matplotlib.testing.decorators.switch_backend(backend)[source]

matplotlib.testing.disable_internet

matplotlib.testing.disable_internet.check_internet_off(original_function)[source]

Wraps original_function, which in most cases is assumed to be a socket.socket method, to raise an IOError for any operations on non-local AF_INET sockets.

matplotlib.testing.disable_internet.no_internet(verbose=False)[source]

Context manager to temporarily disable internet access (if not already disabled). If it was already disabled before entering the context manager (i.e. turn_off_internet was called previously) then this is a no-op and leaves internet access disabled until a manual call to turn_on_internet.

matplotlib.testing.disable_internet.turn_off_internet(verbose=False)[source]

Disable internet access via python by preventing connections from being created using the socket module. Presumably this could be worked around by using some other means of accessing the internet, but all default python modules (urllib, requests, etc.) use socket [citation needed].

matplotlib.testing.disable_internet.turn_on_internet(verbose=False)[source]

Restore internet access. Not used, but kept in case it is needed.

matplotlib.testing.exceptions

exception matplotlib.testing.exceptions.ImageComparisonFailure[source]

Bases: AssertionError

Raise this exception to mark a test as a comparison between two images.