44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
from dataclasses import dataclass
|
|
from typing import get_type_hints, Any, Annotated
|
|
|
|
from megasniff import SchemaInflatorGenerator
|
|
|
|
|
|
def test_return_signature():
|
|
@dataclass
|
|
class A:
|
|
a: list[int]
|
|
|
|
infl = SchemaInflatorGenerator(strict_mode=True)
|
|
fn = infl.schema_to_inflator(A)
|
|
|
|
hints = get_type_hints(fn)
|
|
assert hints['return'] == A
|
|
assert len(hints) == 2
|
|
|
|
|
|
def test_argument_signature():
|
|
@dataclass
|
|
class A:
|
|
a: list[int]
|
|
|
|
infl = SchemaInflatorGenerator(strict_mode=True)
|
|
|
|
type custom_from_type = dict[str, Any]
|
|
|
|
fn1 = infl.schema_to_inflator(A, from_type_override=custom_from_type)
|
|
|
|
fn2 = infl.schema_to_inflator(A)
|
|
|
|
hints = get_type_hints(fn1)
|
|
assert hints['return'] == A
|
|
assert len(hints) == 2
|
|
assert hints['from_data'] == custom_from_type
|
|
assert hints['from_data'] != dict[str, Any]
|
|
|
|
hints = get_type_hints(fn2)
|
|
assert hints['return'] == A
|
|
assert len(hints) == 2
|
|
assert hints['from_data'] != custom_from_type
|
|
assert hints['from_data'] == dict[str, Any]
|