Skip to content

Minor simplifications. #12970

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

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
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
16 changes: 7 additions & 9 deletions lib/matplotlib/tests/test_backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ def _notebook_run(nb_file):
"""Execute a notebook via nbconvert and collect output.
:returns (parsed nb object, execution errors)
"""
with tempfile.NamedTemporaryFile(suffix=".ipynb",
mode='w+t') as fout:
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
"--ExecutePreprocessor.timeout=500",
"--output", fout.name, nb_file]
subprocess.check_call(args)

with tempfile.NamedTemporaryFile(suffix=".ipynb", mode='w+t') as fout:
subprocess.check_call([
"jupyter", "nbconvert", "--to", "notebook",
"--execute", "--ExecutePreprocessor.timeout=500",
"--output", fout.name, nb_file,
])
fout.seek(0)
nb = nbformat.read(fout, nbformat.current_nbformat)

Expand All @@ -30,6 +29,5 @@ def _notebook_run(nb_file):


def test_ipynb():
nb, errors = _notebook_run(
str(Path(__file__).parent / 'test_nbagg_01.ipynb'))
nb, errors = _notebook_run(Path(__file__).parent / 'test_nbagg_01.ipynb')
assert errors == []
29 changes: 10 additions & 19 deletions lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from pathlib import Path
import shutil
import tempfile
import warnings

import numpy as np
Expand All @@ -18,9 +17,8 @@ def test_font_priority():
with rc_context(rc={
'font.sans-serif':
['cmmi10', 'Bitstream Vera Sans']}):
font = findfont(
FontProperties(family=["sans-serif"]))
assert os.path.basename(font) == 'cmmi10.ttf'
font = findfont(FontProperties(family=["sans-serif"]))
assert Path(font).name == 'cmmi10.ttf'

# Smoketest get_charmap, which isn't used internally anymore
font = get_font(font)
Expand All @@ -40,18 +38,12 @@ def test_score_weight():
fontManager.score_weight(400, 400))


def test_json_serialization():
# on windows, we can't open a file twice, so save the name and unlink
# manually...
try:
name = None
with tempfile.NamedTemporaryFile(delete=False) as temp:
name = temp.name
json_dump(fontManager, name)
copy = json_load(name)
finally:
if name and os.path.exists(name):
os.remove(name)
def test_json_serialization(tmpdir):
# Can't open a NamedTemporaryFile twice on Windows, so use a temporary
# directory instead.
path = Path(tmpdir, "fontlist.json")
Copy link
Member

Choose a reason for hiding this comment

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

As a note for the future, when we depend on pytest 3.9, we can use tmp_path here.

json_dump(fontManager, path)
copy = json_load(path)
with warnings.catch_warnings():
warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
for prop in ({'family': 'STIXGeneral'},
Expand All @@ -64,9 +56,8 @@ def test_json_serialization():

def test_otf():
fname = '/usr/share/fonts/opentype/freefont/FreeMono.otf'
if os.path.exists(fname):
if Path(fname).exists():
assert is_opentype_cff_font(fname)

for f in fontManager.ttflist:
if 'otf' in f.fname:
with open(f.fname, 'rb') as fd:
Expand Down