Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed4255b

Browse files
anntzerStephen-Chilcote
authored andcommitted
Minor simplifications.
1 parent cf7f62a commit ed4255b

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

lib/matplotlib/tests/test_backend_nbagg.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ def _notebook_run(nb_file):
1313
"""Execute a notebook via nbconvert and collect output.
1414
:returns (parsed nb object, execution errors)
1515
"""
16-
with tempfile.NamedTemporaryFile(suffix=".ipynb",
17-
mode='w+t') as fout:
18-
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
19-
"--ExecutePreprocessor.timeout=500",
20-
"--output", fout.name, nb_file]
21-
subprocess.check_call(args)
22-
16+
with tempfile.NamedTemporaryFile(suffix=".ipynb", mode='w+t') as fout:
17+
subprocess.check_call([
18+
"jupyter", "nbconvert", "--to", "notebook",
19+
"--execute", "--ExecutePreprocessor.timeout=500",
20+
"--output", fout.name, nb_file,
21+
])
2322
fout.seek(0)
2423
nb = nbformat.read(fout, nbformat.current_nbformat)
2524

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

3130

3231
def test_ipynb():
33-
nb, errors = _notebook_run(
34-
str(Path(__file__).parent / 'test_nbagg_01.ipynb'))
32+
nb, errors = _notebook_run(Path(__file__).parent / 'test_nbagg_01.ipynb')
3533
assert errors == []

lib/matplotlib/tests/test_font_manager.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import os
1+
from pathlib import Path
22
import shutil
33
import sys
4-
import tempfile
54
import warnings
65

76
import numpy as np
@@ -19,9 +18,8 @@ def test_font_priority():
1918
with rc_context(rc={
2019
'font.sans-serif':
2120
['cmmi10', 'Bitstream Vera Sans']}):
22-
font = findfont(
23-
FontProperties(family=["sans-serif"]))
24-
assert os.path.basename(font) == 'cmmi10.ttf'
21+
font = findfont(FontProperties(family=["sans-serif"]))
22+
assert Path(font).name == 'cmmi10.ttf'
2523

2624
# Smoketest get_charmap, which isn't used internally anymore
2725
font = get_font(font)
@@ -41,18 +39,12 @@ def test_score_weight():
4139
fontManager.score_weight(400, 400))
4240

4341

44-
def test_json_serialization():
45-
# on windows, we can't open a file twice, so save the name and unlink
46-
# manually...
47-
try:
48-
name = None
49-
with tempfile.NamedTemporaryFile(delete=False) as temp:
50-
name = temp.name
51-
json_dump(fontManager, name)
52-
copy = json_load(name)
53-
finally:
54-
if name and os.path.exists(name):
55-
os.remove(name)
42+
def test_json_serialization(tmpdir):
43+
# Can't open a NamedTemporaryFile twice on Windows, so use a temporary
44+
# directory instead.
45+
path = Path(tmpdir, "fontlist.json")
46+
json_dump(fontManager, path)
47+
copy = json_load(path)
5648
with warnings.catch_warnings():
5749
warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
5850
for prop in ({'family': 'STIXGeneral'},
@@ -65,9 +57,8 @@ def test_json_serialization():
6557

6658
def test_otf():
6759
fname = '/usr/share/fonts/opentype/freefont/FreeMono.otf'
68-
if os.path.exists(fname):
60+
if Path(fname).exists():
6961
assert is_opentype_cff_font(fname)
70-
7162
for f in fontManager.ttflist:
7263
if 'otf' in f.fname:
7364
with open(f.fname, 'rb') as fd:

0 commit comments

Comments
 (0)