MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_addfont_as_path

Function test_addfont_as_path

lib/matplotlib/tests/test_font_manager.py:231–248  ·  view source on GitHub ↗

Smoke test that addfont() accepts pathlib.Path.

(monkeypatch)

Source from the content-addressed store, hash-verified

229
230
231def 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')

Callers

nothing calls this directly

Calls 5

FontPathClass · 0.90
PathClass · 0.85
addfontMethod · 0.80
findfontMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…