|
9 | 9 | import pytest
|
10 | 10 |
|
11 | 11 | 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) |
14 | 15 | from matplotlib import pyplot as plt, rc_context
|
15 | 16 |
|
16 | 17 | has_fclist = shutil.which('fc-list') is not None
|
@@ -124,3 +125,29 @@ def test_find_ttc():
|
124 | 125 | fig.savefig(BytesIO(), format="pdf")
|
125 | 126 | with pytest.raises(RuntimeError):
|
126 | 127 | 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