5
5
from matplotlib .externals import six
6
6
7
7
import os
8
+ import tempfile
9
+ import warnings
8
10
9
- from matplotlib .font_manager import findfont ,FontProperties
11
+ from matplotlib .font_manager import (
12
+ findfont ,FontProperties ,fontManager ,json_dump ,json_load )
10
13
from matplotlib import rc_context
11
14
12
15
@@ -17,3 +20,17 @@ def test_font_priority():
17
20
font = findfont (
18
21
FontProperties (family = ["sans-serif" ]))
19
22
assert_equal (os .path .basename (font ),'cmmi10.ttf' )
23
+
24
+
25
+ def test_json_serialization ():
26
+ with tempfile .NamedTemporaryFile ()as temp :
27
+ json_dump (fontManager ,temp .name )
28
+ copy = json_load (temp .name )
29
+ with warnings .catch_warnings ():
30
+ warnings .filterwarnings ('ignore' ,'findfont: Font family.*not found' )
31
+ for prop in ({'family' :'STIXGeneral' },
32
+ {'family' :'Bitstream Vera Sans' ,'weight' :700 },
33
+ {'family' :'no such font family' }):
34
+ fp = FontProperties (** prop )
35
+ assert_equal (fontManager .findfont (fp ,rebuild_if_missing = False ),
36
+ copy .findfont (fp ,rebuild_if_missing = False ))