示例#1
0
def test_repr_type(case):
    tp, expected = case
    assert repr_type(tp) == expected
示例#2
0
 def type_name(self) -> str:  # pragma: no cover
     """String representation of the Python type annotation for this field."""
     return repr_type(self.type_obj)
示例#3
0
        "<mro (tests.test_typing.test_repr_type_with_mro.<locals>.FancyInt, int, object)>"
    )
    assert repr_type_with_mro(FancyInt()) == repr(FancyInt())


# Test backports against typing module implementations
if sys.version_info[:2] >= (3, 7):

    backport_cases = [
        int,
        typing.List[int],
        typing.Optional[int],
        MyClass,
        typing.List[MyClass],
        typing.Optional[MyClass],
    ]

    @pytest.mark.parametrize("tp",
                             backport_cases,
                             ids=[repr_type(c) for c in backport_cases])
    def test_get_args(tp):
        assert _get_args is not get_args
        assert _get_args(tp) == get_args(tp)

    @pytest.mark.parametrize("tp",
                             backport_cases,
                             ids=[repr_type(c) for c in backport_cases])
    def test_get_origin(tp):
        assert _get_args is not get_origin
        assert _get_origin(tp) == get_origin(tp)
示例#4
0
def test_repr_type_literal():
    tp = Literal["batman"]
    assert "Literal['batman']" in repr_type(tp)