From 9a44e4527704f17cca158b260b68a8dd37f95970 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 1 Nov 2020 18:23:24 +0900 Subject: Fix #7613: autodoc: autodoc does not respect __signature__ of the class --- tests/roots/test-ext-autodoc/target/classes.py | 11 ++++++ tests/test_ext_autodoc_autoclass.py | 50 ++++++++++++++++++++++++++ tests/test_ext_autodoc_autofunction.py | 8 +++++ 3 files changed, 69 insertions(+) create mode 100644 tests/test_ext_autodoc_autoclass.py (limited to 'tests') diff --git a/tests/roots/test-ext-autodoc/target/classes.py b/tests/roots/test-ext-autodoc/target/classes.py index dc471a6f3..52c23748b 100644 --- a/tests/roots/test-ext-autodoc/target/classes.py +++ b/tests/roots/test-ext-autodoc/target/classes.py @@ -1,3 +1,6 @@ +from inspect import Parameter, Signature + + class Foo: pass @@ -10,3 +13,11 @@ class Bar: class Baz: def __new__(cls, x, y): pass + + +class Qux: + __signature__ = Signature(parameters=[Parameter('foo', Parameter.POSITIONAL_OR_KEYWORD), + Parameter('bar', Parameter.POSITIONAL_OR_KEYWORD)]) + + def __init__(self, x, y): + pass diff --git a/tests/test_ext_autodoc_autoclass.py b/tests/test_ext_autodoc_autoclass.py new file mode 100644 index 000000000..89a79c2c7 --- /dev/null +++ b/tests/test_ext_autodoc_autoclass.py @@ -0,0 +1,50 @@ +""" + test_ext_autodoc_autoclass + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Test the autodoc extension. This tests mainly the Documenters; the auto + directives are tested in a test source file translated by test_build. + + :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import pytest + +from test_ext_autodoc import do_autodoc + + +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_classes(app): + actual = do_autodoc(app, 'function', 'target.classes.Foo') + assert list(actual) == [ + '', + '.. py:function:: Foo()', + ' :module: target.classes', + '', + ] + + actual = do_autodoc(app, 'function', 'target.classes.Bar') + assert list(actual) == [ + '', + '.. py:function:: Bar(x, y)', + ' :module: target.classes', + '', + ] + + actual = do_autodoc(app, 'function', 'target.classes.Baz') + assert list(actual) == [ + '', + '.. py:function:: Baz(x, y)', + ' :module: target.classes', + '', + ] + + actual = do_autodoc(app, 'function', 'target.classes.Qux') + assert list(actual) == [ + '', + '.. py:function:: Qux(foo, bar)', + ' :module: target.classes', + '', + ] + diff --git a/tests/test_ext_autodoc_autofunction.py b/tests/test_ext_autodoc_autofunction.py index bb292bc6a..64f6e8db3 100644 --- a/tests/test_ext_autodoc_autofunction.py +++ b/tests/test_ext_autodoc_autofunction.py @@ -40,6 +40,14 @@ def test_classes(app): '', ] + actual = do_autodoc(app, 'function', 'target.classes.Qux') + assert list(actual) == [ + '', + '.. py:function:: Qux(foo, bar)', + ' :module: target.classes', + '', + ] + @pytest.mark.sphinx('html', testroot='ext-autodoc') def test_callable(app): -- cgit v1.2.1 From 0e98e9b1a8ade24acf1d91f59aa90e8b1e179b19 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 8 Aug 2020 20:06:46 +0900 Subject: Fix #6914: Emit a detailed warning when failed to resolve :ref: To be clear the ambiguous warning for missing-reference :ref:, this separates the warning to missing-label and missing-caption. To emit a warning dynamically, this also adds a new event: `warn-missing-reference` to customize warning messages via event handlers. --- tests/roots/test-domain-py-xref-warning/conf.py | 0 tests/roots/test-domain-py-xref-warning/index.rst | 7 +++++++ tests/test_domain_py.py | 8 ++++++++ 3 files changed, 15 insertions(+) create mode 100644 tests/roots/test-domain-py-xref-warning/conf.py create mode 100644 tests/roots/test-domain-py-xref-warning/index.rst (limited to 'tests') diff --git a/tests/roots/test-domain-py-xref-warning/conf.py b/tests/roots/test-domain-py-xref-warning/conf.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/roots/test-domain-py-xref-warning/index.rst b/tests/roots/test-domain-py-xref-warning/index.rst new file mode 100644 index 000000000..6f2cab795 --- /dev/null +++ b/tests/roots/test-domain-py-xref-warning/index.rst @@ -0,0 +1,7 @@ +test-domain-py-xref-warning +=========================== + +.. _existing-label: + +:ref:`no-label` +:ref:`existing-label` diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index ceea51508..d81b406c2 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -859,3 +859,11 @@ def test_noindexentry(app): assert_node(doctree, (addnodes.index, desc, addnodes.index, desc)) assert_node(doctree[0], addnodes.index, entries=[('single', 'f (built-in class)', 'f', '', None)]) assert_node(doctree[2], addnodes.index, entries=[]) + + +@pytest.mark.sphinx('dummy', testroot='domain-py-xref-warning') +def test_warn_missing_reference(app, status, warning): + app.build() + assert 'index.rst:6: WARNING: undefined label: no-label' in warning.getvalue() + assert ('index.rst:6: WARNING: Failed to create a cross reference. A title or caption not found: existing-label' + in warning.getvalue()) -- cgit v1.2.1 From 218de39462798c8e102ff375b8ee9fb336537041 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 4 Nov 2020 23:19:25 +0900 Subject: Fix testcases for singledispatch are sometimes failed They are sometimes failed with python3.5 because the order of singledispatch functions is not stable on python 3.5. This uses comparision via "in" keyword to check the signature of singledispatch functions stably. --- tests/test_ext_autodoc.py | 33 ++++++++++++++++++++------------- tests/test_ext_autodoc_autofunction.py | 29 +++++++++++++++++++---------- 2 files changed, 39 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py index c0676f23f..703cc13f6 100644 --- a/tests/test_ext_autodoc.py +++ b/tests/test_ext_autodoc.py @@ -1832,19 +1832,26 @@ def test_autodoc_for_egged_code(app): def test_singledispatch(app): options = {"members": None} actual = do_autodoc(app, 'module', 'target.singledispatch', options) - assert list(actual) == [ - '', - '.. py:module:: target.singledispatch', - '', - '', - '.. py:function:: func(arg, kwarg=None)', - ' func(arg: int, kwarg=None)', - ' func(arg: str, kwarg=None)', - ' :module: target.singledispatch', - '', - ' A function for general use.', - '', - ] + if sys.version_info < (3, 6): + # check the result via "in" because the order of singledispatch signatures is + # usually changed (because dict is not OrderedDict yet!) + assert '.. py:function:: func(arg, kwarg=None)' in actual + assert ' func(arg: int, kwarg=None)' in actual + assert ' func(arg: str, kwarg=None)' in actual + else: + assert list(actual) == [ + '', + '.. py:module:: target.singledispatch', + '', + '', + '.. py:function:: func(arg, kwarg=None)', + ' func(arg: int, kwarg=None)', + ' func(arg: str, kwarg=None)', + ' :module: target.singledispatch', + '', + ' A function for general use.', + '', + ] @pytest.mark.skipif(sys.version_info < (3, 8), diff --git a/tests/test_ext_autodoc_autofunction.py b/tests/test_ext_autodoc_autofunction.py index bb292bc6a..1f68c0319 100644 --- a/tests/test_ext_autodoc_autofunction.py +++ b/tests/test_ext_autodoc_autofunction.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +import sys + import pytest from test_ext_autodoc import do_autodoc @@ -108,16 +110,23 @@ def test_decorated(app): def test_singledispatch(app): options = {} actual = do_autodoc(app, 'function', 'target.singledispatch.func', options) - assert list(actual) == [ - '', - '.. py:function:: func(arg, kwarg=None)', - ' func(arg: int, kwarg=None)', - ' func(arg: str, kwarg=None)', - ' :module: target.singledispatch', - '', - ' A function for general use.', - '', - ] + if sys.version_info < (3, 6): + # check the result via "in" because the order of singledispatch signatures is + # usually changed (because dict is not OrderedDict yet!) + assert '.. py:function:: func(arg, kwarg=None)' in actual + assert ' func(arg: int, kwarg=None)' in actual + assert ' func(arg: str, kwarg=None)' in actual + else: + assert list(actual) == [ + '', + '.. py:function:: func(arg, kwarg=None)', + ' func(arg: int, kwarg=None)', + ' func(arg: str, kwarg=None)', + ' :module: target.singledispatch', + '', + ' A function for general use.', + '', + ] @pytest.mark.sphinx('html', testroot='ext-autodoc') -- cgit v1.2.1