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