Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from nose.tools import assert_equal
from matplotlib.externals import six

import sys
import os
import tempfile
import warnings
Expand All @@ -24,8 +25,14 @@ def test_font_priority():

def test_json_serialization():
with tempfile.NamedTemporaryFile() as temp:
if sys.platform == 'win32':
# on Windows, an open NamedTemporaryFile can not be used
# to open the file a second time
temp.close()
json_dump(fontManager, temp.name)
copy = json_load(temp.name)
if sys.platform == 'win32':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a try/finally so it always runs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh... we are making this overly complicated.

try:
    temp = tempfile.NamedTemporaryFile(delete=False)
    temp.close()
    json_dump(fontManager, temp.name)
    copy = json_load(temp.name)
finally:
    if os.path.exists(temp.name):
        os.remove(temp.name)

os.remove(temp.name)
with warnings.catch_warnings():
warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
for prop in ({'family': 'STIXGeneral'},
Expand Down