From f1b6cb31124f0b4e50e6ed1d36bba03a8771ebf1 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 31 Mar 2023 11:22:47 +0100 Subject: [PATCH] Mention minimum Matplotlib versions for different formats and fix test suite --- README.rst | 13 ++++++++++--- tests/baseline/hashes/mpl20_ft261.json | 2 -- tests/test_pytest_mpl.py | 11 +++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 197effc..13e413e 100644 --- a/README.rst +++ b/README.rst @@ -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 ^^^ @@ -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 ^^^ @@ -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 ^^^ @@ -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 -------------------- diff --git a/tests/baseline/hashes/mpl20_ft261.json b/tests/baseline/hashes/mpl20_ft261.json index 3c36dfc..7fe1a4e 100644 --- a/tests/baseline/hashes/mpl20_ft261.json +++ b/tests/baseline/hashes/mpl20_ft261.json @@ -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" } diff --git a/tests/test_pytest_mpl.py b/tests/test_pytest_mpl.py index 9a69c7c..23cfe78 100644 --- a/tests/test_pytest_mpl.py +++ b/tests/test_pytest_mpl.py @@ -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')