Skip to content

Commit

Permalink
fix the tests by falling back to a empty dict on AttributeError
Browse files Browse the repository at this point in the history
  • Loading branch information
keewis committed Aug 4, 2020
1 parent d9fb3bc commit 37c66a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sphinx/ext/napoleon/docstring.py
Expand Up @@ -1131,7 +1131,11 @@ def _parse_numpydoc_see_also_section(self, content: List[str]) -> List[str]:
func_name1, func_name2, :meth:`func_name`, func_name3
"""
inventory = getattr(self._app.builder.env, "intersphinx_inventory", {})
try:
inventory = self._app.builder.env.intersphinx_inventory
except AttributeError:
inventory = {}

items = []

def parse_item_name(text: str) -> Tuple[str, str]:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_ext_napoleon_docstring.py
Expand Up @@ -1365,6 +1365,7 @@ def test_see_also_refs(self):

config = Config()
app = mock.Mock()
app.builder.env.intersphinx_inventory = {}
actual = str(NumpyDocstring(docstring, config, app, "method"))

expected = """\
Expand All @@ -1379,6 +1380,27 @@ def test_see_also_refs(self):
"""
self.assertEqual(expected, actual)

config = Config()
app = mock.Mock()
app.builder.env.intersphinx_inventory = {
"py:func": {"funcs": (), "otherfunc": ()},
"py:meth": {"some": (), "other": ()},
}
actual = str(NumpyDocstring(docstring, config, app, "method"))

expected = """\
numpy.multivariate_normal(mean, cov, shape=None, spam=None)
.. seealso::
:meth:`some`, :meth:`other`, :func:`funcs`
\n\
:func:`otherfunc`
relationship
"""
self.assertEqual(expected, actual)


def test_colon_in_return_type(self):
docstring = """
Summary
Expand Down

0 comments on commit 37c66a0

Please sign in to comment.