44import six
55
66import io
7+ import re
78
89import numpy as np
10+ import pytest
11+
912import matplotlib
1013from matplotlib .testing .decorators import image_comparison , knownfailureif , cleanup
1114import matplotlib .pyplot as plt
@@ -195,8 +198,10 @@ def test_fontinfo():
195198 table = font .get_sfnt_table ("head" )
196199 assert table ['version' ] == (1 , 0 )
197200
198- def test_mathtext_exceptions ():
199- errors = [
201+
202+ @pytest .mark .parametrize (
203+ 'math, msg' ,
204+ [
200205 (r'$\hspace{}$' , r'Expected \hspace{n}' ),
201206 (r'$\hspace{foo}$' , r'Expected \hspace{n}' ),
202207 (r'$\frac$' , r'Expected \frac{num}{den}' ),
@@ -205,28 +210,47 @@ def test_mathtext_exceptions():
205210 (r'$\stackrel{}{}$' , r'Expected \stackrel{num}{den}' ),
206211 (r'$\binom$' , r'Expected \binom{num}{den}' ),
207212 (r'$\binom{}{}$' , r'Expected \binom{num}{den}' ),
208- (r'$\genfrac$' , r'Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}' ),
209- (r'$\genfrac{}{}{}{}{}{}$' , r'Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}' ),
213+ (r'$\genfrac$' ,
214+ r'Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}' ),
215+ (r'$\genfrac{}{}{}{}{}{}$' ,
216+ r'Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}' ),
210217 (r'$\sqrt$' , r'Expected \sqrt{value}' ),
211218 (r'$\sqrt f$' , r'Expected \sqrt{value}' ),
212219 (r'$\overline$' , r'Expected \overline{value}' ),
213220 (r'$\overline{}$' , r'Expected \overline{value}' ),
214221 (r'$\leftF$' , r'Expected a delimiter' ),
215222 (r'$\rightF$' , r'Unknown symbol: \rightF' ),
216223 (r'$\left(\right$' , r'Expected a delimiter' ),
217- (r'$\left($' , r'Expected "\right"' )
218- ]
219-
224+ (r'$\left($' , r'Expected "\right"' ),
225+ ],
226+ ids = [
227+ 'hspace without value' ,
228+ 'hspace with invalid value' ,
229+ 'frac without parameters' ,
230+ 'frac with empty parameters' ,
231+ 'stackrel without parameters' ,
232+ 'stackrel with empty parameters' ,
233+ 'binom without parameters' ,
234+ 'binom with empty parameters' ,
235+ 'genfrac without parameters' ,
236+ 'genfrac with empty parameters' ,
237+ 'sqrt without parameters' ,
238+ 'sqrt with invalid value' ,
239+ 'overline without parameters' ,
240+ 'overline with empty parameter' ,
241+ 'left with invalid delimiter' ,
242+ 'right with invalid delimiter' ,
243+ 'unclosed parentheses with sizing' ,
244+ 'unclosed parentheses without sizing' ,
245+ ]
246+ )
247+ def test_mathtext_exceptions (math , msg ):
220248 parser = mathtext .MathTextParser ('agg' )
221249
222- for math , msg in errors :
223- try :
224- parser .parse (math )
225- except ValueError as e :
226- exc = str (e ).split ('\n ' )
227- assert exc [3 ].startswith (msg )
228- else :
229- assert False , "Expected '%s', but didn't get it" % msg
250+ with pytest .raises (ValueError ) as excinfo :
251+ parser .parse (math )
252+ excinfo .match (re .escape (msg ))
253+
230254
231255@cleanup
232256def test_single_minus_sign ():
0 commit comments