Skip to content

Commit 659e43f

Browse files
ev-brjnothman
authored andcommitted
MAINT switch the test suite to pytest (#166)
1 parent 95e8888 commit 659e43f

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ cache:
1717
before_install:
1818
- sudo apt-get install texlive texlive-latex-extra latexmk
1919
- pip install --upgrade pip setuptools # Upgrade pip and setuptools to get ones with `wheel` support
20-
- pip install nose numpy matplotlib ${SPHINX_SPEC}
20+
- pip install pytest numpy matplotlib ${SPHINX_SPEC}
2121
script:
2222
- |
2323
python setup.py sdist
2424
cd dist
2525
pip install numpydoc* -v
26-
- nosetests numpydoc
26+
- pytest --pyargs numpydoc
2727
- |
2828
cd ../doc
2929
make SPHINXOPTS=$SPHINXOPTS html

numpydoc/tests/test_docscrape.py

+49-49
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
)
1717
from numpydoc.docscrape_sphinx import (SphinxDocString, SphinxClassDoc,
1818
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
2120

22-
assert_list_equal.__self__.maxDiff = None
2321

2422
if sys.version_info[0] >= 3:
2523
sixu = lambda s: s
@@ -167,52 +165,53 @@ def test_extended_summary():
167165

168166

169167
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']))
172171

173172
arg, arg_type, desc = doc['Parameters'][1]
174-
assert_equal(arg_type, '(N, N) ndarray')
173+
assert arg_type == '(N, N) ndarray'
175174
assert desc[0].startswith('Covariance matrix')
176175
assert doc['Parameters'][0][-1][-1] == ' (1+2+3)/3'
177176

178177

179178
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']
182181
arg, arg_type, desc = doc['Other Parameters'][0]
183-
assert_equal(arg_type, 'parrot')
182+
assert arg_type == 'parrot'
184183
assert desc[0].startswith('A parrot off its mortal coil')
185184

186185

187186
def test_returns():
188-
assert_equal(len(doc['Returns']), 3)
187+
assert len(doc['Returns']) == 3
189188
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'
192191
assert desc[0].startswith('The drawn samples')
193192
assert desc[-1].endswith('distribution.')
194193

195194
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 == ''
198197
assert desc[0].startswith('This is not a real')
199198
assert desc[-1].endswith('anonymous return values.')
200199

201200
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 == ''
204203
assert not ''.join(desc).strip()
205204

206205

207206
def test_yields():
208207
section = doc_yields['Yields']
209-
assert_equal(len(section), 3)
208+
assert len(section) == 3
210209
truth = [('a', 'int', 'apples.'),
211210
('b', 'int', 'bananas.'),
212211
('int', '', 'unknowns.')]
213212
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_
216215
assert desc[0].startswith('The number of')
217216
assert desc[0].endswith(end)
218217

@@ -290,21 +289,21 @@ def dummy_func(arg):
290289
SphinxClassDoc(Dummy)
291290
except ValueError as e:
292291
# 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))
295294

296295
try:
297296
SphinxFunctionDoc(dummy_func)
298297
except ValueError as e:
299298
# 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))
302301

303302

304303
def test_notes():
305304
assert doc['Notes'][0].startswith('Instead')
306305
assert doc['Notes'][-1].endswith('definite.')
307-
assert_equal(len(doc['Notes']), 17)
306+
assert len(doc['Notes']) == 17
308307

309308

310309
def test_references():
@@ -318,9 +317,9 @@ def test_examples():
318317

319318

320319
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
324323

325324

326325
def _strip_blank_lines(s):
@@ -336,7 +335,7 @@ def line_by_line_compare(a, b):
336335
b = textwrap.dedent(b)
337336
a = [l.rstrip() for l in _strip_blank_lines(a).split('\n')]
338337
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))
340339

341340

342341
def test_str():
@@ -620,7 +619,7 @@ def test_sphinx_yields_str():
620619

621620

622621
def test_parameters_without_extended_description():
623-
assert_equal(len(doc2['Parameters']), 2)
622+
assert len(doc2['Parameters']) == 2
624623

625624

626625
doc3 = NumpyDocString("""
@@ -632,13 +631,13 @@ def test_parameters_without_extended_description():
632631

633632
def test_escape_stars():
634633
signature = str(doc3).split('\n')[0]
635-
assert_equal(signature, 'my_signature(\*params, \*\*kwds)')
634+
assert signature == 'my_signature(\*params, \*\*kwds)'
636635

637636
def my_func(a, b, **kwargs):
638637
pass
639638

640639
fdoc = FunctionDoc(func=my_func)
641-
assert_equal(fdoc['Signature'], 'my_func(a, b, \*\*kwargs)')
640+
assert fdoc['Signature'] == 'my_func(a, b, \*\*kwargs)'
642641

643642

644643
doc4 = NumpyDocString(
@@ -648,7 +647,7 @@ def my_func(a, b, **kwargs):
648647

649648

650649
def test_empty_extended_summary():
651-
assert_equal(doc4['Extended Summary'], [])
650+
assert doc4['Extended Summary'] == []
652651

653652

654653
doc5 = NumpyDocString(
@@ -668,17 +667,17 @@ def test_empty_extended_summary():
668667

669668

670669
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.']
675674

676675

677676
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']
682681

683682

684683
def test_see_also():
@@ -737,10 +736,11 @@ def test_see_also_parse_error():
737736
""")
738737
with assert_raises(ParseError) as err:
739738
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+
744744

745745
def test_see_also_print():
746746
class Dummy(object):
@@ -787,9 +787,9 @@ class BadSection(object):
787787
with warnings.catch_warnings(record=True) as w:
788788
SphinxClassDoc(BadSection)
789789
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))
793793

794794

795795
doc7 = NumpyDocString("""
@@ -1253,5 +1253,5 @@ def test_args_and_kwargs():
12531253

12541254

12551255
if __name__ == "__main__":
1256-
import nose
1257-
nose.run()
1256+
import pytest
1257+
pytest.main()

0 commit comments

Comments
 (0)