1- import os
1+ from pathlib import Path
22import shutil
3- import tempfile
43import warnings
54
65import 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
6557def 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