diff options
| author | Rob Ruana <rob@relentlessidiot.com> | 2014-03-09 22:07:21 -0400 |
|---|---|---|
| committer | Rob Ruana <rob@relentlessidiot.com> | 2014-03-09 22:07:21 -0400 |
| commit | 01d98d34ad010f38204540677e447a3d38adee4e (patch) | |
| tree | 73dd8a5828e78ce01dd65f21347c6b2d82bcb4ca /tests | |
| parent | 0deddff3813aefd50fb7d853584d0a9330bf063c (diff) | |
| download | sphinx-01d98d34ad010f38204540677e447a3d38adee4e.tar.gz | |
Closes #1384: Parse and interpret See Also section the way NumpyDoc does
The NumpyDoc extension that is developed by the Numpy folks does a lot
of extra work interpreting See Also sections. It assumes that the contents
of the See Also will always be references to other functions/classes and
it tries to deduce what is being referenced.
I've ported their implementation for See Also sections written in the
Numpy style. There is NO extra interpretation done for See Also sections
that are written using the Google style.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_napoleon_docstring.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_napoleon_docstring.py b/tests/test_napoleon_docstring.py index 7d5e3ad8..61b9efe2 100644 --- a/tests/test_napoleon_docstring.py +++ b/tests/test_napoleon_docstring.py @@ -15,6 +15,12 @@ from sphinx.ext.napoleon import Config from sphinx.ext.napoleon.docstring import GoogleDocstring, NumpyDocstring from unittest import TestCase +try: + # Python >=3.3 + from unittest.mock import Mock +except ImportError: + from mock import Mock + class BaseDocstringTest(TestCase): pass @@ -306,3 +312,50 @@ class NumpyDocstringTest(BaseDocstringTest): :type param1: MyClass instance """) self.assertEqual(expected, actual) + + def test_see_also_refs(self): + docstring = """ + numpy.multivariate_normal(mean, cov, shape=None, spam=None) + + See Also + -------- + some, other, funcs + otherfunc : relationship + + """ + + actual = str(NumpyDocstring(textwrap.dedent(docstring))) + + expected = """ +numpy.multivariate_normal(mean, cov, shape=None, spam=None) + +.. seealso:: +\n :obj:`some`, :obj:`other`, :obj:`funcs` + \n :obj:`otherfunc` + relationship +""" + self.assertEqual(expected, actual) + + docstring = """ + numpy.multivariate_normal(mean, cov, shape=None, spam=None) + + See Also + -------- + some, other, funcs + otherfunc : relationship + + """ + + config = Config() + app = Mock() + actual = str(NumpyDocstring(textwrap.dedent(docstring), config, app, "method")) + + expected = """ +numpy.multivariate_normal(mean, cov, shape=None, spam=None) + +.. seealso:: +\n :meth:`some`, :meth:`other`, :meth:`funcs` + \n :meth:`otherfunc` + relationship +""" + self.assertEqual(expected, actual) |
