1+ from pathlib import Path
2+ import re
3+
14import matplotlib .pyplot as plt
25from matplotlib .texmanager import TexManager
6+ import pytest
37
48
59def 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