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

Commit7285029

Browse files
authored
Merge pull request#28784 from QuLogic/better-fallback-tests
Improve fallback font export tests
2 parents39c1d50 +921e49f commit7285029

File tree

13 files changed

+23971
-1224
lines changed

13 files changed

+23971
-1224
lines changed

‎lib/matplotlib/testing/__init__.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"""
22
Helper functions for testing.
33
"""
4-
frompathlibimportPath
5-
fromtempfileimportTemporaryDirectory
4+
importitertools
65
importlocale
76
importlogging
87
importos
8+
frompathlibimportPath
9+
importstring
910
importsubprocess
1011
importsys
12+
fromtempfileimportTemporaryDirectory
1113

1214
importmatplotlibasmpl
1315
frommatplotlibimport_api
@@ -232,3 +234,44 @@ def is_ci_environment():
232234
returnTrue
233235

234236
returnFalse
237+
238+
239+
def_gen_multi_font_text():
240+
"""
241+
Generate text intended for use with multiple fonts to exercise font fallbacks.
242+
243+
Returns
244+
-------
245+
fonts : list of str
246+
The names of the fonts used to render the test string, sorted by intended
247+
priority. This should be set as the font family for the Figure or Text artist.
248+
text : str
249+
The test string.
250+
"""
251+
# These fonts are serif and sans-serif, and would not normally be combined, but that
252+
# should make it easier to see which glyph is from which font.
253+
fonts= ['cmr10','DejaVu Sans']
254+
# cmr10 does not contain accented characters, so they should fall back to DejaVu
255+
# Sans. However, some accented capital A versions *are* in cmr10 with non-standard
256+
# glyph shapes, so don't test those (otherwise this Latin1 supplement group would
257+
# start at 0xA0.)
258+
start=0xC5
259+
latin1_supplement= [chr(x)forxinrange(start,0xFF+1)]
260+
latin_extended_A= [chr(x)forxinrange(0x100,0x17F+1)]
261+
latin_extended_B= [chr(x)forxinrange(0x180,0x24F+1)]
262+
count=itertools.count(start-0xA0)
263+
non_basic_characters='\n'.join(
264+
''.join(line)
265+
for_,lineinitertools.groupby(# Replace with itertools.batched for Py3.12+.
266+
[*latin1_supplement,*latin_extended_A,*latin_extended_B],
267+
key=lambdax:next(count)//32)# 32 characters per line.
268+
)
269+
test_str=f"""There are basic characters
270+
{string.ascii_uppercase}{string.ascii_lowercase}
271+
{string.digits}{string.punctuation}
272+
and accented characters
273+
{non_basic_characters}
274+
in between!"""
275+
# The resulting string contains 491 unique characters. Some file formats use 8-bit
276+
# tables, which the large number of characters exercises twice over.
277+
returnfonts,test_str

‎lib/matplotlib/testing/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ def ipython_in_subprocess(
5252
all_expected_backends:dict[tuple[int,int],str],
5353
)->None: ...
5454
defis_ci_environment()->bool: ...
55+
def_gen_multi_font_text()->tuple[list[str],str]: ...

‎lib/matplotlib/testing/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def convert(filename, cache):
316316
_log.debug("For %s: converting to png.",filename)
317317
convert=converter[path.suffix[1:]]
318318
ifpath.suffix==".svg":
319-
contents=path.read_text()
319+
contents=path.read_text(encoding="utf-8")
320320
# NOTE: This check should be kept in sync with font styling in
321321
# `lib/matplotlib/backends/backend_svg.py`. If it changes, then be sure to
322322
# re-generate any SVG test files using this mode, or else such tests will
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp