Skip to content

Commit b7acfb2

Browse files
committed
Add a test which checks wheter a font in the user directory is found
1 parent 69b68ed commit b7acfb2

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

lib/matplotlib/tests/test_font_manager.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import pytest
1010

1111
from matplotlib.font_manager import (
12-
findfont, FontProperties, fontManager, json_dump, json_load, get_font,
13-
get_fontconfig_fonts, is_opentype_cff_font)
12+
findfont, findSystemFonts, FontProperties, fontManager, json_dump,
13+
json_load, get_font, get_fontconfig_fonts, is_opentype_cff_font,
14+
MSUserFontDirectories)
1415
from matplotlib import pyplot as plt, rc_context
1516

1617
has_fclist = shutil.which('fc-list') is not None
@@ -124,3 +125,29 @@ def test_find_ttc():
124125
fig.savefig(BytesIO(), format="pdf")
125126
with pytest.raises(RuntimeError):
126127
fig.savefig(BytesIO(), format="ps")
128+
129+
130+
def test_user_fonts():
131+
if not os.environ.get('APPVEYOR', False):
132+
pytest.xfail('This test does only work on appveyor since user fonts '
133+
'are Windows specific')
134+
135+
font_test_file = 'mpltest.ttf'
136+
137+
# Precondition: the test font should not be available
138+
fonts = findSystemFonts()
139+
assert not any(font_test_file in font for font in fonts)
140+
141+
user_fonts_dir = MSUserFontDirectories[0]
142+
143+
# Make sure that the user font directory exists (this is probably not the
144+
# case on Windows versions < 1809)
145+
os.makedirs(user_fonts_dir)
146+
147+
# Copy the test font to the user font directory
148+
shutil.copyfile(os.path.join(os.path.dirname(__file__), font_test_file),
149+
os.path.join(user_fonts_dir, font_test_file))
150+
151+
# Now, the font should be available
152+
fonts = findSystemFonts()
153+
assert any(font_test_file in font for font in fonts)

0 commit comments

Comments
 (0)