File: test_grouped_metadata.py

package info (click to toggle)
python-annotated-types 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 156 kB
  • sloc: python: 430; makefile: 50; sh: 5
file content (37 lines) | stat: -rw-r--r-- 889 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
from typing import Iterator

import pytest

if sys.version_info < (3, 9):
    from typing_extensions import Literal
else:
    from typing import Literal

from annotated_types import BaseMetadata, GroupedMetadata, Gt


def test_subclass_without_implementing_iter() -> None:
    with pytest.raises(TypeError):

        class Foo1(GroupedMetadata):
            pass

    class Foo2(GroupedMetadata):
        def __iter__(self) -> Iterator[BaseMetadata]:
            raise NotImplementedError

    with pytest.raises(NotImplementedError):
        for _ in Foo2():
            pass


def test_non_subclass_implementer() -> None:
    class Foo:
        __is_annotated_types_grouped_metadata__: Literal[True] = True

        def __iter__(self) -> Iterator[BaseMetadata]:
            return
            yield Gt(0)

    _: GroupedMetadata = Foo()  # type checker will fail if not valid