From 396648546ecde263b39f621d9c04ef1455c2caa2 Mon Sep 17 00:00:00 2001 From: Tuan333 Date: Fri, 26 May 2017 17:58:43 +0000 Subject: [PATCH 1/6] added unit test for back end pdf and fixed small bug in testing facility --- lib/matplotlib/backends/backend_pdf.py | 8 ++++++++ lib/matplotlib/testing/compare.py | 5 +++-- lib/matplotlib/tests/test_backend_pdf.py | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index e14aadcb48bd..96e3cdfa3590 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -1626,6 +1626,13 @@ def check_gc(self, gc, fillcolor=None): orig_alphas = getattr(gc, '_effective_alphas', (1.0, 1.0)) + if gc._rgb is None: + if gc.get_linewidth() != 0: + warnings.warn('if rgb is None, ' + + 'linewidth should also be 0') + # doesn't matter what color here + gc._rgb = [1, 0, 0, 1] + if gc._forced_alpha: gc._effective_alphas = (gc._alpha, gc._alpha) elif fillcolor is None or len(fillcolor) < 4: @@ -2621,3 +2628,4 @@ class FigureManagerPdf(FigureManagerBase): FigureCanvas = FigureCanvasPdf FigureManager = FigureManagerPdf + diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index c3d649e38069..dedf1c57b863 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -355,8 +355,8 @@ def crop_to_same(actual_path, actual_image, expected_path, expected_image): # clip the images to the same size -- this is useful only when # comparing eps to pdf if actual_path[-7:-4] == 'eps' and expected_path[-7:-4] == 'pdf': - aw, ah = actual_image.shape - ew, eh = expected_image.shape + aw, ah, ad = actual_image.shape + ew, eh, ed = expected_image.shape actual_image = actual_image[int(aw / 2 - ew / 2):int( aw / 2 + ew / 2), int(ah / 2 - eh / 2):int(ah / 2 + eh / 2)] return actual_image, expected_image @@ -492,3 +492,4 @@ def save_diff_image(expected, actual, output): save_image_np[:, :, 3] = 255 _png.write_png(save_image_np, output) + diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 3529ea8541db..708cabd6355c 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -19,7 +19,9 @@ _determinism_check) from matplotlib.testing.decorators import image_comparison from matplotlib import dviread +from matplotlib.testing.compare import compare_images +import matplotlib as mpl needs_tex = pytest.mark.xfail( not checkdep_tex(), @@ -191,3 +193,23 @@ def psfont(*args, **kwargs): ax.text(0.5, 0.5, 'hello') with tempfile.TemporaryFile() as tmpfile, pytest.raises(ValueError): fig.savefig(tmpfile, format='pdf') + + +def test_pdf_savefig_when_color_is_none(): + backup_params = mpl.rcParams.copy() + mpl.rcParams.update(mpl.rcParamsDefault) + plt.subplot() + plt.axis('off') + plt.plot(np.sin(np.linspace(-5, 5, 100)), 'v', c='none') + try: + plt.savefig("figure.pdf", format='pdf') + except Exception: + pytest.fail("Failed to save pdf") + plt.savefig("figure.eps", format='eps') + result = compare_images('figure.pdf', 'figure.eps', 0) + assert result is None + from os import remove + remove('figure.eps') + remove('figure.pdf') + mpl.rcParams.update(backup_params) + From c1f89cae4ba0c39fc4af4fff315530159cfd51da Mon Sep 17 00:00:00 2001 From: Tuan333 Date: Sat, 27 May 2017 05:01:03 +0000 Subject: [PATCH 2/6] fixed up decorator testing facility --- lib/matplotlib/testing/decorators.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index 3a0dd4e0f9a8..a3085e7f8cb1 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -223,7 +223,12 @@ def _xfail_if_format_is_uncomparable(extension): def _mark_xfail_if_format_is_uncomparable(extension): - will_fail = extension not in comparable_formats() + will_fail = True + for compare_type in comparable_formats(): + if (isinstance(extension, type(compare_type)) and\ + extension == compare_type): + will_fail = False + break if will_fail: fail_msg = 'Cannot compare %s files on this system' % extension import pytest @@ -569,3 +574,4 @@ def skip_if_command_unavailable(cmd): return pytest.mark.skip(reason='missing command: %s' % cmd[0]) return lambda f: f + From 20676894561f47992041137b964f4cc520ed13f0 Mon Sep 17 00:00:00 2001 From: Tuan333 Date: Sat, 27 May 2017 05:04:04 +0000 Subject: [PATCH 3/6] fixed pep8 --- lib/matplotlib/backends/backend_pdf.py | 1 - lib/matplotlib/tests/test_backend_pdf.py | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 96e3cdfa3590..7ae584ac63df 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -2628,4 +2628,3 @@ class FigureManagerPdf(FigureManagerBase): FigureCanvas = FigureCanvasPdf FigureManager = FigureManagerPdf - diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 708cabd6355c..fac9cd8635fd 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -212,4 +212,3 @@ def test_pdf_savefig_when_color_is_none(): remove('figure.eps') remove('figure.pdf') mpl.rcParams.update(backup_params) - From a0b79739742e3b2230077c6b0b5338b000eddab9 Mon Sep 17 00:00:00 2001 From: Tuan333 Date: Sat, 27 May 2017 05:05:48 +0000 Subject: [PATCH 4/6] more pep8 stuff --- lib/matplotlib/testing/compare.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index dedf1c57b863..b6f508660fc9 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -492,4 +492,3 @@ def save_diff_image(expected, actual, output): save_image_np[:, :, 3] = 255 _png.write_png(save_image_np, output) - From 76b67150b79d64854173acff015bf983c21854b7 Mon Sep 17 00:00:00 2001 From: Tuan333 Date: Sat, 27 May 2017 08:44:23 +0000 Subject: [PATCH 5/6] even more pep8 --- lib/matplotlib/testing/decorators.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index a3085e7f8cb1..6d3c3b7b467c 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -574,4 +574,3 @@ def skip_if_command_unavailable(cmd): return pytest.mark.skip(reason='missing command: %s' % cmd[0]) return lambda f: f - From 7c72d51cbb402cf4e873fdb0e26cdb8599e16733 Mon Sep 17 00:00:00 2001 From: Tuan Date: Sat, 27 May 2017 19:20:57 +1000 Subject: [PATCH 6/6] Update decorators.py --- lib/matplotlib/testing/decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index 6d3c3b7b467c..1237ca85fecc 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -225,7 +225,7 @@ def _xfail_if_format_is_uncomparable(extension): def _mark_xfail_if_format_is_uncomparable(extension): will_fail = True for compare_type in comparable_formats(): - if (isinstance(extension, type(compare_type)) and\ + if (isinstance(extension, type(compare_type)) and extension == compare_type): will_fail = False break pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy