diff options
author | Adam Turner <9087854+AA-Turner@users.noreply.github.com> | 2023-01-02 17:49:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-02 17:49:18 +0000 |
commit | 77a02cf696f8375791a2f5aa5c38306ca080d443 (patch) | |
tree | d7fd73833c2c6435d82e5f67f9e21b112fc058cf /tests/test_util_typing.py | |
parent | dc3f22a370b1a04d99591eddecfec835555feaf0 (diff) | |
download | sphinx-git-77a02cf696f8375791a2f5aa5c38306ca080d443.tar.gz |
Use PEP 604 display for ``typing.Optional`` and ``typing.Union`` (#11072)
Diffstat (limited to 'tests/test_util_typing.py')
-rw-r--r-- | tests/test_util_typing.py | 289 |
1 files changed, 147 insertions, 142 deletions
diff --git a/tests/test_util_typing.py b/tests/test_util_typing.py index 0cca1913e..89afb0021 100644 --- a/tests/test_util_typing.py +++ b/tests/test_util_typing.py @@ -10,7 +10,7 @@ from typing import (Any, Callable, Dict, Generator, List, NewType, Optional, Tup import pytest from sphinx.ext.autodoc import mock -from sphinx.util.typing import restify, stringify +from sphinx.util.typing import restify, stringify_annotation class MyClass1: @@ -198,169 +198,174 @@ def test_restify_mock(): assert restify(unknown.secret.Class, "smart") == ':py:class:`~unknown.secret.Class`' -def test_stringify(): - assert stringify(int) == "int" - assert stringify(int, "smart") == "int" +def test_stringify_annotation(): + assert stringify_annotation(int, 'fully-qualified-except-typing') == "int" + assert stringify_annotation(int, "smart") == "int" - assert stringify(str) == "str" - assert stringify(str, "smart") == "str" + assert stringify_annotation(str, 'fully-qualified-except-typing') == "str" + assert stringify_annotation(str, "smart") == "str" - assert stringify(None) == "None" - assert stringify(None, "smart") == "None" + assert stringify_annotation(None, 'fully-qualified-except-typing') == "None" + assert stringify_annotation(None, "smart") == "None" - assert stringify(Integral) == "numbers.Integral" - assert stringify(Integral, "smart") == "~numbers.Integral" + assert stringify_annotation(Integral, 'fully-qualified-except-typing') == "numbers.Integral" + assert stringify_annotation(Integral, "smart") == "~numbers.Integral" - assert stringify(Struct) == "struct.Struct" - assert stringify(Struct, "smart") == "~struct.Struct" + assert stringify_annotation(Struct, 'fully-qualified-except-typing') == "struct.Struct" + assert stringify_annotation(Struct, "smart") == "~struct.Struct" - assert stringify(TracebackType) == "types.TracebackType" - assert stringify(TracebackType, "smart") == "~types.TracebackType" + assert stringify_annotation(TracebackType, 'fully-qualified-except-typing') == "types.TracebackType" + assert stringify_annotation(TracebackType, "smart") == "~types.TracebackType" - assert stringify(Any) == "Any" - assert stringify(Any, "fully-qualified") == "typing.Any" - assert stringify(Any, "smart") == "~typing.Any" + assert stringify_annotation(Any, 'fully-qualified-except-typing') == "Any" + assert stringify_annotation(Any, "fully-qualified") == "typing.Any" + assert stringify_annotation(Any, "smart") == "~typing.Any" def test_stringify_type_hints_containers(): - assert stringify(List) == "List" - assert stringify(List, "fully-qualified") == "typing.List" - assert stringify(List, "smart") == "~typing.List" + assert stringify_annotation(List, 'fully-qualified-except-typing') == "List" + assert stringify_annotation(List, "fully-qualified") == "typing.List" + assert stringify_annotation(List, "smart") == "~typing.List" - assert stringify(Dict) == "Dict" - assert stringify(Dict, "fully-qualified") == "typing.Dict" - assert stringify(Dict, "smart") == "~typing.Dict" + assert stringify_annotation(Dict, 'fully-qualified-except-typing') == "Dict" + assert stringify_annotation(Dict, "fully-qualified") == "typing.Dict" + assert stringify_annotation(Dict, "smart") == "~typing.Dict" - assert stringify(List[int]) == "List[int]" - assert stringify(List[int], "fully-qualified") == "typing.List[int]" - assert stringify(List[int], "smart") == "~typing.List[int]" + assert stringify_annotation(List[int], 'fully-qualified-except-typing') == "List[int]" + assert stringify_annotation(List[int], "fully-qualified") == "typing.List[int]" + assert stringify_annotation(List[int], "smart") == "~typing.List[int]" - assert stringify(List[str]) == "List[str]" - assert stringify(List[str], "fully-qualified") == "typing.List[str]" - assert stringify(List[str], "smart") == "~typing.List[str]" + assert stringify_annotation(List[str], 'fully-qualified-except-typing') == "List[str]" + assert stringify_annotation(List[str], "fully-qualified") == "typing.List[str]" + assert stringify_annotation(List[str], "smart") == "~typing.List[str]" - assert stringify(Dict[str, float]) == "Dict[str, float]" - assert stringify(Dict[str, float], "fully-qualified") == "typing.Dict[str, float]" - assert stringify(Dict[str, float], "smart") == "~typing.Dict[str, float]" + assert stringify_annotation(Dict[str, float], 'fully-qualified-except-typing') == "Dict[str, float]" + assert stringify_annotation(Dict[str, float], "fully-qualified") == "typing.Dict[str, float]" + assert stringify_annotation(Dict[str, float], "smart") == "~typing.Dict[str, float]" - assert stringify(Tuple[str, str, str]) == "Tuple[str, str, str]" - assert stringify(Tuple[str, str, str], "fully-qualified") == "typing.Tuple[str, str, str]" - assert stringify(Tuple[str, str, str], "smart") == "~typing.Tuple[str, str, str]" + assert stringify_annotation(Tuple[str, str, str], 'fully-qualified-except-typing') == "Tuple[str, str, str]" + assert stringify_annotation(Tuple[str, str, str], "fully-qualified") == "typing.Tuple[str, str, str]" + assert stringify_annotation(Tuple[str, str, str], "smart") == "~typing.Tuple[str, str, str]" - assert stringify(Tuple[str, ...]) == "Tuple[str, ...]" - assert stringify(Tuple[str, ...], "fully-qualified") == "typing.Tuple[str, ...]" - assert stringify(Tuple[str, ...], "smart") == "~typing.Tuple[str, ...]" + assert stringify_annotation(Tuple[str, ...], 'fully-qualified-except-typing') == "Tuple[str, ...]" + assert stringify_annotation(Tuple[str, ...], "fully-qualified") == "typing.Tuple[str, ...]" + assert stringify_annotation(Tuple[str, ...], "smart") == "~typing.Tuple[str, ...]" if sys.version_info[:2] <= (3, 10): - assert stringify(Tuple[()]) == "Tuple[()]" - assert stringify(Tuple[()], "fully-qualified") == "typing.Tuple[()]" - assert stringify(Tuple[()], "smart") == "~typing.Tuple[()]" + assert stringify_annotation(Tuple[()], 'fully-qualified-except-typing') == "Tuple[()]" + assert stringify_annotation(Tuple[()], "fully-qualified") == "typing.Tuple[()]" + assert stringify_annotation(Tuple[()], "smart") == "~typing.Tuple[()]" else: - assert stringify(Tuple[()]) == "Tuple" - assert stringify(Tuple[()], "fully-qualified") == "typing.Tuple" - assert stringify(Tuple[()], "smart") == "~typing.Tuple" + assert stringify_annotation(Tuple[()], 'fully-qualified-except-typing') == "Tuple" + assert stringify_annotation(Tuple[()], "fully-qualified") == "typing.Tuple" + assert stringify_annotation(Tuple[()], "smart") == "~typing.Tuple" - assert stringify(List[Dict[str, Tuple]]) == "List[Dict[str, Tuple]]" - assert stringify(List[Dict[str, Tuple]], "fully-qualified") == "typing.List[typing.Dict[str, typing.Tuple]]" - assert stringify(List[Dict[str, Tuple]], "smart") == "~typing.List[~typing.Dict[str, ~typing.Tuple]]" + assert stringify_annotation(List[Dict[str, Tuple]], 'fully-qualified-except-typing') == "List[Dict[str, Tuple]]" + assert stringify_annotation(List[Dict[str, Tuple]], "fully-qualified") == "typing.List[typing.Dict[str, typing.Tuple]]" + assert stringify_annotation(List[Dict[str, Tuple]], "smart") == "~typing.List[~typing.Dict[str, ~typing.Tuple]]" - assert stringify(MyList[Tuple[int, int]]) == "tests.test_util_typing.MyList[Tuple[int, int]]" - assert stringify(MyList[Tuple[int, int]], "fully-qualified") == "tests.test_util_typing.MyList[typing.Tuple[int, int]]" - assert stringify(MyList[Tuple[int, int]], "smart") == "~tests.test_util_typing.MyList[~typing.Tuple[int, int]]" + assert stringify_annotation(MyList[Tuple[int, int]], 'fully-qualified-except-typing') == "tests.test_util_typing.MyList[Tuple[int, int]]" + assert stringify_annotation(MyList[Tuple[int, int]], "fully-qualified") == "tests.test_util_typing.MyList[typing.Tuple[int, int]]" + assert stringify_annotation(MyList[Tuple[int, int]], "smart") == "~tests.test_util_typing.MyList[~typing.Tuple[int, int]]" - assert stringify(Generator[None, None, None]) == "Generator[None, None, None]" - assert stringify(Generator[None, None, None], "fully-qualified") == "typing.Generator[None, None, None]" - assert stringify(Generator[None, None, None], "smart") == "~typing.Generator[None, None, None]" + assert stringify_annotation(Generator[None, None, None], 'fully-qualified-except-typing') == "Generator[None, None, None]" + assert stringify_annotation(Generator[None, None, None], "fully-qualified") == "typing.Generator[None, None, None]" + assert stringify_annotation(Generator[None, None, None], "smart") == "~typing.Generator[None, None, None]" @pytest.mark.skipif(sys.version_info[:2] <= (3, 8), reason='python 3.9+ is required.') def test_stringify_type_hints_pep_585(): - assert stringify(list[int]) == "list[int]" - assert stringify(list[int], "smart") == "list[int]" + assert stringify_annotation(list[int], 'fully-qualified-except-typing') == "list[int]" + assert stringify_annotation(list[int], "smart") == "list[int]" - assert stringify(list[str]) == "list[str]" - assert stringify(list[str], "smart") == "list[str]" + assert stringify_annotation(list[str], 'fully-qualified-except-typing') == "list[str]" + assert stringify_annotation(list[str], "smart") == "list[str]" - assert stringify(dict[str, float]) == "dict[str, float]" - assert stringify(dict[str, float], "smart") == "dict[str, float]" + assert stringify_annotation(dict[str, float], 'fully-qualified-except-typing') == "dict[str, float]" + assert stringify_annotation(dict[str, float], "smart") == "dict[str, float]" - assert stringify(tuple[str, str, str]) == "tuple[str, str, str]" - assert stringify(tuple[str, str, str], "smart") == "tuple[str, str, str]" + assert stringify_annotation(tuple[str, str, str], 'fully-qualified-except-typing') == "tuple[str, str, str]" + assert stringify_annotation(tuple[str, str, str], "smart") == "tuple[str, str, str]" - assert stringify(tuple[str, ...]) == "tuple[str, ...]" - assert stringify(tuple[str, ...], "smart") == "tuple[str, ...]" + assert stringify_annotation(tuple[str, ...], 'fully-qualified-except-typing') == "tuple[str, ...]" + assert stringify_annotation(tuple[str, ...], "smart") == "tuple[str, ...]" - assert stringify(tuple[()]) == "tuple[()]" - assert stringify(tuple[()], "smart") == "tuple[()]" + assert stringify_annotation(tuple[()], 'fully-qualified-except-typing') == "tuple[()]" + assert stringify_annotation(tuple[()], "smart") == "tuple[()]" - assert stringify(list[dict[str, tuple]]) == "list[dict[str, tuple]]" - assert stringify(list[dict[str, tuple]], "smart") == "list[dict[str, tuple]]" + assert stringify_annotation(list[dict[str, tuple]], 'fully-qualified-except-typing') == "list[dict[str, tuple]]" + assert stringify_annotation(list[dict[str, tuple]], "smart") == "list[dict[str, tuple]]" - assert stringify(type[int]) == "type[int]" - assert stringify(type[int], "smart") == "type[int]" + assert stringify_annotation(type[int], 'fully-qualified-except-typing') == "type[int]" + assert stringify_annotation(type[int], "smart") == "type[int]" @pytest.mark.skipif(sys.version_info[:2] <= (3, 8), reason='python 3.9+ is required.') def test_stringify_Annotated(): from typing import Annotated # type: ignore - assert stringify(Annotated[str, "foo", "bar"]) == "str" - assert stringify(Annotated[str, "foo", "bar"], "smart") == "str" + assert stringify_annotation(Annotated[str, "foo", "bar"], 'fully-qualified-except-typing') == "str" + assert stringify_annotation(Annotated[str, "foo", "bar"], "smart") == "str" def test_stringify_type_hints_string(): - assert stringify("int") == "int" - assert stringify("int", "smart") == "int" + assert stringify_annotation("int", 'fully-qualified-except-typing') == "int" + assert stringify_annotation("int", 'fully-qualified') == "int" + assert stringify_annotation("int", "smart") == "int" - assert stringify("str") == "str" - assert stringify("str", "smart") == "str" + assert stringify_annotation("str", 'fully-qualified-except-typing') == "str" + assert stringify_annotation("str", 'fully-qualified') == "str" + assert stringify_annotation("str", "smart") == "str" - assert stringify(List["int"]) == "List[int]" - assert stringify(List["int"], "smart") == "~typing.List[int]" + assert stringify_annotation(List["int"], 'fully-qualified-except-typing') == "List[int]" + assert stringify_annotation(List["int"], 'fully-qualified') == "typing.List[int]" + assert stringify_annotation(List["int"], "smart") == "~typing.List[int]" - assert stringify("Tuple[str]") == "Tuple[str]" - assert stringify("Tuple[str]", "smart") == "Tuple[str]" + assert stringify_annotation("Tuple[str]", 'fully-qualified-except-typing') == "Tuple[str]" + assert stringify_annotation("Tuple[str]", 'fully-qualified') == "Tuple[str]" + assert stringify_annotation("Tuple[str]", "smart") == "Tuple[str]" - assert stringify("unknown") == "unknown" - assert stringify("unknown", "smart") == "unknown" + assert stringify_annotation("unknown", 'fully-qualified-except-typing') == "unknown" + assert stringify_annotation("unknown", 'fully-qualified') == "unknown" + assert stringify_annotation("unknown", "smart") == "unknown" def test_stringify_type_hints_Callable(): - assert stringify(Callable) == "Callable" - assert stringify(Callable, "fully-qualified") == "typing.Callable" - assert stringify(Callable, "smart") == "~typing.Callable" + assert stringify_annotation(Callable, 'fully-qualified-except-typing') == "Callable" + assert stringify_annotation(Callable, "fully-qualified") == "typing.Callable" + assert stringify_annotation(Callable, "smart") == "~typing.Callable" - assert stringify(Callable[[str], int]) == "Callable[[str], int]" - assert stringify(Callable[[str], int], "fully-qualified") == "typing.Callable[[str], int]" - assert stringify(Callable[[str], int], "smart") == "~typing.Callable[[str], int]" + assert stringify_annotation(Callable[[str], int], 'fully-qualified-except-typing') == "Callable[[str], int]" + assert stringify_annotation(Callable[[str], int], "fully-qualified") == "typing.Callable[[str], int]" + assert stringify_annotation(Callable[[str], int], "smart") == "~typing.Callable[[str], int]" - assert stringify(Callable[..., int]) == "Callable[[...], int]" - assert stringify(Callable[..., int], "fully-qualified") == "typing.Callable[[...], int]" - assert stringify(Callable[..., int], "smart") == "~typing.Callable[[...], int]" + assert stringify_annotation(Callable[..., int], 'fully-qualified-except-typing') == "Callable[[...], int]" + assert stringify_annotation(Callable[..., int], "fully-qualified") == "typing.Callable[[...], int]" + assert stringify_annotation(Callable[..., int], "smart") == "~typing.Callable[[...], int]" def test_stringify_type_hints_Union(): - assert stringify(Optional[int]) == "Optional[int]" - assert stringify(Optional[int], "fully-qualified") == "typing.Optional[int]" - assert stringify(Optional[int], "smart") == "~typing.Optional[int]" + assert stringify_annotation(Optional[int], 'fully-qualified-except-typing') == "int | None" + assert stringify_annotation(Optional[int], "fully-qualified") == "int | None" + assert stringify_annotation(Optional[int], "smart") == "int | None" - assert stringify(Union[str, None]) == "Optional[str]" - assert stringify(Union[str, None], "fully-qualified") == "typing.Optional[str]" - assert stringify(Union[str, None], "smart") == "~typing.Optional[str]" + assert stringify_annotation(Union[str, None], 'fully-qualified-except-typing') == "str | None" + assert stringify_annotation(Union[str, None], "fully-qualified") == "str | None" + assert stringify_annotation(Union[str, None], "smart") == "str | None" - assert stringify(Union[int, str]) == "Union[int, str]" - assert stringify(Union[int, str], "fully-qualified") == "typing.Union[int, str]" - assert stringify(Union[int, str], "smart") == "~typing.Union[int, str]" + assert stringify_annotation(Union[int, str], 'fully-qualified-except-typing') == "int | str" + assert stringify_annotation(Union[int, str], "fully-qualified") == "int | str" + assert stringify_annotation(Union[int, str], "smart") == "int | str" - assert stringify(Union[int, Integral]) == "Union[int, numbers.Integral]" - assert stringify(Union[int, Integral], "fully-qualified") == "typing.Union[int, numbers.Integral]" - assert stringify(Union[int, Integral], "smart") == "~typing.Union[int, ~numbers.Integral]" + assert stringify_annotation(Union[int, Integral], 'fully-qualified-except-typing') == "int | numbers.Integral" + assert stringify_annotation(Union[int, Integral], "fully-qualified") == "int | numbers.Integral" + assert stringify_annotation(Union[int, Integral], "smart") == "int | ~numbers.Integral" - assert (stringify(Union[MyClass1, MyClass2]) == - "Union[tests.test_util_typing.MyClass1, tests.test_util_typing.<MyClass2>]") - assert (stringify(Union[MyClass1, MyClass2], "fully-qualified") == - "typing.Union[tests.test_util_typing.MyClass1, tests.test_util_typing.<MyClass2>]") - assert (stringify(Union[MyClass1, MyClass2], "smart") == - "~typing.Union[~tests.test_util_typing.MyClass1, ~tests.test_util_typing.<MyClass2>]") + assert (stringify_annotation(Union[MyClass1, MyClass2], 'fully-qualified-except-typing') == + "tests.test_util_typing.MyClass1 | tests.test_util_typing.<MyClass2>") + assert (stringify_annotation(Union[MyClass1, MyClass2], "fully-qualified") == + "tests.test_util_typing.MyClass1 | tests.test_util_typing.<MyClass2>") + assert (stringify_annotation(Union[MyClass1, MyClass2], "smart") == + "~tests.test_util_typing.MyClass1 | ~tests.test_util_typing.<MyClass2>") def test_stringify_type_hints_typevars(): @@ -368,72 +373,72 @@ def test_stringify_type_hints_typevars(): T_co = TypeVar('T_co', covariant=True) T_contra = TypeVar('T_contra', contravariant=True) - assert stringify(T) == "tests.test_util_typing.T" - assert stringify(T, "smart") == "~tests.test_util_typing.T" + assert stringify_annotation(T, 'fully-qualified-except-typing') == "tests.test_util_typing.T" + assert stringify_annotation(T, "smart") == "~tests.test_util_typing.T" - assert stringify(T_co) == "tests.test_util_typing.T_co" - assert stringify(T_co, "smart") == "~tests.test_util_typing.T_co" + assert stringify_annotation(T_co, 'fully-qualified-except-typing') == "tests.test_util_typing.T_co" + assert stringify_annotation(T_co, "smart") == "~tests.test_util_typing.T_co" - assert stringify(T_contra) == "tests.test_util_typing.T_contra" - assert stringify(T_contra, "smart") == "~tests.test_util_typing.T_contra" + assert stringify_annotation(T_contra, 'fully-qualified-except-typing') == "tests.test_util_typing.T_contra" + assert stringify_annotation(T_contra, "smart") == "~tests.test_util_typing.T_contra" - assert stringify(List[T]) == "List[tests.test_util_typing.T]" - assert stringify(List[T], "smart") == "~typing.List[~tests.test_util_typing.T]" + assert stringify_annotation(List[T], 'fully-qualified-except-typing') == "List[tests.test_util_typing.T]" + assert stringify_annotation(List[T], "smart") == "~typing.List[~tests.test_util_typing.T]" if sys.version_info[:2] >= (3, 10): - assert stringify(MyInt) == "tests.test_util_typing.MyInt" - assert stringify(MyInt, "smart") == "~tests.test_util_typing.MyInt" + assert stringify_annotation(MyInt, 'fully-qualified-except-typing') == "tests.test_util_typing.MyInt" + assert stringify_annotation(MyInt, "smart") == "~tests.test_util_typing.MyInt" else: - assert stringify(MyInt) == "MyInt" - assert stringify(MyInt, "smart") == "MyInt" + assert stringify_annotation(MyInt, 'fully-qualified-except-typing') == "MyInt" + assert stringify_annotation(MyInt, "smart") == "MyInt" def test_stringify_type_hints_custom_class(): - assert stringify(MyClass1) == "tests.test_util_typing.MyClass1" - assert stringify(MyClass1, "smart") == "~tests.test_util_typing.MyClass1" + assert stringify_annotation(MyClass1, 'fully-qualified-except-typing') == "tests.test_util_typing.MyClass1" + assert stringify_annotation(MyClass1, "smart") == "~tests.test_util_typing.MyClass1" - assert stringify(MyClass2) == "tests.test_util_typing.<MyClass2>" - assert stringify(MyClass2, "smart") == "~tests.test_util_typing.<MyClass2>" + assert stringify_annotation(MyClass2, 'fully-qualified-except-typing') == "tests.test_util_typing.<MyClass2>" + assert stringify_annotation(MyClass2, "smart") == "~tests.test_util_typing.<MyClass2>" def test_stringify_type_hints_alias(): MyStr = str MyTuple = Tuple[str, str] - assert stringify(MyStr) == "str" - assert stringify(MyStr, "smart") == "str" + assert stringify_annotation(MyStr, 'fully-qualified-except-typing') == "str" + assert stringify_annotation(MyStr, "smart") == "str" - assert stringify(MyTuple) == "Tuple[str, str]" # type: ignore - assert stringify(MyTuple, "smart") == "~typing.Tuple[str, str]" # type: ignore + assert stringify_annotation(MyTuple) == "Tuple[str, str]" # type: ignore + assert stringify_annotation(MyTuple, "smart") == "~typing.Tuple[str, str]" # type: ignore def test_stringify_type_Literal(): from typing import Literal # type: ignore - assert stringify(Literal[1, "2", "\r"]) == "Literal[1, '2', '\\r']" - assert stringify(Literal[1, "2", "\r"], "fully-qualified") == "typing.Literal[1, '2', '\\r']" - assert stringify(Literal[1, "2", "\r"], "smart") == "~typing.Literal[1, '2', '\\r']" + assert stringify_annotation(Literal[1, "2", "\r"], 'fully-qualified-except-typing') == "Literal[1, '2', '\\r']" + assert stringify_annotation(Literal[1, "2", "\r"], "fully-qualified") == "typing.Literal[1, '2', '\\r']" + assert stringify_annotation(Literal[1, "2", "\r"], "smart") == "~typing.Literal[1, '2', '\\r']" @pytest.mark.skipif(sys.version_info[:2] <= (3, 9), reason='python 3.10+ is required.') def test_stringify_type_union_operator(): - assert stringify(int | None) == "int | None" # type: ignore - assert stringify(int | None, "smart") == "int | None" # type: ignore + assert stringify_annotation(int | None) == "int | None" # type: ignore + assert stringify_annotation(int | None, "smart") == "int | None" # type: ignore - assert stringify(int | str) == "int | str" # type: ignore - assert stringify(int | str, "smart") == "int | str" # type: ignore + assert stringify_annotation(int | str) == "int | str" # type: ignore + assert stringify_annotation(int | str, "smart") == "int | str" # type: ignore - assert stringify(int | str | None) == "int | str | None" # type: ignore - assert stringify(int | str | None, "smart") == "int | str | None" # type: ignore + assert stringify_annotation(int | str | None) == "int | str | None" # type: ignore + assert stringify_annotation(int | str | None, "smart") == "int | str | None" # type: ignore def test_stringify_broken_type_hints(): - assert stringify(BrokenType) == 'tests.test_util_typing.BrokenType' - assert stringify(BrokenType, "smart") == '~tests.test_util_typing.BrokenType' + assert stringify_annotation(BrokenType, 'fully-qualified-except-typing') == 'tests.test_util_typing.BrokenType' + assert stringify_annotation(BrokenType, "smart") == '~tests.test_util_typing.BrokenType' def test_stringify_mock(): with mock(['unknown']): import unknown - assert stringify(unknown) == 'unknown' - assert stringify(unknown.secret.Class) == 'unknown.secret.Class' - assert stringify(unknown.secret.Class, "smart") == 'unknown.secret.Class' + assert stringify_annotation(unknown, 'fully-qualified-except-typing') == 'unknown' + assert stringify_annotation(unknown.secret.Class, 'fully-qualified-except-typing') == 'unknown.secret.Class' + assert stringify_annotation(unknown.secret.Class, "smart") == 'unknown.secret.Class' |