From 9721cb7a328003ca3f27b160061cede1704d1ff1 Mon Sep 17 00:00:00 2001 From: Thomas Spura Date: Mon, 17 Apr 2017 23:39:45 +0200 Subject: [PATCH 1/2] Tests: Add failing tests for LaTeX --- lib/matplotlib/tests/test_backend_pdf.py | 12 ++++++++++++ lib/matplotlib/tests/test_backend_ps.py | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index ded0af7f93c9..bec49eb8cdec 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -218,3 +218,15 @@ def test_pdf_savefig_when_color_is_none(tmpdir): fig.savefig(str(expected_image), format='eps') result = compare_images(str(actual_image), str(expected_image), 0) assert result is None + + +def test_failing_latex(tmpdir): + """Test failing latex subprocess call""" + path = tmpdir.join("tmpoutput.pdf") + + rcParams['text.usetex'] = True + + # This failes with "Double subscript" + plt.xlabel("$%f_2_2$" % np.random.random()) + with pytest.raises(RuntimeError) as excinfo: + plt.savefig(path) diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index 0d86b32bd9b7..e3cbe97bb965 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -11,7 +11,7 @@ import matplotlib import matplotlib.pyplot as plt -from matplotlib import patheffects +from matplotlib import patheffects, rcParams from matplotlib.testing.decorators import image_comparison from matplotlib.testing.determinism import (_determinism_source_date_epoch, _determinism_check) @@ -157,3 +157,16 @@ def test_transparency(): ax.set_axis_off() ax.plot([0, 1], color="r", alpha=0) ax.text(.5, .5, "foo", color="r", alpha=0) + + +@needs_usetex +def test_failing_latex(tmpdir): + """Test failing latex subprocess call""" + path = tmpdir.join("tmpoutput.ps") + + rcParams['text.usetex'] = True + + # This failes with "Double subscript" + plt.xlabel("$%f_2_2$" % np.random.random()) + with pytest.raises(RuntimeError) as excinfo: + plt.savefig(path) From 7cf0e22680a27d7b1c3603f7f4719defe8fc0e8c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 6 Jan 2018 04:12:42 -0500 Subject: [PATCH 2/2] TST: Cleanup new tests a bit. Matplotlib doesn't support pytest Path objects, so convert to str. Remove unnecessary randomness and fix typos. --- lib/matplotlib/tests/test_backend_pdf.py | 9 +++++---- lib/matplotlib/tests/test_backend_ps.py | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index bec49eb8cdec..95ed12827ff5 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -220,13 +220,14 @@ def test_pdf_savefig_when_color_is_none(tmpdir): assert result is None +@needs_usetex def test_failing_latex(tmpdir): """Test failing latex subprocess call""" - path = tmpdir.join("tmpoutput.pdf") + path = str(tmpdir.join("tmpoutput.pdf")) rcParams['text.usetex'] = True - # This failes with "Double subscript" - plt.xlabel("$%f_2_2$" % np.random.random()) - with pytest.raises(RuntimeError) as excinfo: + # This fails with "Double subscript" + plt.xlabel("$22_2_2$") + with pytest.raises(RuntimeError): plt.savefig(path) diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index e3cbe97bb965..f93addeed014 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -11,7 +11,7 @@ import matplotlib import matplotlib.pyplot as plt -from matplotlib import patheffects, rcParams +from matplotlib import patheffects from matplotlib.testing.decorators import image_comparison from matplotlib.testing.determinism import (_determinism_source_date_epoch, _determinism_check) @@ -162,11 +162,11 @@ def test_transparency(): @needs_usetex def test_failing_latex(tmpdir): """Test failing latex subprocess call""" - path = tmpdir.join("tmpoutput.ps") + path = str(tmpdir.join("tmpoutput.ps")) - rcParams['text.usetex'] = True + matplotlib.rcParams['text.usetex'] = True - # This failes with "Double subscript" - plt.xlabel("$%f_2_2$" % np.random.random()) - with pytest.raises(RuntimeError) as excinfo: + # This fails with "Double subscript" + plt.xlabel("$22_2_2$") + with pytest.raises(RuntimeError): plt.savefig(path)