77
88import io
99import os
10+ import tempfile
11+
12+ try :
13+ from unittest .mock import patch
14+ except ImportError :
15+ from mock import patch
16+ from nose .tools import raises
1017
1118import numpy as np
12- from matplotlib import cm , rcParams
19+ from matplotlib import checkdep_tex , cm , rcParams
1320from matplotlib .backends .backend_pdf import PdfPages
1421from matplotlib import pyplot as plt
1522from matplotlib .testing .decorators import (image_comparison , knownfailureif ,
1623 cleanup )
24+ from matplotlib import dviread
1725
1826if 'TRAVIS' not in os .environ :
1927 @image_comparison (baseline_images = ['pdf_use14corefonts' ],
@@ -29,6 +37,10 @@ def test_use14corefonts():
2937 and containing some French characters and the euro symbol:
3038 "Merci pépé pour les 10 €"'''
3139
40+ needs_tex = knownfailureif (
41+ not checkdep_tex (),
42+ "This test needs a TeX installation" )
43+
3244
3345@cleanup
3446def test_type42 ():
@@ -132,3 +144,19 @@ def test_grayscale_alpha():
132144 ax .imshow (dd , interpolation = 'none' , cmap = 'gray_r' )
133145 ax .set_xticks ([])
134146 ax .set_yticks ([])
147+
148+
149+ @cleanup
150+ @needs_tex
151+ @raises (ValueError )
152+ @patch ('matplotlib.dviread.PsfontsMap.__getitem__' )
153+ def test_missing_psfont (mock ):
154+ """An error is raised if a TeX font lacks a Type-1 equivalent"""
155+ psfont = dviread .PsFont (texname = 'texfont' , psname = 'Some Font' ,
156+ effects = None , encoding = None , filename = None )
157+ mock .configure_mock (return_value = psfont )
158+ rcParams ['text.usetex' ] = True
159+ fig , ax = plt .subplots ()
160+ ax .text (0.5 , 0.5 , 'hello' )
161+ with tempfile .TemporaryFile () as tmpfile :
162+ fig .savefig (tmpfile , format = 'pdf' )
0 commit comments