()
| 57 | |
| 58 | |
| 59 | def test_annotation_issubclass() -> None: |
| 60 | def func( |
| 61 | int_arg: int, |
| 62 | base_model: BaseModel, |
| 63 | list_arg: list, # type: ignore[type-arg] # what we test |
| 64 | dict_arg: dict, # type: ignore[type-arg] # what we test |
| 65 | list_typing_arg: typing.List, # type: ignore[type-arg] # what we test |
| 66 | dict_typing_arg: typing.Dict, # type: ignore[type-arg] # what we test |
| 67 | list_typing_generic_arg: typing.List[str], |
| 68 | dict_typing_generic_arg: typing.Dict[str, str], |
| 69 | ) -> None: |
| 70 | pass |
| 71 | |
| 72 | parameters = inspect.signature(func).parameters |
| 73 | assert annotation_issubclass(parameters['int_arg'].annotation, int) is True |
| 74 | assert annotation_issubclass(parameters['base_model'].annotation, BaseModel) is True |
| 75 | assert annotation_issubclass(parameters['list_arg'].annotation, list) is True |
| 76 | assert annotation_issubclass(parameters['dict_arg'].annotation, dict) is True |
| 77 | |
| 78 | # Here the annotation is simply not a class, so function must return False |
| 79 | assert annotation_issubclass(parameters['list_typing_arg'].annotation, BaseModel) is False |
| 80 | assert annotation_issubclass(parameters['dict_typing_arg'].annotation, BaseModel) is False |
| 81 | assert annotation_issubclass(parameters['list_typing_generic_arg'].annotation, BaseModel) is False |
| 82 | assert annotation_issubclass(parameters['dict_typing_generic_arg'].annotation, BaseModel) is False |
| 83 | |
| 84 | |
| 85 | @pytest.mark.skipif(sys.version_info < (3, 9), reason="Notation is only supported in Python 3.9 or newer.") |
nothing calls this directly
no test coverage detected