diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/roots/test-ext-autodoc/target/typed_vars.py | 9 | ||||
-rw-r--r-- | tests/roots/test-templating/_templates/autosummary/class.rst | 1 | ||||
-rw-r--r-- | tests/test_autodoc.py | 39 | ||||
-rw-r--r-- | tests/test_domain_c.py | 15 | ||||
-rw-r--r-- | tests/test_ext_autosummary.py | 3 | ||||
-rw-r--r-- | tests/test_templating.py | 14 | ||||
-rw-r--r-- | tests/test_util_typing.py | 8 |
7 files changed, 87 insertions, 2 deletions
diff --git a/tests/roots/test-ext-autodoc/target/typed_vars.py b/tests/roots/test-ext-autodoc/target/typed_vars.py index b0782787e..65302fa44 100644 --- a/tests/roots/test-ext-autodoc/target/typed_vars.py +++ b/tests/roots/test-ext-autodoc/target/typed_vars.py @@ -6,11 +6,20 @@ attr2: str attr3 = '' # type: str +class _Descriptor: + def __init__(self, name): + self.__doc__ = "This is {}".format(name) + def __get__(self): + pass + + class Class: attr1: int = 0 attr2: int attr3 = 0 # type: int + descr4: int = _Descriptor("descr4") + def __init__(self): self.attr4: int = 0 #: attr4 self.attr5: int #: attr5 diff --git a/tests/roots/test-templating/_templates/autosummary/class.rst b/tests/roots/test-templating/_templates/autosummary/class.rst index 7f1536173..6f505649c 100644 --- a/tests/roots/test-templating/_templates/autosummary/class.rst +++ b/tests/roots/test-templating/_templates/autosummary/class.rst @@ -3,6 +3,7 @@ {% block methods %} .. note:: autosummary/class.rst method block overloading + {{ sentence }} {{ super() }} {% endblock %} diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 3907e3465..51ae3ddc3 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -1511,6 +1511,13 @@ def test_autodoc_typed_instance_variables(app): ' attr6', '', '', + ' .. py:attribute:: Class.descr4', + ' :module: target.typed_vars', + ' :type: int', + '', + ' This is descr4', + '', + '', '.. py:data:: attr1', ' :module: target.typed_vars', ' :type: str', @@ -1596,6 +1603,21 @@ def test_singledispatch(): ] +@pytest.mark.usefixtures('setup_test') +def test_singledispatch_autofunction(): + 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.', + '', + ] + @pytest.mark.skipif(sys.version_info < (3, 8), reason='singledispatchmethod is available since python3.8') @pytest.mark.usefixtures('setup_test') @@ -1623,6 +1645,23 @@ def test_singledispatchmethod(): ] +@pytest.mark.skipif(sys.version_info < (3, 8), + reason='singledispatchmethod is available since python3.8') +@pytest.mark.usefixtures('setup_test') +def test_singledispatchmethod_automethod(): + options = {} + actual = do_autodoc(app, 'method', 'target.singledispatchmethod.Foo.meth', options) + assert list(actual) == [ + '', + '.. py:method:: Foo.meth(arg, kwarg=None)', + ' Foo.meth(arg: int, kwarg=None)', + ' Foo.meth(arg: str, kwarg=None)', + ' :module: target.singledispatchmethod', + '', + ' A method for general use.', + '', + ] + @pytest.mark.usefixtures('setup_test') @pytest.mark.skipif(pyximport is None, reason='cython is not installed') def test_cython(): diff --git a/tests/test_domain_c.py b/tests/test_domain_c.py index f85a0e62e..237519fcc 100644 --- a/tests/test_domain_c.py +++ b/tests/test_domain_c.py @@ -362,6 +362,21 @@ def test_function_definitions(): check('function', 'void f(enum E e)', {1: 'f'}) check('function', 'void f(union E e)', {1: 'f'}) + # array declarators + check('function', 'void f(int arr[])', {1: 'f'}) + check('function', 'void f(int arr[*])', {1: 'f'}) + cvrs = ['', 'const', 'volatile', 'restrict', 'restrict volatile const'] + for cvr in cvrs: + space = ' ' if len(cvr) != 0 else '' + check('function', 'void f(int arr[{}*])'.format(cvr), {1: 'f'}) + check('function', 'void f(int arr[{}])'.format(cvr), {1: 'f'}) + check('function', 'void f(int arr[{}{}42])'.format(cvr, space), {1: 'f'}) + check('function', 'void f(int arr[static{}{} 42])'.format(space, cvr), {1: 'f'}) + check('function', 'void f(int arr[{}{}static 42])'.format(cvr, space), {1: 'f'}, + output='void f(int arr[static{}{} 42])'.format(space, cvr)) + check('function', 'void f(int arr[const static volatile 42])', {1: 'f'}, + output='void f(int arr[static volatile const 42])') + def test_union_definitions(): check('struct', 'A', {1: 'A'}) diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py index 7e7a20663..114694166 100644 --- a/tests/test_ext_autosummary.py +++ b/tests/test_ext_autosummary.py @@ -353,7 +353,8 @@ def test_autosummary_imported_members(app, status, warning): sys.modules.pop('autosummary_dummy_package', None) -@pytest.mark.sphinx(testroot='ext-autodoc') +@pytest.mark.sphinx(testroot='ext-autodoc', + confoverrides={'extensions': ['sphinx.ext.autosummary']}) def test_generate_autosummary_docs_property(app): with patch('sphinx.ext.autosummary.generate.find_autosummary_in_files') as mock: mock.return_value = [AutosummaryEntry('target.methods.Base.prop', 'prop', None, False)] diff --git a/tests/test_templating.py b/tests/test_templating.py index becacda0d..f2c1d563b 100644 --- a/tests/test_templating.py +++ b/tests/test_templating.py @@ -33,3 +33,17 @@ def test_autosummary_class_template_overloading(make_app, app_params): result = (app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html').read_text() assert 'autosummary/class.rst method block overloading' in result + assert 'foobar' not in result + + +@pytest.mark.sphinx('html', testroot='templating', + confoverrides={'autosummary_context': {'sentence': 'foobar'}}) +def test_autosummary_context(make_app, app_params): + args, kwargs = app_params + app = make_app(*args, **kwargs) + setup_documenters(app) + app.builder.build_update() + + result = (app.outdir / 'generated' / 'sphinx.application.TemplateBridge.html').read_text() + assert 'autosummary/class.rst method block overloading' in result + assert 'foobar' in result diff --git a/tests/test_util_typing.py b/tests/test_util_typing.py index f6fd35fb0..41d2a19c2 100644 --- a/tests/test_util_typing.py +++ b/tests/test_util_typing.py @@ -10,7 +10,7 @@ import sys from numbers import Integral -from typing import Any, Dict, List, TypeVar, Union, Callable, Tuple, Optional +from typing import Any, Dict, List, TypeVar, Union, Callable, Tuple, Optional, Generic import pytest @@ -24,6 +24,11 @@ class MyClass1: class MyClass2(MyClass1): __qualname__ = '<MyClass2>' +T = TypeVar('T') + +class MyList(List[T]): + pass + def test_stringify(): assert stringify(int) == "int" @@ -42,6 +47,7 @@ def test_stringify_type_hints_containers(): assert stringify(Tuple[str, str, str]) == "Tuple[str, str, str]" assert stringify(Tuple[str, ...]) == "Tuple[str, ...]" assert stringify(List[Dict[str, Tuple]]) == "List[Dict[str, Tuple]]" + assert stringify(MyList[Tuple[int, int]]) == "test_util_typing.MyList[Tuple[int, int]]" @pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.') |