1
+ from pathlib import Path
2
+ import re
3
+
1
4
import matplotlib .pyplot as plt
2
5
from matplotlib .texmanager import TexManager
6
+ import pytest
3
7
4
8
5
9
def test_fontconfig_preamble ():
6
- """
7
- Test that the preamble is included in _fontconfig
8
- """
10
+ """Test that the preamble is included in _fontconfig."""
9
11
plt .rcParams ['text.usetex' ] = True
10
12
11
13
tm1 = TexManager ()
@@ -16,3 +18,22 @@ def test_fontconfig_preamble():
16
18
font_config2 = tm2 .get_font_config ()
17
19
18
20
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