55from
D866
matplotlib .externals import six
66
77import os
8+ import tempfile
9+ import warnings
810
9- from matplotlib .font_manager import findfont , FontProperties
11+ from matplotlib .font_manager import (
12+ findfont , FontProperties , fontManager , json_dump , json_load )
1013from matplotlib import rc_context
1114
1215
@@ -17,3 +20,17 @@ def test_font_priority():
1720 font = findfont (
1821 FontProperties (family = ["sans-serif" ]))
1922 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 ))
0 commit comments