16
16
)
17
17
from numpydoc .docscrape_sphinx import (SphinxDocString , SphinxClassDoc ,
18
18
SphinxFunctionDoc , get_doc_object )
19
- from nose .tools import (assert_equal , assert_raises , assert_list_equal ,
20
- assert_true )
19
+ from pytest import raises as assert_raises
21
20
22
- assert_list_equal .__self__ .maxDiff = None
23
21
24
22
if sys .version_info [0 ] >= 3 :
25
23
sixu = lambda s : s
@@ -167,52 +165,53 @@ def test_extended_summary():
167
165
168
166
169
167
def test_parameters ():
170
- assert_equal (len (doc ['Parameters' ]), 3 )
171
- assert_equal ([n for n ,_ ,_ in doc ['Parameters' ]], ['mean' ,'cov' ,'shape' ])
168
+ assert len (doc ['Parameters' ]) == 3
169
+ names = [n for n , _ , _ in doc ['Parameters' ]]
170
+ assert all (a == b for a , b in zip (names , ['mean' , 'cov' , 'shape' ]))
172
171
173
172
arg , arg_type , desc = doc ['Parameters' ][1 ]
174
- assert_equal ( arg_type , '(N, N) ndarray' )
173
+ assert arg_type == '(N, N) ndarray'
175
174
assert desc [0 ].startswith ('Covariance matrix' )
176
175
assert doc ['Parameters' ][0 ][- 1 ][- 1 ] == ' (1+2+3)/3'
177
176
178
177
179
178
def test_other_parameters ():
180
- assert_equal ( len (doc ['Other Parameters' ]), 1 )
181
- assert_equal ( [n for n ,_ , _ in doc ['Other Parameters' ]], ['spam' ])
179
+ assert len (doc ['Other Parameters' ]) == 1
180
+ assert [n for n , _ , _ in doc ['Other Parameters' ]] == ['spam' ]
182
181
arg , arg_type , desc = doc ['Other Parameters' ][0 ]
183
- assert_equal ( arg_type , 'parrot' )
182
+ assert arg_type == 'parrot'
184
183
assert desc [0 ].startswith ('A parrot off its mortal coil' )
185
184
186
185
187
186
def test_returns ():
188
- assert_equal ( len (doc ['Returns' ]), 3 )
187
+ assert len (doc ['Returns' ]) == 3
189
188
arg , arg_type , desc = doc ['Returns' ][0 ]
190
- assert_equal ( arg , 'out' )
191
- assert_equal ( arg_type , 'ndarray' )
189
+ assert arg == 'out'
190
+ assert arg_type == 'ndarray'
192
191
assert desc [0 ].startswith ('The drawn samples' )
193
192
assert desc [- 1 ].endswith ('distribution.' )
194
193
195
194
arg , arg_type , desc = doc ['Returns' ][1 ]
196
- assert_equal ( arg , 'list of str' )
197
- assert_equal ( arg_type , '' )
195
+ assert arg == 'list of str'
196
+ assert arg_type == ''
198
197
assert desc [0 ].startswith ('This is not a real' )
199
198
assert desc [- 1 ].endswith ('anonymous return values.' )
200
199
201
200
arg , arg_type , desc = doc ['Returns' ][2 ]
202
- assert_equal ( arg , 'no_description' )
203
- assert_equal ( arg_type , '' )
201
+ assert arg == 'no_description'
202
+ assert arg_type == ''
204
203
assert not '' .join (desc ).strip ()
205
204
206
205
207
206
def test_yields ():
208
207
section = doc_yields ['Yields' ]
209
- assert_equal ( len (section ), 3 )
208
+ assert len (section ) == 3
210
209
truth = [('a' , 'int' , 'apples.' ),
211
210
('b' , 'int' , 'bananas.' ),
212
211
('int' , '' , 'unknowns.' )]
213
212
for (arg , arg_type , desc ), (arg_ , arg_type_ , end ) in zip (section , truth ):
214
- assert_equal ( arg , arg_ )
215
- assert_equal ( arg_type , arg_type_ )
213
+ assert arg == arg_
214
+ assert arg_type == arg_type_
216
215
assert desc [0 ].startswith ('The number of' )
217
216
assert desc [0 ].endswith (end )
218
217
@@ -290,21 +289,21 @@ def dummy_func(arg):
290
289
SphinxClassDoc (Dummy )
291
290
except ValueError as e :
292
291
# python 3 version or python 2 version
293
- assert_true ("test_section_twice.<locals>.Dummy" in str (e )
294
- or 'test_docscrape.Dummy' in str (e ))
292
+ assert ("test_section_twice.<locals>.Dummy" in str (e )
293
+ or 'test_docscrape.Dummy' in str (e ))
295
294
296
295
try :
297
296
SphinxFunctionDoc (dummy_func )
298
297
except ValueError as e :
299
298
# python 3 version or python 2 version
300
- assert_true ("test_section_twice.<locals>.dummy_func" in str (e )
301
- or 'function dummy_func' in str (e ))
299
+ assert ("test_section_twice.<locals>.dummy_func" in str (e )
300
+ or 'function dummy_func' in str (e ))
302
301
303
302
304
303
def test_notes ():
305
304
assert doc ['Notes' ][0 ].startswith ('Instead' )
306
305
assert doc ['Notes' ][- 1 ].endswith ('definite.' )
307
- assert_equal ( len (doc ['Notes' ]), 17 )
306
+ assert len (doc ['Notes' ]) == 17
308
307
309
308
310
309
def test_references ():
@@ -318,9 +317,9 @@ def test_examples():
318
317
319
318
320
319
def test_index ():
321
- assert_equal ( doc ['index' ]['default' ], 'random' )
322
- assert_equal ( len (doc ['index' ]), 2 )
323
- assert_equal ( len (doc ['index' ]['refguide' ]), 2 )
320
+ assert doc ['index' ]['default' ] == 'random'
321
+ assert len (doc ['index' ]) == 2
322
+ assert len (doc ['index' ]['refguide' ]) == 2
324
323
325
324
326
325
def _strip_blank_lines (s ):
@@ -336,7 +335,7 @@ def line_by_line_compare(a, b):
336
335
b = textwrap .dedent (b )
337
336
a = [l .rstrip () for l in _strip_blank_lines (a ).split ('\n ' )]
338
337
b = [l .rstrip () for l in _strip_blank_lines (b ).split ('\n ' )]
339
- assert_list_equal ( a , b )
338
+ assert all ( x == y for x , y in zip ( a , b ) )
340
339
341
340
342
341
def test_str ():
@@ -620,7 +619,7 @@ def test_sphinx_yields_str():
620
619
621
620
622
621
def test_parameters_without_extended_description ():
623
- assert_equal ( len (doc2 ['Parameters' ]), 2 )
622
+ assert len (doc2 ['Parameters' ]) == 2
624
623
625
624
626
625
doc3 = NumpyDocString ("""
@@ -632,13 +631,13 @@ def test_parameters_without_extended_description():
632
631
633
632
def test_escape_stars ():
634
633
signature = str (doc3 ).split ('\n ' )[0 ]
635
- assert_equal ( signature , 'my_signature(\*params, \*\*kwds)' )
634
+ assert signature == 'my_signature(\*params, \*\*kwds)'
636
635
637
636
def my_func (a , b , ** kwargs ):
638
637
pass
639
638
640
639
fdoc = FunctionDoc (func = my_func )
641
- assert_equal ( fdoc ['Signature' ], 'my_func(a, b, \*\*kwargs)' )
640
+ assert fdoc ['Signature' ] == 'my_func(a, b, \*\*kwargs)'
642
641
643
642
644
643
doc4 = NumpyDocString (
@@ -648,7 +647,7 @@ def my_func(a, b, **kwargs):
648
647
649
648
650
649
def test_empty_extended_summary ():
651
- assert_equal ( doc4 ['Extended Summary' ], [])
650
+ assert doc4 ['Extended Summary' ] == []
652
651
653
652
654
653
doc5 = NumpyDocString (
@@ -668,17 +667,17 @@ def test_empty_extended_summary():
668
667
669
668
670
669
def test_raises ():
671
- assert_equal ( len (doc5 ['Raises' ]), 1 )
672
- name ,_ , desc = doc5 ['Raises' ][0 ]
673
- assert_equal ( name , 'LinAlgException' )
674
- assert_equal ( desc , ['If array is singular.' ])
670
+ assert len (doc5 ['Raises' ]) == 1
671
+ name , _ , desc = doc5 ['Raises' ][0 ]
672
+ assert name == 'LinAlgException'
673
+ assert desc == ['If array is singular.' ]
675
674
676
675
677
676
def test_warns ():
678
- assert_equal ( len (doc5 ['Warns' ]), 1 )
679
- name ,_ , desc = doc5 ['Warns' ][0 ]
680
- assert_equal ( name , 'SomeWarning' )
681
- assert_equal ( desc , ['If needed' ])
677
+ assert len (doc5 ['Warns' ]) == 1
678
+ name , _ , desc = doc5 ['Warns' ][0 ]
679
+ assert name == 'SomeWarning'
680
+ assert desc == ['If needed' ]
682
681
683
682
684
683
def test_see_also ():
@@ -737,10 +736,11 @@ def test_see_also_parse_error():
737
736
""" )
738
737
with assert_raises (ParseError ) as err :
739
738
NumpyDocString (text )
740
- assert_equal (
741
- str (r":func:`~foo` is not a item name in '\n z(x,theta)\n\n See Also\n --------\n :func:`~foo`\n '" ),
742
- str (err .exception )
743
- )
739
+
740
+ s1 = str (r":func:`~foo` is not a item name in '\n z(x,theta)\n\n See Also\n --------\n :func:`~foo`\n '" )
741
+ s2 = str (err .value )
742
+ assert s1 == s2
743
+
744
744
745
745
def test_see_also_print ():
746
746
class Dummy (object ):
@@ -787,9 +787,9 @@ class BadSection(object):
787
787
with warnings .catch_warnings (record = True ) as w :
788
788
SphinxClassDoc (BadSection )
789
789
assert len (w ) == 1
790
- assert_true ('test_docscrape.test_unknown_section.<locals>.BadSection'
791
- in str (w [0 ].message )
792
- or 'test_docscrape.BadSection' in str (w [0 ].message ))
790
+ assert ('test_docscrape.test_unknown_section.<locals>.BadSection'
791
+ in str (w [0 ].message )
792
+ or 'test_docscrape.BadSection' in str (w [0 ].message ))
793
793
794
794
795
795
doc7 = NumpyDocString ("""
@@ -1253,5 +1253,5 @@ def test_args_and_kwargs():
1253
1253
1254
1254
1255
1255
if __name__ == "__main__" :
1256
- import nose
1257
- nose . run ()
1256
+ import pytest
1257
+ pytest . main ()
0 commit comments