Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83f2d64

Browse files
committed
Fix the cherry-picked test.
1 parentdb5ecdc commit83f2d64

File tree

2 files changed

+21
-30
lines changed

2 files changed

+21
-30
lines changed

‎lib/matplotlib/dviread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ def _parse(file):
978978
# to bother backend_pdf, so that needs to be investigated more. (The fixed
979979
# version below is necessary for textpath/backend_svg, though.)
980980
def_parse_enc(path):
981-
"""
981+
r"""
982982
Parses a \*.enc file referenced from a psfonts.map style file.
983983
The format this class understands is a very limited subset of PostScript.
984984

‎lib/matplotlib/tests/test_backend_svg.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
importnumpyasnp
22
fromioimportBytesIO
33
importos
4+
importre
45
importtempfile
56
importwarnings
67
importxml.parsers.expat
78

89
importpytest
910

11+
importmatplotlibasmpl
12+
frommatplotlibimportdviread
13+
frommatplotlib.figureimportFigure
1014
importmatplotlib.pyplotasplt
1115
frommatplotlib.testing.decoratorsimportimage_comparison
12-
importmatplotlib
13-
frommatplotlibimportdviread
1416

1517

1618
withwarnings.catch_warnings():
1719
warnings.simplefilter('ignore')
1820
needs_usetex=pytest.mark.skipif(
19-
notmatplotlib.checkdep_usetex(True),
21+
notmpl.checkdep_usetex(True),
2022
reason="This test needs a TeX installation")
2123

2224

@@ -100,15 +102,10 @@ def test_bold_font_output_with_none_fonttype():
100102

101103
def_test_determinism_save(filename,usetex):
102104
# This function is mostly copy&paste from "def test_visibility"
103-
# To require no GUI, we use Figure and FigureCanvasSVG
104-
# instead of plt.figure and fig.savefig
105-
frommatplotlib.figureimportFigure
106-
frommatplotlib.backends.backend_svgimportFigureCanvasSVG
107-
frommatplotlibimportrc
108-
rc('svg',hashsalt='asdf')
109-
rc('text',usetex=usetex)
105+
mpl.rc('svg',hashsalt='asdf')
106+
mpl.rc('text',usetex=usetex)
110107

111-
fig=Figure()
108+
fig=Figure()# Require no GUI.
112109
ax=fig.add_subplot(111)
113110

114111
x=np.linspace(0,4*np.pi,50)
@@ -122,7 +119,7 @@ def _test_determinism_save(filename, usetex):
122119
ax.set_xlabel('A string $1+2+\\sigma$')
123120
ax.set_ylabel('A string $1+2+\\sigma$')
124121

125-
FigureCanvasSVG(fig).print_svg(filename)
122+
fig.savefig(filename,format="svg")
126123

127124

128125
@pytest.mark.parametrize(
@@ -165,36 +162,30 @@ def test_determinism(filename, usetex):
165162
@needs_usetex
166163
deftest_missing_psfont(monkeypatch):
167164
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
168-
frommatplotlibimportrc
169165

170166
defpsfont(*args,**kwargs):
171167
returndviread.PsFont(texname='texfont',psname='Some Font',
172168
effects=None,encoding=None,filename=None)
173169

174170
monkeypatch.setattr(dviread.PsfontsMap,'__getitem__',psfont)
175-
rc('text',usetex=True)
171+
mpl.rc('text',usetex=True)
176172
fig,ax=plt.subplots()
177173
ax.text(0.5,0.5,'hello')
178174
withtempfile.TemporaryFile()astmpfile,pytest.raises(ValueError):
179175
fig.savefig(tmpfile,format='svg')
180176

181177

182-
@needs_tex
178+
# Use Computer Modern Sans Serif, not Helvetica (which has no \textwon).
179+
@pytest.mark.style('default')
180+
@needs_usetex
183181
deftest_unicode_won():
184-
frompylabimportrcParams,plot,ylabel,savefig
185-
rcParams.update({'text.usetex':True,'text.latex.unicode':True})
186-
187-
plot(1,1)
188-
ylabel(r'\textwon')
182+
fig=Figure()
183+
fig.text(.5,.5,r'\textwon',usetex=True)
189184

190-
fd=BytesIO()
191-
savefig(fd,format='svg')
192-
fd.seek(0)
193-
buf=fd.read().decode()
194-
fd.close()
185+
withBytesIO()asfd:
186+
fig.savefig(fd,format='svg')
187+
buf=fd.getvalue().decode('ascii')
195188

196189
won_id='Computer_Modern_Sans_Serif-142'
197-
def_regex=re.compile(r'<path d=(.|\s)*?id="{0}"/>'.format(won_id))
198-
use_regex=re.compile(r'<use[^/>]*? xlink:href="#{0}"/>'.format(won_id))
199-
assertTrue(bool(def_regex.search(buf)))
200-
assertTrue(bool(use_regex.search(buf)))
190+
assertre.search(r'<path d=(.|\s)*?id="{0}"/>'.format(won_id),buf)
191+
assertre.search(r'<use[^/>]*? xlink:href="#{0}"/>'.format(won_id),buf)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp