diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-02-16 21:42:20 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-02-16 21:42:20 +0900 |
commit | 954db2bd27f2e917ac0622f6b12badf045dd0ef8 (patch) | |
tree | d68b2176ea65530b5093046e6206dfeaae3ac369 /tests | |
parent | 81964e036b08e182fa9d58c6330a4094083f9070 (diff) | |
parent | e9c165fa5548f2af0370644b649c4452e2563044 (diff) | |
download | sphinx-git-954db2bd27f2e917ac0622f6b12badf045dd0ef8.tar.gz |
Merge branch '2.0'
Diffstat (limited to 'tests')
-rw-r--r-- | tests/roots/test-ext-autodoc/target/pep570.py | 10 | ||||
-rw-r--r-- | tests/roots/test-ext-autodoc/target/typehints.py | 20 | ||||
-rw-r--r-- | tests/test_ext_autodoc_configs.py | 24 | ||||
-rw-r--r-- | tests/test_util_inspect.py | 13 |
4 files changed, 62 insertions, 5 deletions
diff --git a/tests/roots/test-ext-autodoc/target/pep570.py b/tests/roots/test-ext-autodoc/target/pep570.py index 904692eeb..1a77eae93 100644 --- a/tests/roots/test-ext-autodoc/target/pep570.py +++ b/tests/roots/test-ext-autodoc/target/pep570.py @@ -1,5 +1,11 @@ -def foo(a, b, /, c, d): +def foo(*, a, b): pass -def bar(a, b, /): +def bar(a, b, /, c, d): + pass + +def baz(a, /, *, b): + pass + +def qux(a, b, /): pass diff --git a/tests/roots/test-ext-autodoc/target/typehints.py b/tests/roots/test-ext-autodoc/target/typehints.py index 842530c13..ab5bfb624 100644 --- a/tests/roots/test-ext-autodoc/target/typehints.py +++ b/tests/roots/test-ext-autodoc/target/typehints.py @@ -18,7 +18,27 @@ class Math: # type: (int, int) -> int return a - b + def nothing(self): + # type: () -> None + pass + + def horse(self, + a, # type: str + b, # type: int + ): + # type: (...) -> None + return + def complex_func(arg1, arg2, arg3=None, *args, **kwargs): # type: (str, List[int], Tuple[int, Union[str, Unknown]], *str, **str) -> None pass + + +def missing_attr(c, + a, # type: str + b=None # type: Optional[str] + ): + # type: (...) -> str + return a + (b or "") + diff --git a/tests/test_ext_autodoc_configs.py b/tests/test_ext_autodoc_configs.py index a9af8a272..b90772f6e 100644 --- a/tests/test_ext_autodoc_configs.py +++ b/tests/test_ext_autodoc_configs.py @@ -482,9 +482,17 @@ def test_autodoc_typehints_signature(app): ' :module: target.typehints', ' ', ' ', + ' .. py:method:: Math.horse(a: str, b: int) -> None', + ' :module: target.typehints', + ' ', + ' ', ' .. py:method:: Math.incr(a: int, b: int = 1) -> int', ' :module: target.typehints', ' ', + ' ', + ' .. py:method:: Math.nothing() -> None', + ' :module: target.typehints', + ' ', '', '.. py:function:: complex_func(arg1: str, arg2: List[int], arg3: Tuple[int, ' 'Union[str, Unknown]] = None, *args: str, **kwargs: str) -> None', @@ -497,6 +505,10 @@ def test_autodoc_typehints_signature(app): '', '.. py:function:: incr(a: int, b: int = 1) -> int', ' :module: target.typehints', + '', + '', + '.. py:function:: missing_attr(c, a: str, b: Optional[str] = None) -> str', + ' :module: target.typehints', '' ] @@ -521,9 +533,17 @@ def test_autodoc_typehints_none(app): ' :module: target.typehints', ' ', ' ', + ' .. py:method:: Math.horse(a, b)', + ' :module: target.typehints', + ' ', + ' ', ' .. py:method:: Math.incr(a, b=1)', ' :module: target.typehints', ' ', + ' ', + ' .. py:method:: Math.nothing()', + ' :module: target.typehints', + ' ', '', '.. py:function:: complex_func(arg1, arg2, arg3=None, *args, **kwargs)', ' :module: target.typehints', @@ -535,6 +555,10 @@ def test_autodoc_typehints_none(app): '', '.. py:function:: incr(a, b=1)', ' :module: target.typehints', + '', + '', + '.. py:function:: missing_attr(c, a, b=None)', + ' :module: target.typehints', '' ] diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py index 34844c9bf..c6b2c9149 100644 --- a/tests/test_util_inspect.py +++ b/tests/test_util_inspect.py @@ -298,14 +298,21 @@ def test_signature_annotations(): @pytest.mark.skipif(sys.version_info < (3, 8), reason='python 3.8+ is required.') @pytest.mark.sphinx(testroot='ext-autodoc') def test_signature_annotations_py38(app): - from target.pep570 import foo, bar + from target.pep570 import foo, bar, baz, qux - # case: separator in the middle + # case: separator at head sig = inspect.signature(foo) + assert stringify_signature(sig) == '(*, a, b)' + + # case: separator in the middle + sig = inspect.signature(bar) assert stringify_signature(sig) == '(a, b, /, c, d)' + sig = inspect.signature(baz) + assert stringify_signature(sig) == '(a, /, *, b)' + # case: separator at tail - sig = inspect.signature(bar) + sig = inspect.signature(qux) assert stringify_signature(sig) == '(a, b, /)' |