Add a test for `restify(Annotated[...])`

This commit is contained in:
Adam Turner 2024-04-24 23:16:22 +01:00
parent 173b5912e5
commit 6b70620993

View File

@ -30,9 +30,12 @@ from types import (
WrapperDescriptorType,
)
from typing import (
Annotated,
Any,
Dict,
ForwardRef,
List,
Literal,
NewType,
Optional,
Tuple,
@ -184,6 +187,11 @@ def test_restify_type_hints_containers():
"[:py:obj:`None`]")
def test_restify_Annotated():
assert restify(Annotated[str, "foo", "bar"]) == ':py:class:`~typing.Annotated`\\ [:py:class:`str`]'
assert restify(Annotated[str, "foo", "bar"], 'smart') == ':py:class:`~typing.Annotated`\\ [:py:class:`str`]'
def test_restify_type_hints_Callable():
assert restify(t.Callable) == ":py:class:`~typing.Callable`"
assert restify(t.Callable[[str], int]) == (":py:class:`~typing.Callable`\\ "
@ -284,7 +292,6 @@ def test_restify_type_hints_alias():
def test_restify_type_ForwardRef():
from typing import ForwardRef # type: ignore[attr-defined]
assert restify(ForwardRef("MyInt")) == ":py:class:`MyInt`"
assert restify(list[ForwardRef("MyInt")]) == ":py:class:`list`\\ [:py:class:`MyInt`]"
@ -293,7 +300,6 @@ def test_restify_type_ForwardRef():
def test_restify_type_Literal():
from typing import Literal # type: ignore[attr-defined]
assert restify(Literal[1, "2", "\r"]) == ":py:obj:`~typing.Literal`\\ [1, '2', '\\r']"
assert restify(Literal[MyEnum.a], 'fully-qualified-except-typing') == ':py:obj:`~typing.Literal`\\ [:py:attr:`tests.test_util.test_util_typing.MyEnum.a`]'
@ -469,7 +475,6 @@ def test_stringify_type_hints_pep_585():
def test_stringify_Annotated():
from typing import Annotated # type: ignore[attr-defined]
assert stringify_annotation(Annotated[str, "foo", "bar"], 'fully-qualified-except-typing') == "str"
assert stringify_annotation(Annotated[str, "foo", "bar"], "smart") == "str"