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

Skip to content

Commit 4b5a2db

Browse files
committed
Add a test that XDG font directories work.
1 parent c25d273 commit 4b5a2db

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

lib/matplotlib/tests/test_font_manager.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from matplotlib.font_manager import (
1313
findfont, findSystemFonts, FontProperties, fontManager, json_dump,
1414
json_load, get_font, get_fontconfig_fonts, is_opentype_cff_font,
15-
MSUserFontDirectories)
15+
MSUserFontDirectories, _call_fc_list)
1616
from matplotlib import pyplot as plt, rc_context
1717

1818
has_fclist = shutil.which('fc-list') is not None
@@ -131,7 +131,33 @@ def test_find_ttc():
131131
fig.savefig(BytesIO(), format="ps")
132132

133133

134-
def test_user_fonts():
134+
@pytest.mark.skipif(sys.platform != 'linux', reason='Linux only')
135+
def test_user_fonts_linux(tmpdir, monkeypatch):
136+
font_test_file = 'mpltest.ttf'
137+
138+
# Precondition: the test font should not be available
139+
fonts = findSystemFonts()
140+
assert not any(font_test_file in font for font in fonts)
141+
142+
# Prepare a temporary user font directory
143+
user_fonts_dir = tmpdir.join('fonts')
144+
user_fonts_dir.ensure(dir=True)
145+
shutil.copyfile(Path(__file__).parent / font_test_file,
146+
user_fonts_dir.join(font_test_file))
147+
148+
with monkeypatch.context() as m:
149+
m.setenv('XDG_DATA_HOME', str(tmpdir))
150+
_call_fc_list.cache_clear()
151+
# Now, the font should be available
152+
fonts = findSystemFonts()
153+
assert any(font_test_file in font for font in fonts)
154+
155+
# Make sure the temporary directory is no longer cached.
156+
_call_fc_list.cache_clear()
157+
158+
159+
@pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')
160+
def test_user_fonts_win32():
135161
if not os.environ.get('APPVEYOR', False):
136162
pytest.xfail('This test does only work on appveyor since user fonts '
137163
'are Windows specific and the developer\'s font '

0 commit comments

Comments
 (0)