diff options
author | Pauli Virtanen <pav@iki.fi> | 2010-10-01 11:15:38 +0200 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-10-01 12:13:21 +0200 |
commit | 4510c4a81185eed7e144f75ec5121f80bc924a6e (patch) | |
tree | ceadb6c8e7c06d134d2e1823f4475d2d1b4ef6c6 | |
parent | 75cebc1b71a161b18a45f291b97595c1f391ca46 (diff) | |
download | numpy-4510c4a81185eed7e144f75ec5121f80bc924a6e.tar.gz |
sphinxext: fix Other Parameters section parsing in docscrape
-rw-r--r-- | doc/sphinxext/docscrape.py | 7 | ||||
-rw-r--r-- | doc/sphinxext/docscrape_sphinx.py | 3 | ||||
-rw-r--r-- | doc/sphinxext/tests/test_docscrape.py | 76 |
3 files changed, 79 insertions, 7 deletions
diff --git a/doc/sphinxext/docscrape.py b/doc/sphinxext/docscrape.py index 63fec42ad..615ea11f8 100644 --- a/doc/sphinxext/docscrape.py +++ b/doc/sphinxext/docscrape.py @@ -284,8 +284,8 @@ class NumpyDocString(object): for (section,content) in self._read_sections(): if not section.startswith('..'): section = ' '.join([s.capitalize() for s in section.split(' ')]) - if section in ('Parameters', 'Attributes', 'Methods', - 'Returns', 'Raises', 'Warns'): + if section in ('Parameters', 'Returns', 'Raises', 'Warns', + 'Other Parameters', 'Attributes', 'Methods'): self[section] = self._parse_param_list(content) elif section.startswith('.. index::'): self['index'] = self._parse_index(section, content) @@ -381,7 +381,8 @@ class NumpyDocString(object): out += self._str_signature() out += self._str_summary() out += self._str_extended_summary() - for param_list in ('Parameters','Returns','Raises'): + for param_list in ('Parameters', 'Returns', 'Other Parameters', + 'Raises', 'Warns'): out += self._str_param_list(param_list) out += self._str_section('Warnings') out += self._str_see_also(func_role) diff --git a/doc/sphinxext/docscrape_sphinx.py b/doc/sphinxext/docscrape_sphinx.py index 9f4350d46..e44e770ef 100644 --- a/doc/sphinxext/docscrape_sphinx.py +++ b/doc/sphinxext/docscrape_sphinx.py @@ -178,7 +178,8 @@ class SphinxDocString(NumpyDocString): out += self._str_index() + [''] out += self._str_summary() out += self._str_extended_summary() - for param_list in ('Parameters', 'Returns', 'Raises'): + for param_list in ('Parameters', 'Returns', 'Other Parameters', + 'Raises', 'Warns'): out += self._str_param_list(param_list) out += self._str_warnings() out += self._str_see_also(func_role) diff --git a/doc/sphinxext/tests/test_docscrape.py b/doc/sphinxext/tests/test_docscrape.py index 1d775e99e..6fab79832 100644 --- a/doc/sphinxext/tests/test_docscrape.py +++ b/doc/sphinxext/tests/test_docscrape.py @@ -8,7 +8,7 @@ from docscrape_sphinx import SphinxDocString, SphinxClassDoc from nose.tools import * doc_txt = '''\ - numpy.multivariate_normal(mean, cov, shape=None) + numpy.multivariate_normal(mean, cov, shape=None, spam=None) Draw values from a multivariate normal distribution with specified mean and covariance. @@ -42,6 +42,21 @@ doc_txt = '''\ In other words, each entry ``out[i,j,...,:]`` is an N-dimensional value drawn from the distribution. + Other Parameters + ---------------- + spam : parrot + A parrot off its mortal coil. + + Raises + ------ + RuntimeError + Some error + + Warns + ----- + RuntimeWarning + Some warning + Warnings -------- Certain warnings apply. @@ -102,7 +117,7 @@ doc = NumpyDocString(doc_txt) def test_signature(): assert doc['Signature'].startswith('numpy.multivariate_normal(') - assert doc['Signature'].endswith('shape=None)') + assert doc['Signature'].endswith('spam=None)') def test_summary(): assert doc['Summary'][0].startswith('Draw values') @@ -120,6 +135,13 @@ def test_parameters(): assert desc[0].startswith('Covariance matrix') assert doc['Parameters'][0][-1][-2] == ' (1+2+3)/3' +def test_other_parameters(): + assert_equal(len(doc['Other Parameters']), 1) + assert_equal([n for n,_,_ in doc['Other Parameters']], ['spam']) + arg, arg_type, desc = doc['Other Parameters'][0] + assert_equal(arg_type, 'parrot') + assert desc[0].startswith('A parrot off its mortal coil') + def test_returns(): assert_equal(len(doc['Returns']), 1) arg, arg_type, desc = doc['Returns'][0] @@ -157,7 +179,7 @@ def non_blank_line_by_line_compare(a,b): (n,line,b[n])) def test_str(): non_blank_line_by_line_compare(str(doc), -"""numpy.multivariate_normal(mean, cov, shape=None) +"""numpy.multivariate_normal(mean, cov, shape=None, spam=None) Draw values from a multivariate normal distribution with specified mean and covariance. @@ -191,6 +213,21 @@ out : ndarray In other words, each entry ``out[i,j,...,:]`` is an N-dimensional value drawn from the distribution. +Other Parameters +---------------- +spam : parrot + A parrot off its mortal coil. + +Raises +------ +RuntimeError : + Some error + +Warns +----- +RuntimeWarning : + Some warning + Warnings -------- Certain warnings apply. @@ -291,6 +328,24 @@ of the one-dimensional normal distribution to higher dimensions. In other words, each entry ``out[i,j,...,:]`` is an N-dimensional value drawn from the distribution. +:Other Parameters: + + **spam** : parrot + + A parrot off its mortal coil. + +:Raises: + + **RuntimeError** : + + Some error + +:Warns: + + **RuntimeWarning** : + + Some warning + .. warning:: Certain warnings apply. @@ -390,6 +445,10 @@ doc5 = NumpyDocString( LinAlgException If array is singular. + Warns + ----- + SomeWarning + If needed """) def test_raises(): @@ -398,6 +457,12 @@ def test_raises(): assert_equal(name,'LinAlgException') assert_equal(desc,['If array is singular.']) +def test_warns(): + assert_equal(len(doc5['Warns']), 1) + name,_,desc = doc5['Warns'][0] + assert_equal(name,'SomeWarning') + assert_equal(desc,['If needed']) + def test_see_also(): doc6 = NumpyDocString( """ @@ -543,3 +608,8 @@ def test_class_members(): if cls is SphinxClassDoc: assert '.. autosummary::' in str(doc), str(doc) + +if __name__ == "__main__": + import nose + nose.run() + |