Allow constructing iflators for dict->tuple for further args unwrap
This commit is contained in:
27
tests/test_tuple_inflate.py
Normal file
27
tests/test_tuple_inflate.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
from src.megasniff.utils import TupleSchemaItem
|
||||
from src.megasniff import SchemaInflatorGenerator
|
||||
|
||||
|
||||
def test_basic_tuple():
|
||||
infl = SchemaInflatorGenerator()
|
||||
|
||||
fn = infl.schema_to_inflator({'a': int, 'b': float, 'c': str, 'd': list[int]})
|
||||
a = fn({'a': 42, 'b': 1.1, 'c': 123, 'd': []})
|
||||
|
||||
assert a[0] == 42
|
||||
|
||||
fn = infl.schema_to_inflator((('a', int), ('b', list[int])))
|
||||
a = fn({'a': 42, 'b': ['1']})
|
||||
|
||||
assert a[1][0] == 1
|
||||
|
||||
fn = infl.schema_to_inflator(
|
||||
(('a', int), TupleSchemaItem(Optional[list[int]], key_name='b', has_default=True, default=None)))
|
||||
a = fn({'a': 42})
|
||||
|
||||
assert a[1] is None
|
||||
assert a[0] == 42
|
||||
Reference in New Issue
Block a user