File: test_typing.py

package info (click to toggle)
python-odmantic 1.0.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 1,640 kB
  • sloc: python: 8,547; sh: 37; makefile: 34; xml: 13; javascript: 3
file content (22 lines) | stat: -rw-r--r-- 820 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from typing import Dict, List, Set

from odmantic.model import EmbeddedModel
from odmantic.typing import get_first_type_argument_subclassing


def test_get_first_type_argument_subclassing():
    class E(EmbeddedModel):
        e: int

    assert get_first_type_argument_subclassing(List[E], EmbeddedModel) == E
    assert get_first_type_argument_subclassing(Set[E], EmbeddedModel) == E
    assert get_first_type_argument_subclassing(Dict[int, E], EmbeddedModel) == E


def test_get_first_type_argument_subclassing_on_non_matching_generics():
    class E(EmbeddedModel):
        e: int

    assert get_first_type_argument_subclassing(E, EmbeddedModel) is None
    assert get_first_type_argument_subclassing(int, EmbeddedModel) is None
    assert get_first_type_argument_subclassing(Dict[int, str], EmbeddedModel) is None