Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c283a42

Browse files
committed
Add test for font selection by texmanager.
1 parent b61e3a7 commit c283a42

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed
Lines 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)