Skip to content

Commit f1b6cb3

Browse files
committed
Mention minimum Matplotlib versions for different formats and fix test suite
1 parent 71ced71 commit f1b6cb3

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

README.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ in ``mpl_image_compare``. Supported formats are ``'eps'``, ``'pdf'``, ``'png'``,
286286
Note that Ghostscript is required to be installed for comparing PDF and EPS figures, while
287287
Inkscape is required for SVG comparison.
288288

289-
By default, Matplotlib does not produce deterministic output that will
290-
have a consistent hash every time it is run, or over different Matplotlib versions.
291-
In order to enforce that the output is deterministic, you will need to do the following:
289+
By default, Matplotlib does not produce deterministic output that will have a
290+
consistent hash every time it is run, or over different Matplotlib versions. In
291+
order to enforce that the output is deterministic, you will need to set metadata
292+
as described in the following subsections.
292293

293294
PNG
294295
^^^
@@ -311,6 +312,8 @@ For PDF files, the output can be made deterministic by setting:
311312
"Producer": None,
312313
"CreationDate": None}})
313314
315+
Note that deterministic PDF output can only be achieved with Matplotlib 2.1 and above
316+
314317
EPS
315318
^^^
316319

@@ -330,6 +333,8 @@ a constant value (this is a unit timestamp):
330333
331334
You could do this inside the test.
332335
336+
Note that deterministic PDF output can only be achieved with Matplotlib 2.1 and above
337+
333338
SVG
334339
^^^
335340
@@ -345,6 +350,8 @@ and in addition, you should make sure the following rcParam is set to a constant
345350
346351
plt.rcParams['svg.hashsalt'] = 'test'
347352
353+
Note that SVG files can only be used in pytest-mpl with Matplotlib 3.3 and above.
354+
348355
Test failure example
349356
--------------------
350357

tests/baseline/hashes/mpl20_ft261.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@
1313
"test.test_modified": "54f6cf83d5b06fa2ecb7fa23d6e87898679178ef5d0dfdd2551a139f1932127b",
1414
"test.test_new": "54f6cf83d5b06fa2ecb7fa23d6e87898679178ef5d0dfdd2551a139f1932127b",
1515
"test.test_unmodified": "54f6cf83d5b06fa2ecb7fa23d6e87898679178ef5d0dfdd2551a139f1932127b",
16-
"test_formats.test_format_eps": "d43d276873ee3a46e4dfc86feba5b814a76fa72163dfc6e9624a2750ff625f2f",
17-
"test_formats.test_format_pdf": "917a633ed43b288ecd4ccad64c2f61eee5f2a1b6383a808572dd5a63671298f6",
1816
"test_formats.test_format_png": "480062c2239ed9d70e361d1a5b578dc2aa756971161ac6e7287b492ae6118c59"
1917
}

tests/test_pytest_mpl.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,15 @@ def test_formats(pytester, use_hash_library, passes, file_format):
685685
if file_format == 'svg' and MPL_VERSION < Version('3.3'):
686686
pytest.skip('SVG comparison is only supported in Matplotlib 3.3 and above')
687687

688-
if use_hash_library and MPL_VERSION >= Version('3.4'):
689-
pytest.skip('No hash library for Matplotlib >= 3.4')
688+
if use_hash_library:
689+
690+
if file_format == 'pdf' and MPL_VERSION < Version('2.1'):
691+
pytest.skip('PDF hashes are only deterministic in Matplotlib 2.1 and above')
692+
elif file_format == 'eps' and MPL_VERSION < Version('2.1'):
693+
pytest.skip('EPS hashes are only deterministic in Matplotlib 2.1 and above')
694+
695+
if MPL_VERSION >= Version('3.4'):
696+
pytest.skip('No hash library in test suite for Matplotlib >= 3.4')
690697

691698
if use_hash_library and not sys.platform.startswith('linux'):
692699
pytest.skip('Hashes for vector graphics are only provided in the hash library for Linux')

0 commit comments

Comments
 (0)