Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7552cdd

Browse files
authored
Merge pull request #21218 from anntzer/mp
Parametrize/simplify test_missing_psfont.
2 parents b78b47a + fe0683f commit 7552cdd

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010

1111
import matplotlib as mpl
12-
from matplotlib import dviread, pyplot as plt, checkdep_usetex, rcParams
12+
from matplotlib import pyplot as plt, checkdep_usetex, rcParams
1313
from matplotlib.cbook import _get_data_path
1414
from matplotlib.ft2font import FT2Font
1515
from matplotlib.backends._backend_pdf_ps import get_glyphs_subset
@@ -295,23 +295,6 @@ def test_grayscale_alpha():
295295
ax.set_yticks([])
296296

297297

298-
# This tests tends to hit a TeX cache lock on AppVeyor.
299-
@pytest.mark.flaky(reruns=3)
300-
@needs_usetex
301-
def test_missing_psfont(monkeypatch):
302-
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
303-
def psfont(*args, **kwargs):
304-
return dviread.PsFont(texname='texfont', psname='Some Font',
305-
effects=None, encoding=None, filename=None)
306-
307-
monkeypatch.setattr(dviread.PsfontsMap, '__getitem__', psfont)
308-
rcParams['text.usetex'] = True
309-
fig, ax = plt.subplots()
310-
ax.text(0.5, 0.5, 'hello')
311-
with NamedTemporaryFile() as tmpfile, pytest.raises(ValueError):
312-
fig.savefig(tmpfile, format='pdf')
313-
314-
315298
@mpl.style.context('default')
316299
@check_figures_equal(extensions=["pdf", "eps"])
317300
def test_pdf_eps_savefig_when_color_is_none(fig_test, fig_ref):

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import datetime
22
from io import BytesIO
3-
import tempfile
43
import xml.etree.ElementTree
54
import xml.parsers.expat
65

76
import numpy as np
87
import pytest
98

109
import matplotlib as mpl
11-
from matplotlib import dviread
1210
from matplotlib.figure import Figure
1311
import matplotlib.pyplot as plt
1412
from matplotlib.testing.decorators import image_comparison, check_figures_equal
@@ -181,22 +179,6 @@ def count_tag(fig, tag):
181179
assert count_tag(fig5, "path") == 1 # axis patch
182180

183181

184-
@needs_usetex
185-
def test_missing_psfont(monkeypatch):
186-
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
187-
188-
def psfont(*args, **kwargs):
189-
return dviread.PsFont(texname='texfont', psname='Some Font',
190-
effects=None, encoding=None, filename=None)
191-
192-
monkeypatch.setattr(dviread.PsfontsMap, '__getitem__', psfont)
193-
mpl.rc('text', usetex=True)
194-
fig, ax = plt.subplots()
195-
ax.text(0.5, 0.5, 'hello')
196-
with tempfile.TemporaryFile() as tmpfile, pytest.raises(ValueError):
197-
fig.savefig(tmpfile, format='svg')
198-
199-
200182
# Use Computer Modern Sans Serif, not Helvetica (which has no \textwon).
201183
@mpl.style.context('default')
202184
@needs_usetex

lib/matplotlib/tests/test_usetex.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
from tempfile import TemporaryFile
2+
13
import numpy as np
24
import pytest
35

46
import matplotlib as mpl
7+
from matplotlib import dviread
58
from matplotlib.testing import _has_tex_package
69
from matplotlib.testing.decorators import check_figures_equal, image_comparison
710
import matplotlib.pyplot as plt
@@ -119,3 +122,19 @@ def test_usetex_with_underscore():
119122
ax.legend()
120123
ax.text(0, 0, "foo_bar", usetex=True)
121124
plt.draw()
125+
126+
127+
@pytest.mark.flaky(reruns=3) # Tends to hit a TeX cache lock on AppVeyor.
128+
@pytest.mark.parametrize("fmt", ["pdf", "svg"])
129+
def test_missing_psfont(fmt, monkeypatch):
130+
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
131+
monkeypatch.setattr(
132+
dviread.PsfontsMap, '__getitem__',
133+
lambda self, k: dviread.PsFont(
134+
texname='texfont', psname='Some Font',
135+
effects=None, encoding=None, filename=None))
136+
mpl.rcParams['text.usetex'] = True
137+
fig, ax = plt.subplots()
138+
ax.text(0.5, 0.5, 'hello')
139+
with TemporaryFile() as tmpfile, pytest.raises(ValueError):
140+
fig.savefig(tmpfile, format=fmt)

0 commit comments

Comments
 (0)