Skip to content

Commit eb0af18

Browse files
committed
Use process_docstring in testing
1 parent 22dba11 commit eb0af18

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

tests/test_elegant_typehints.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import inspect
12
import typing as t
23

34
import pytest
45
from sphinx.application import Sphinx
6+
from sphinx_autodoc_typehints import process_docstring
57

68
from scanpydoc.elegant_typehints import format_annotation, _format_terse, _format_full
79

@@ -13,19 +15,34 @@ def app(make_app_no_setup) -> Sphinx:
1315
return app
1416

1517

18+
@pytest.fixture
19+
def process_doc(app):
20+
app.config.typehints_fully_qualified = True
21+
22+
def process(fn: t.Callable) -> t.List[str]:
23+
lines = inspect.getdoc(fn).split("\n")
24+
process_docstring(app, "function", fn.__name__, fn, None, lines)
25+
return lines
26+
27+
return process
28+
29+
1630
def test_default(app):
1731
assert format_annotation(str) == ":py:class:`str`"
1832

1933

20-
def test_alternatives(app):
21-
def process_docstring(a):
22-
"""Caller needs to be `process_docstring` to create both formats"""
23-
return format_annotation(a)
34+
def test_alternatives(process_doc):
35+
def fn_test(s: str):
36+
"""
37+
:param s: Test
38+
"""
2439

25-
assert process_docstring(str) == (
40+
assert process_doc(fn_test) == [
41+
":type s: "
2642
r":annotation-terse:`:py:class:\`str\``\ "
27-
r":annotation-full:`:py:class:\`str\``"
28-
)
43+
r":annotation-full:`:py:class:\`str\``",
44+
":param s: Test",
45+
]
2946

3047

3148
def test_mapping(app):

0 commit comments

Comments
 (0)