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

Commit d220d77

Browse filesBrowse files
authored
Merge pull request #20310 from anntzer/test-tex-font-selection
Add test for font selection by texmanager.
2 parents 3590c26 + c283a42 commit d220d77
Copy full SHA for d220d77

File tree

Expand file treeCollapse file tree

1 file changed

+24
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-3
lines changed
+24-3Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from pathlib import Path
2+
import re
3+
14
import matplotlib.pyplot as plt
25
from matplotlib.texmanager import TexManager
6+
import pytest
37

48

59
def test_fontconfig_preamble():
6-
"""
7-
Test that the preamble is included in _fontconfig
8-
"""
10+
"""Test that the preamble is included in _fontconfig."""
911
plt.rcParams['text.usetex'] = True
1012

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

1820
assert font_config1 != font_config2
21+
22+
23+
@pytest.mark.parametrize(
24+
"rc, preamble, family", [
25+
({"font.family": "sans-serif", "font.sans-serif": "helvetica"},
26+
r"\usepackage{helvet}", r"\sffamily"),
27+
({"font.family": "serif", "font.serif": "palatino"},
28+
r"\usepackage{mathpazo}", r"\rmfamily"),
29+
({"font.family": "cursive", "font.cursive": "zapf chancery"},
30+
r"\usepackage{chancery}", r"\rmfamily"),
31+
({"font.family": "monospace", "font.monospace": "courier"},
32+
r"\usepackage{courier}", r"\ttfamily"),
33+
])
34+
def test_font_selection(rc, preamble, family):
35+
plt.rcParams.update(rc)
36+
tm = TexManager()
37+
src = Path(tm.make_tex("hello, world", fontsize=12)).read_text()
38+
assert preamble in src
39+
assert [*re.findall(r"\\\w+family", src)] == [family]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.