1
- import os
1
+ from pathlib import Path
2
2
import shutil
3
- import tempfile
4
3
import warnings
5
4
6
5
import numpy as np
@@ -18,9 +17,8 @@ def test_font_priority():
18
17
with rc_context (rc = {
19
18
'font.sans-serif' :
20
19
['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'
24
22
25
23
# Smoketest get_charmap, which isn't used internally anymore
26
24
font = get_font (font )
@@ -40,18 +38,12 @@ def test_score_weight():
40
38
fontManager .score_weight (400 , 400 ))
41
39
42
40
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 )
55
47
with warnings .catch_warnings ():
56
48
warnings .filterwarnings ('ignore' , 'findfont: Font family.*not found' )
57
49
for prop in ({'family' : 'STIXGeneral' },
@@ -64,9 +56,8 @@ def test_json_serialization():
64
56
65
57
def test_otf ():
66
58
fname = '/usr/share/fonts/opentype/freefont/FreeMono.otf'
67
- if os . path . exists (fname ):
59
+ if Path ( fname ). exists ():
68
60
assert is_opentype_cff_font (fname )
69
-
70
61
for f in fontManager .ttflist :
71
62
if 'otf' in f .fname :
72
63
with open (f .fname , 'rb' ) as fd :
0 commit comments