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

Skip to content

Commit 53c4269

Browse files
committed
Minor simplifications.
1 parent 135bab0 commit 53c4269

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,6 +1,5 @@
1-
import os
1+
from pathlib import Path
22
import shutil
3-
import tempfile
43
import warnings
54

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

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

4240

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

6557
def test_otf():
6658
fname = '/usr/share/fonts/opentype/freefont/FreeMono.otf'
67-
if os.path.exists(fname):
59+
if Path(fname).exists():
6860
assert is_opentype_cff_font(fname)
69-
7061
for f in fontManager.ttflist:
7162
if 'otf' in f.fname:
7263
with open(f.fname, 'rb') as fd:

0 commit comments

Comments
 (0)