From e69724245135f152699d3f4a8b3c20992d9448ed Mon Sep 17 00:00:00 2001 From: Keewis Date: Tue, 4 Aug 2020 20:48:59 +0200 Subject: fix the tests by falling back to a empty dict on AttributeError --- tests/test_ext_napoleon_docstring.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/test_ext_napoleon_docstring.py') diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index 56812d193..0894a9bff 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -1365,6 +1365,7 @@ otherfunc : relationship config = Config() app = mock.Mock() + app.builder.env = None actual = str(NumpyDocstring(docstring, config, app, "method")) expected = """\ @@ -1379,6 +1380,27 @@ numpy.multivariate_normal(mean, cov, shape=None, spam=None) """ 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 -- cgit v1.2.1 From 4428393403ad98e49459e36085c7f0a85a627bab Mon Sep 17 00:00:00 2001 From: Keewis Date: Thu, 6 Aug 2020 14:08:34 +0200 Subject: translate the functions before attempting to find a matching role --- tests/test_ext_napoleon_docstring.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/test_ext_napoleon_docstring.py') diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index 0894a9bff..57bdf1342 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -1400,6 +1400,38 @@ numpy.multivariate_normal(mean, cov, shape=None, spam=None) """ self.assertEqual(expected, actual) + docstring = """\ +numpy.multivariate_normal(mean, cov, shape=None, spam=None) + +See Also +-------- +some, other, :func:`funcs` +otherfunc : relationship + +""" + translations = { + "other": "MyClass.other", + "otherfunc": ":func:`~my_package.otherfunc`", + } + config = Config(napoleon_type_aliases=translations) + app = mock.Mock() + app.builder.env.intersphinx_inventory = { + "py:func": {"funcs": (), "otherfunc": ()}, + "py:meth": {"some": (), "MyClass.other": ()}, + } + actual = str(NumpyDocstring(docstring, config, app, "method")) + + expected = """\ +numpy.multivariate_normal(mean, cov, shape=None, spam=None) + +.. seealso:: + + :meth:`some`, :meth:`MyClass.other`, :func:`funcs` + \n\ + :func:`~my_package.otherfunc` + relationship +""" + self.assertEqual(expected, actual) def test_colon_in_return_type(self): docstring = """ -- cgit v1.2.1 From 95c861facb752daeacca09a118f48f323ffcea32 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 7 Aug 2020 12:43:56 +0200 Subject: always use :obj: instead of searching the inventory --- tests/test_ext_napoleon_docstring.py | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) (limited to 'tests/test_ext_napoleon_docstring.py') diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index 57bdf1342..18a7cc88b 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -1365,7 +1365,6 @@ otherfunc : relationship config = Config() app = mock.Mock() - app.builder.env = None actual = str(NumpyDocstring(docstring, config, app, "method")) expected = """\ @@ -1373,29 +1372,9 @@ numpy.multivariate_normal(mean, cov, shape=None, spam=None) .. seealso:: - :meth:`some`, :meth:`other`, :meth:`funcs` - \n\ - :meth:`otherfunc` - relationship -""" - 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` + :obj:`some`, :obj:`other`, :obj:`funcs` \n\ - :func:`otherfunc` + :obj:`otherfunc` relationship """ self.assertEqual(expected, actual) @@ -1415,10 +1394,6 @@ otherfunc : relationship } config = Config(napoleon_type_aliases=translations) app = mock.Mock() - app.builder.env.intersphinx_inventory = { - "py:func": {"funcs": (), "otherfunc": ()}, - "py:meth": {"some": (), "MyClass.other": ()}, - } actual = str(NumpyDocstring(docstring, config, app, "method")) expected = """\ @@ -1426,7 +1401,7 @@ numpy.multivariate_normal(mean, cov, shape=None, spam=None) .. seealso:: - :meth:`some`, :meth:`MyClass.other`, :func:`funcs` + :obj:`some`, :obj:`MyClass.other`, :func:`funcs` \n\ :func:`~my_package.otherfunc` relationship -- cgit v1.2.1