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

Appearance settings

Add test for font selection by texmanager. #20310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions 27 lib/matplotlib/tests/test_texmanager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from pathlib import Path
import re

import matplotlib.pyplot as plt
from matplotlib.texmanager import TexManager
import pytest


def test_fontconfig_preamble():
"""
Test that the preamble is included in _fontconfig
"""
"""Test that the preamble is included in _fontconfig."""
plt.rcParams['text.usetex'] = True

tm1 = TexManager()
Expand All @@ -16,3 +18,22 @@ def test_fontconfig_preamble():
font_config2 = tm2.get_font_config()

assert font_config1 != font_config2


@pytest.mark.parametrize(
"rc, preamble, family", [
({"font.family": "sans-serif", "font.sans-serif": "helvetica"},
r"\usepackage{helvet}", r"\sffamily"),
({"font.family": "serif", "font.serif": "palatino"},
r"\usepackage{mathpazo}", r"\rmfamily"),
({"font.family": "cursive", "font.cursive": "zapf chancery"},
r"\usepackage{chancery}", r"\rmfamily"),
({"font.family": "monospace", "font.monospace": "courier"},
r"\usepackage{courier}", r"\ttfamily"),
])
def test_font_selection(rc, preamble, family):
plt.rcParams.update(rc)
tm = TexManager()
src = Path(tm.make_tex("hello, world", fontsize=12)).read_text()
assert preamble in src
assert [*re.findall(r"\\\w+family", src)] == [family]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.