8000 Add matplotlib.testing to the documentation · matplotlib/matplotlib@a64cbfc · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit a64cbfc

Browse files
committed
Add matplotlib.testing to the documentation
1 parent a43fd85 commit a64cbfc

File tree

4 files changed

+103
-8
lines changed

4 files changed

+103
-8
lines changed

doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Modules
5454
spines_api.rst
5555
style_api.rst
5656
table_api.rst
57+
testing_api.rst
5758
text_api.rst
5859
ticker_api.rst
5960
tight_layout_api.rst

doc/api/testing_api.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
*******
2+
testing
3+
*******
4+
5+
6+
:mod:`matplotlib.testing`
7+
=========================
8+
9+
.. automodule:: matplotlib.testing
10+
:members:
11+
:undoc-members:
12+
:show-inheritance:
13+
14+
15+
:mod:`matplotlib.testing.compare`
16+
=================================
17+
18+
.. automodule:: matplotlib.testing.compare
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
24+
:mod:`matplotlib.testing.conftest`
25+
==================================
26+
27+
.. automodule:: matplotlib.testing.conftest
28+
:members:
29+
:undoc-members:
30+
:show-inheritance:
31+
32+
33+
:mod:`matplotlib.testing.decorators`
34+
====================================
35+
36+
.. automodule:: matplotlib.testing.decorators
37+
:members:
38+
:undoc-members:
39+
:show-inheritance:
40+
41+
42+
:mod:`matplotlib.testing.determinism`
43+
=====================================
44+
45+
.. automodule:: matplotlib.testing.determinism
46+
:members:
47+
:undoc-members:
48+
:show-inheritance:
49+
50+
51+
:mod:`matplotlib.testing.disable_internet`
52+
==========================================
53+
54+
.. automodule:: matplotlib.testing.disable_internet
55+
:members:
56+
:undoc-members:
57+
:show-inheritance:
58+
59+
60+
:mod:`matplotlib.testing.exceptions`
61+
====================================
62+
63+
.. automodule:: matplotlib.testing.exceptions
64+
:members:
65+
:undoc-members:
66+
:show-inheritance:

lib/matplotlib/testing/__init__.py

Lines changed: 4 additions & 1 deletion
< 8000 td data-grid-cell-id="diff-dff5590a4cf0f221159c2e5534cf8f989b5fa3204590c72fe3e38ec57501ac2e-0-3-2" data-line-anchor="diff-dff5590a4cf0f221159c2e5534cf8f989b5fa3204590c72fe3e38ec57501ac2eR3" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">+
"""
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Helper functions for testing.
3
14
import locale
25
import warnings
36

@@ -6,7 +9,7 @@
69

710

811
def is_called_from_pytest():
9-
"""Returns whether the call was done from pytest"""
12+
"""Whether we are in a pytest run."""
1013
return getattr(mpl, '_called_from_pytest', False)
1114

1215

lib/matplotlib/testing/compare.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,14 @@ def _update_converter():
281281

282282
def comparable_formats():
283283
"""
284-
Returns the list of file formats that compare_images can compare
284+
Return the list of file formats that `.compare_images` can compare
285285
on this system.
286286
287+
Returns
288+
-------
289+
supported_formats : list of str
290+
E.g. ``['png', 'pdf', 'svg', 'eps']``.
291+
287292
"""
288293
return ['png', *converter]
289294

@@ -369,21 +374,41 @@ def compare_images(expected, actual, tol, in_decorator=False):
369374
----------
370375
expected : str
371376
The filename of the expected image.
372-
actual :str
377+
actual : str
373378
The filename of the actual image.
374379
tol : float
375380
The tolerance (a color value difference, where 255 is the
376381
maximal difference). The test fails if the average pixel
377382
difference is greater than this value.
378383
in_decorator : bool
379-
If called from image_comparison decorator, this should be
380-
True. (default=False)
384+
Determines the output format. If called from image_comparison
385+
decorator, this should be True. (default=False)
386+
387+
Returns
388+
-------
389+
comparison_result : None or dict or str
390+
Return *None* if the images are equal within the given tolerance.
391+
392+
If the images differ, the return value depends on *in_decorator*.
393+
If *in_decorator* is true, a dict with the following entries is
394+
returned:
395+
396+
- *rms*: The RMS of the image difference.
397+
- *expected*: The filename of the expected image.
398+
- *actual*: The filename of the actual image.
399+
- *diff_image*: The filename of the difference image.
400+
- *tol*: The comparison tolerance.
401+
402+
Otherwise, a human-readable multi-line string representation of this
403+
information is returned.
381404
382405
Examples
383406
--------
384-
img1 = "./baseline/plot.png"
385-
img2 = "./output/plot.png"
386-
compare_images(img1, img2, 0.001):
407+
::
408+
409+
img1 = "./baseline/plot.png"
410+
img2 = "./output/plot.png"
411+
compare_images(img1, img2, 0.001)
387412
388413
"""
389414
if not os.path.exists(actual):

0 commit comments

Comments
 (0)
0