8000 TST: fix PermissionError on Windows by cgohlke · Pull Request #5278 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

TST: fix PermissionError on Windows #5278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
TST: on Windows, manually remove temporary file
  • Loading branch information
cgohlke committed Oct 22, 2015
commit 70c36aeda8363e8eaf25c91f15bcd8aad05c82d4
8 changes: 7 additions & 1 deletion 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,9 +25,14 @@ def test_font_priority():

def test_json_serialization():
with tempfile.NamedTemporaryFile() as temp:
temp.close()
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
0