Skip to content

Commit

Permalink
Mention minimum Matplotlib versions for different formats and fix tes…
Browse files Browse the repository at this point in the history
…t suite
  • Loading branch information
astrofrog committed Mar 31, 2023
1 parent 71ced71 commit f1b6cb3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 10 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,10 @@ in ``mpl_image_compare``. Supported formats are ``'eps'``, ``'pdf'``, ``'png'``,
Note that Ghostscript is required to be installed for comparing PDF and EPS figures, while
Inkscape is required for SVG comparison.

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

PNG
^^^
Expand All @@ -311,6 +312,8 @@ For PDF files, the output can be made deterministic by setting:
"Producer": None,
"CreationDate": None}})
Note that deterministic PDF output can only be achieved with Matplotlib 2.1 and above

EPS
^^^

Expand All @@ -330,6 +333,8 @@ a constant value (this is a unit timestamp):
You could do this inside the test.
Note that deterministic PDF output can only be achieved with Matplotlib 2.1 and above
SVG
^^^
Expand All @@ -345,6 +350,8 @@ and in addition, you should make sure the following rcParam is set to a constant
plt.rcParams['svg.hashsalt'] = 'test'
Note that SVG files can only be used in pytest-mpl with Matplotlib 3.3 and above.
Test failure example
--------------------
Expand Down
2 changes: 0 additions & 2 deletions tests/baseline/hashes/mpl20_ft261.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@
"test.test_modified": "54f6cf83d5b06fa2ecb7fa23d6e87898679178ef5d0dfdd2551a139f1932127b",
"test.test_new": "54f6cf83d5b06fa2ecb7fa23d6e87898679178ef5d0dfdd2551a139f1932127b",
"test.test_unmodified": "54f6cf83d5b06fa2ecb7fa23d6e87898679178ef5d0dfdd2551a139f1932127b",
"test_formats.test_format_eps": "d43d276873ee3a46e4dfc86feba5b814a76fa72163dfc6e9624a2750ff625f2f",
"test_formats.test_format_pdf": "917a633ed43b288ecd4ccad64c2f61eee5f2a1b6383a808572dd5a63671298f6",
"test_formats.test_format_png": "480062c2239ed9d70e361d1a5b578dc2aa756971161ac6e7287b492ae6118c59"
}
11 changes: 9 additions & 2 deletions tests/test_pytest_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,15 @@ def test_formats(pytester, use_hash_library, passes, file_format):
if file_format == 'svg' and MPL_VERSION < Version('3.3'):
pytest.skip('SVG comparison is only supported in Matplotlib 3.3 and above')

if use_hash_library and MPL_VERSION >= Version('3.4'):
pytest.skip('No hash library for Matplotlib >= 3.4')
if use_hash_library:

if file_format == 'pdf' and MPL_VERSION < Version('2.1'):
pytest.skip('PDF hashes are only deterministic in Matplotlib 2.1 and above')
elif file_format == 'eps' and MPL_VERSION < Version('2.1'):
pytest.skip('EPS hashes are only deterministic in Matplotlib 2.1 and above')

if MPL_VERSION >= Version('3.4'):
pytest.skip('No hash library in test suite for Matplotlib >= 3.4')

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

0 comments on commit f1b6cb3

Please sign in to comment.