MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_mathtext_fallback

Function test_mathtext_fallback

lib/matplotlib/tests/test_mathtext.py:451–474  ·  view source on GitHub ↗
(fallback, fontlist)

Source from the content-addressed store, hash-verified

449 [("cm", ['DejaVu Sans', 'mpltest', 'STIXGeneral', 'cmr10', 'STIXGeneral']),
450 ("stix", ['DejaVu Sans', 'mpltest', 'STIXGeneral', 'STIXGeneral', 'STIXGeneral'])])
451def test_mathtext_fallback(fallback, fontlist):
452 mpl.font_manager.fontManager.addfont(
453 (Path(__file__).resolve().parent / 'data/mpltest.ttf'))
454 mpl.rcParams["svg.fonttype"] = 'none'
455 mpl.rcParams['mathtext.fontset'] = 'custom'
456 mpl.rcParams['mathtext.rm'] = 'mpltest'
457 mpl.rcParams['mathtext.it'] = 'mpltest:italic'
458 mpl.rcParams['mathtext.bf'] = 'mpltest:bold'
459 mpl.rcParams['mathtext.bfit'] = 'mpltest:italic:bold'
460 mpl.rcParams['mathtext.fallback'] = fallback
461
462 test_str = r'a$A\AA\breve\gimel$'
463
464 buff = io.BytesIO()
465 fig, ax = plt.subplots()
466 fig.text(.5, .5, test_str, fontsize=40, ha='center')
467 fig.savefig(buff, format="svg")
468 tspans = (ET.fromstring(buff.getvalue())
469 .findall(".//{http://www.w3.org/2000/svg}tspan[@style]"))
470 char_fonts = [
471 re.search(r"font-family: '([\w ]+)'", tspan.attrib["style"]).group(1)
472 for tspan in tspans]
473 assert char_fonts == fontlist, f'Expected {fontlist}, got {char_fonts}'
474 mpl.font_manager.fontManager.ttflist.pop()
475
476
477def test_math_to_image(tmp_path):

Callers

nothing calls this directly

Calls 9

PathClass · 0.85
addfontMethod · 0.80
resolveMethod · 0.80
groupMethod · 0.80
searchMethod · 0.80
subplotsMethod · 0.45
textMethod · 0.45
savefigMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…