Skip to content

Commit 3008a7a

Browse files
committed
Test case of FontManager serialization
1 parent 34af5c6 commit 3008a7a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/matplotlib/tests/test_font_manager.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
from matplotlib.externals import six
66

77
import 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)
1013
from 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

Comments
 (0)