|
12 | 12 | from matplotlib.font_manager import (
|
13 | 13 | findfont, findSystemFonts, FontProperties, fontManager, json_dump,
|
14 | 14 | json_load, get_font, get_fontconfig_fonts, is_opentype_cff_font,
|
15 |
| - MSUserFontDirectories) |
| 15 | + MSUserFontDirectories, _call_fc_list) |
16 | 16 | from matplotlib import pyplot as plt, rc_context
|
17 | 17 |
|
18 | 18 | has_fclist = shutil.which('fc-list') is not None
|
@@ -131,7 +131,33 @@ def test_find_ttc():
|
131 | 131 | fig.savefig(BytesIO(), format="ps")
|
132 | 132 |
|
133 | 133 |
|
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(): |
135 | 161 | if not os.environ.get('APPVEYOR', False):
|
136 | 162 | pytest.xfail('This test does only work on appveyor since user fonts '
|
137 | 163 | 'are Windows specific and the developer\'s font '
|
|
0 commit comments