4
4
import six
5
5
6
6
import io
7
+ import re
7
8
8
9
import numpy as np
10
+ import pytest
11
+
9
12
import matplotlib
10
13
from matplotlib .testing .decorators import image_comparison , knownfailureif , cleanup
11
14
import matplotlib .pyplot as plt
@@ -195,8 +198,10 @@ def test_fontinfo():
195
198
table = font .get_sfnt_table ("head" )
196
199
assert table ['version' ] == (1 , 0 )
197
200
198
- def test_mathtext_exceptions ():
199
- errors = [
201
+
202
+ @pytest .mark .parametrize (
203
+ 'math, msg' ,
204
+ [
200
205
(r'$\hspace{}$' , r'Expected \hspace{n}' ),
201
206
(r'$\hspace{foo}$' , r'Expected \hspace{n}' ),
202
207
(r'$\frac$' , r'Expected \frac{num}{den}' ),
@@ -205,28 +210,47 @@ def test_mathtext_exceptions():
205
210
(r'$\stackrel{}{}$' , r'Expected \stackrel{num}{den}' ),
206
211
(r'$\binom$' , r'Expected \binom{num}{den}' ),
207
212
(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}' ),
210
217
(r'$\sqrt$' , r'Expected \sqrt{value}' ),
211
218
(r'$\sqrt f$' , r'Expected \sqrt{value}' ),
212
219
(r'$\overline$' , r'Expected \overline{value}' ),
213
220
(r'$\overline{}$' , r'Expected \overline{value}' ),
214
221
(r'$\leftF$' , r'Expected a delimiter' ),
215
222
(r'$\rightF$' , r'Unknown symbol: \rightF' ),
216
223
(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 ):
220
248
parser = mathtext .MathTextParser ('agg' )
221
249
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
+
230
254
231
255
@cleanup
232
256
def test_single_minus_sign ():
@@ -243,8 +267,3 @@ def test_single_minus_sign():
243
267
244
268
# If this fails, it would be all white
245
269
assert not np .all (array == 0xff )
246
-
247
-
248
- if __name__ == '__main__' :
249
- import nose
250
- nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments