diff options
author | Keewis <keewis@posteo.de> | 2020-08-04 11:25:57 +0200 |
---|---|---|
committer | Keewis <keewis@posteo.de> | 2020-08-04 11:25:57 +0200 |
commit | 697fc8b16c211dc8515afd3f6df8d7c3baca469d (patch) | |
tree | 235b8c05e0775e77dccee1165f1c6489f74b5fc6 | |
parent | 2e3e22ee03f7093f62c53cab8efe0d21e79d2c14 (diff) | |
download | sphinx-git-697fc8b16c211dc8515afd3f6df8d7c3baca469d.tar.gz |
add test for the raises, yields and returns sections
-rw-r--r-- | tests/test_ext_napoleon_docstring.py | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index 56812d193..017737387 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -1609,6 +1609,20 @@ Example Function Raises ------ +CustomError + If the dimensions couldn't be parsed. + +""", """ +Example Function + +:raises package.CustomError: If the dimensions couldn't be parsed. +"""), + ################################ + (""" +Example Function + +Raises +------ :class:`exc.InvalidDimensionsError` :class:`exc.InvalidArgumentsError` @@ -1619,7 +1633,7 @@ Example Function :raises exc.InvalidArgumentsError: """)] for docstring, expected in docstrings: - config = Config() + config = Config(napoleon_type_aliases={"CustomError": "package.CustomError"}) app = mock.Mock() actual = str(NumpyDocstring(docstring, config, app, "method")) self.assertEqual(expected, actual) @@ -1646,6 +1660,43 @@ Example Function actual = str(NumpyDocstring(docstring, config, app, "method")) self.assertEqual(expected, actual) + docstring = """ +Example Function + +Returns +------- +ndarray + A :math:`n \\times 2` array containing + a bunch of math items +""" + config = Config(napoleon_type_aliases={"ndarray": ":class:`numpy.ndarray`"}) + actual = str(NumpyDocstring(docstring, config, app, "method")) + self.assertEqual(expected, actual) + + def test_yield_types(self): + docstring = dedent(""" + Example Function + + Yields + ------ + scalar or array-like + The result of the computation + """) + expected = dedent(""" + Example Function + + :Yields: :term:`scalar` or :class:`array-like <numpy.ndarray>` -- The result of the computation + """) + config = Config( + napoleon_type_aliases={ + "scalar": ":term:`scalar`", + "array-like": ":class:`array-like <numpy.ndarray>`", + } + ) + app = mock.Mock() + actual = str(NumpyDocstring(docstring, config, app, "method")) + self.assertEqual(expected, actual) + def test_section_header_underline_length(self): docstrings = [(""" Summary line |