diff options
author | Keewis <keewis@posteo.de> | 2020-08-04 11:35:39 +0200 |
---|---|---|
committer | Keewis <keewis@posteo.de> | 2020-08-04 11:35:39 +0200 |
commit | 278a057104a26e33b6a986f3a1184482b90cdbbd (patch) | |
tree | 8120f11af7b794e88cc5c13b8300367acdfdbd0a | |
parent | fa760c326a1a96e9fe9f373b9b94757dd636e12f (diff) | |
download | sphinx-git-278a057104a26e33b6a986f3a1184482b90cdbbd.tar.gz |
move the return types and yield types tests to above the raises test
-rw-r--r-- | tests/test_ext_napoleon_docstring.py | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index 991e5a232..35e2f36bd 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -1443,6 +1443,51 @@ arg_ : type self.assertEqual(expected, actual) + def test_return_types(self): + docstring = dedent(""" + Returns + ------- + DataFrame + a dataframe + """) + expected = dedent(""" + :returns: a dataframe + :rtype: :class:`~pandas.DataFrame` + """) + translations = { + "DataFrame": "~pandas.DataFrame", + } + config = Config( + napoleon_use_param=True, + napoleon_use_rtype=True, + napoleon_type_aliases=translations, + ) + actual = str(NumpyDocstring(docstring, config)) + 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 + """) + translations = { + "scalar": ":term:`scalar`", + "array-like": ":class:`array-like <numpy.ndarray>`", + } + config = Config(napoleon_type_aliases=translations) + app = mock.Mock() + actual = str(NumpyDocstring(docstring, config, app, "method")) + self.assertEqual(expected, actual) + def test_raises_types(self): docstrings = [(""" Example Function @@ -1660,42 +1705,6 @@ 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 - """) - translations = { - "scalar": ":term:`scalar`", - "array-like": ":class:`array-like <numpy.ndarray>`", - } - config = Config(napoleon_type_aliases=translations) - app = mock.Mock() - actual = str(NumpyDocstring(docstring, config, app, "method")) - self.assertEqual(expected, actual) - def test_section_header_underline_length(self): docstrings = [(""" Summary line |