summaryrefslogtreecommitdiff
path: root/tests/test_ext_napoleon_docstring.py
diff options
context:
space:
mode:
authorRob Ruana <rob@robruana.com>2015-06-11 01:15:52 -0700
committerRob Ruana <rob@robruana.com>2015-06-11 01:16:25 -0700
commitd82d110dfd28f53f7cf3acea6bf751fe692f6ddd (patch)
tree9f1029e265ec85a6352d557e0195b8051cf8b7b2 /tests/test_ext_napoleon_docstring.py
parentcf42c46beb999d3ea3e6f8044dd64401bedadbf2 (diff)
downloadsphinx-git-d82d110dfd28f53f7cf3acea6bf751fe692f6ddd.tar.gz
Closes #1927: [Napoleon] fixes parsing & formatting of types in Raises section
Diffstat (limited to 'tests/test_ext_napoleon_docstring.py')
-rw-r--r--tests/test_ext_napoleon_docstring.py363
1 files changed, 362 insertions, 1 deletions
diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py
index 5cb5f1627..0543d0846 100644
--- a/tests/test_ext_napoleon_docstring.py
+++ b/tests/test_ext_napoleon_docstring.py
@@ -376,6 +376,175 @@ Returns:
actual = str(GoogleDocstring(docstring))
self.assertEqual(expected, actual)
+ def test_raises_types(self):
+ docstrings = [("""
+Example Function
+
+Raises:
+ RuntimeError:
+ A setting wasn't specified, or was invalid.
+ ValueError:
+ Something something value error.
+
+""", """
+Example Function
+
+:raises: * :exc:`RuntimeError`
+
+ A setting wasn't specified, or was invalid.
+ * :exc:`ValueError`
+
+ Something something value error.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ InvalidDimensionsError
+
+""", """
+Example Function
+
+:raises: :exc:`InvalidDimensionsError`
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ Invalid Dimensions Error
+
+""", """
+Example Function
+
+:raises: Invalid Dimensions Error
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ Invalid Dimensions Error: With description
+
+""", """
+Example Function
+
+:raises: *Invalid Dimensions Error* --
+ With description
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ InvalidDimensionsError: If the dimensions couldn't be parsed.
+
+""", """
+Example Function
+
+:raises: :exc:`InvalidDimensionsError` --
+ If the dimensions couldn't be parsed.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ Invalid Dimensions Error: If the dimensions couldn't be parsed.
+
+""", """
+Example Function
+
+:raises: *Invalid Dimensions Error* --
+ If the dimensions couldn't be parsed.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ If the dimensions couldn't be parsed.
+
+""", """
+Example Function
+
+:raises: If the dimensions couldn't be parsed.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ :class:`exc.InvalidDimensionsError`
+
+""", """
+Example Function
+
+:raises: :class:`exc.InvalidDimensionsError`
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ :class:`exc.InvalidDimensionsError`: If the dimensions couldn't be parsed.
+
+""", """
+Example Function
+
+:raises: :class:`exc.InvalidDimensionsError` --
+ If the dimensions couldn't be parsed.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ :class:`exc.InvalidDimensionsError`: If the dimensions couldn't be parsed,
+ then a :class:`exc.InvalidDimensionsError` will be raised.
+
+""", """
+Example Function
+
+:raises: :class:`exc.InvalidDimensionsError` --
+ If the dimensions couldn't be parsed,
+ then a :class:`exc.InvalidDimensionsError` will be raised.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ :class:`exc.InvalidDimensionsError`: If the dimensions couldn't be parsed.
+ :class:`exc.InvalidArgumentsError`: If the arguments are invalid.
+
+""", """
+Example Function
+
+:raises: * :class:`exc.InvalidDimensionsError` --
+ If the dimensions couldn't be parsed.
+ * :class:`exc.InvalidArgumentsError` --
+ If the arguments are invalid.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises:
+ :class:`exc.InvalidDimensionsError`
+ :class:`exc.InvalidArgumentsError`
+
+""", """
+Example Function
+
+:raises: * :class:`exc.InvalidDimensionsError`
+ * :class:`exc.InvalidArgumentsError`
+""")]
+ for docstring, expected in docstrings:
+ actual = str(GoogleDocstring(docstring))
+ self.assertEqual(expected, actual)
+
def test_kwargs_in_arguments(self):
docstring = """Allows to create attributes binded to this device.
@@ -564,7 +733,7 @@ class NumpyDocstringTest(BaseDocstringTest):
:Yields: *str* --
Extended
description of yielded value"""
- )]
+ )]
def test_docstrings(self):
config = Config(napoleon_use_param=False, napoleon_use_rtype=False)
@@ -713,6 +882,198 @@ arg_ : type
self.assertEqual(expected, actual)
+ def test_raises_types(self):
+ docstrings = [("""
+Example Function
+
+Raises
+------
+ RuntimeError
+
+ A setting wasn't specified, or was invalid.
+ ValueError
+
+ Something something value error.
+
+""", """
+Example Function
+
+:raises: * :exc:`RuntimeError`
+
+ A setting wasn't specified, or was invalid.
+ * :exc:`ValueError`
+
+ Something something value error.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+InvalidDimensionsError
+
+""", """
+Example Function
+
+:raises: :exc:`InvalidDimensionsError`
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+Invalid Dimensions Error
+
+""", """
+Example Function
+
+:raises: Invalid Dimensions Error
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+Invalid Dimensions Error
+ With description
+
+""", """
+Example Function
+
+:raises: *Invalid Dimensions Error* --
+ With description
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+InvalidDimensionsError
+ If the dimensions couldn't be parsed.
+
+""", """
+Example Function
+
+:raises: :exc:`InvalidDimensionsError` --
+ If the dimensions couldn't be parsed.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+Invalid Dimensions Error
+ If the dimensions couldn't be parsed.
+
+""", """
+Example Function
+
+:raises: *Invalid Dimensions Error* --
+ If the dimensions couldn't be parsed.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+If the dimensions couldn't be parsed.
+
+""", """
+Example Function
+
+:raises: If the dimensions couldn't be parsed.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+:class:`exc.InvalidDimensionsError`
+
+""", """
+Example Function
+
+:raises: :class:`exc.InvalidDimensionsError`
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+:class:`exc.InvalidDimensionsError`
+ If the dimensions couldn't be parsed.
+
+""", """
+Example Function
+
+:raises: :class:`exc.InvalidDimensionsError` --
+ If the dimensions couldn't be parsed.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+:class:`exc.InvalidDimensionsError`
+ If the dimensions couldn't be parsed,
+ then a :class:`exc.InvalidDimensionsError` will be raised.
+
+""", """
+Example Function
+
+:raises: :class:`exc.InvalidDimensionsError` --
+ If the dimensions couldn't be parsed,
+ then a :class:`exc.InvalidDimensionsError` will be raised.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+:class:`exc.InvalidDimensionsError`
+ If the dimensions couldn't be parsed.
+:class:`exc.InvalidArgumentsError`
+ If the arguments are invalid.
+
+""", """
+Example Function
+
+:raises: * :class:`exc.InvalidDimensionsError` --
+ If the dimensions couldn't be parsed.
+ * :class:`exc.InvalidArgumentsError` --
+ If the arguments are invalid.
+"""),
+ ################################
+ ("""
+Example Function
+
+Raises
+------
+:class:`exc.InvalidDimensionsError`
+:class:`exc.InvalidArgumentsError`
+
+""", """
+Example Function
+
+:raises: * :class:`exc.InvalidDimensionsError`
+ * :class:`exc.InvalidArgumentsError`
+""")]
+ for docstring, expected in docstrings:
+ config = Config()
+ app = mock.Mock()
+ actual = str(NumpyDocstring(docstring, config, app, "method"))
+ self.assertEqual(expected, actual)
+
def test_xrefs_in_return_type(self):
docstring = """
Example Function