Smoke test that addfont() accepts pathlib.Path.
(monkeypatch)
| 229 | |
| 230 | |
| 231 | def test_addfont_as_path(monkeypatch): |
| 232 | """Smoke test that addfont() accepts pathlib.Path.""" |
| 233 | font_test_file = 'mpltest.ttf' |
| 234 | path = Path(__file__).parent / 'data' / font_test_file |
| 235 | try: |
| 236 | fontManager.addfont(path) |
| 237 | assert fontManager.findfont('mpltest:weight=500') == FontPath(path, 0) |
| 238 | with monkeypatch.context() as m, pytest.raises(ValueError): |
| 239 | m.setenv('MPL_IGNORE_SYSTEM_FONTS', 'true') # Can only find internal fonts. |
| 240 | fontManager.findfont('mpltest:weight=500', fallback_to_default=False) |
| 241 | added, = (font for font in fontManager.ttflist |
| 242 | if font.fname.endswith(font_test_file)) |
| 243 | fontManager.ttflist.remove(added) |
| 244 | finally: |
| 245 | to_remove = [font for font in fontManager.ttflist |
| 246 | if font.fname.endswith(font_test_file)] |
| 247 | for font in to_remove: |
| 248 | fontManager.ttflist.remove(font) |
| 249 | |
| 250 | |
| 251 | @pytest.mark.skipif(sys.platform != 'win32', reason='Windows only') |