|
2 | 2 | import multiprocessing |
3 | 3 | import os |
4 | 4 | from pathlib import Path |
| 5 | +from PIL import Image |
5 | 6 | import shutil |
6 | 7 | import subprocess |
7 | 8 | import sys |
|
11 | 12 | import pytest |
12 | 13 |
|
13 | 14 | from matplotlib.font_manager import ( |
14 | | - findfont, findSystemFonts, FontProperties, fontManager, json_dump, |
15 | | - json_load, get_font, is_opentype_cff_font, MSUserFontDirectories, |
16 | | - _get_fontconfig_fonts, ft2font, ttfFontProperty, cbook) |
| 15 | + findfont, findSystemFonts, FontEntry, FontProperties, fontManager, |
| 16 | + json_dump, json_load, get_font, is_opentype_cff_font, |
| 17 | + MSUserFontDirectories, _get_fontconfig_fonts, ft2font, |
| 18 | + ttfFontProperty, cbook) |
17 | 19 | from matplotlib import pyplot as plt, rc_context |
18 | 20 |
|
19 | 21 | has_fclist = shutil.which('fc-list') is not None |
@@ -268,6 +270,24 @@ def test_fontcache_thread_safe(): |
268 | 270 | f"{proc.returncode}.") |
269 | 271 |
|
270 | 272 |
|
| 273 | +def test_fontentry_dataclass(): |
| 274 | + fontent = FontEntry(name='font-name') |
| 275 | + |
| 276 | + png = fontent._repr_png_() |
| 277 | + img = Image.open(BytesIO(png)) |
| 278 | + assert img.width > 0 |
| 279 | + assert img.height > 0 |
| 280 | + |
| 281 | + html = fontent._repr_html_() |
| 282 | + assert html.startswith("<img src=\"data:image/png;base64") |
| 283 | + |
| 284 | + |
| 285 | +def test_fontentry_dataclass_invalid_path(): |
| 286 | + with pytest.raises(FileNotFoundError): |
| 287 | + fontent = FontEntry(fname='/random', name='font-name') |
| 288 | + fontent._repr_html_() |
| 289 | + |
| 290 | + |
271 | 291 | @pytest.mark.skipif(sys.platform == 'win32', reason='Linux or OS only') |
272 | 292 | def test_get_font_names(): |
273 | 293 | paths_mpl = [cbook._get_data_path('fonts', subdir) for subdir in ['ttf']] |
|
0 commit comments