Remove lookup_table from inflator generated code, rename generating func

This commit is contained in:
2025-07-12 05:50:56 +03:00
parent aee6dcf3d3
commit 897eccd8d1
10 changed files with 131 additions and 79 deletions

View File

@@ -11,7 +11,7 @@ def test_basic_constructor():
self.a = a
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(A)
fn = infl.schema_to_inflator(A)
a = fn({'a': 42})
assert a.a == 42
@@ -23,7 +23,7 @@ def test_unions():
a: int | str
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(A)
fn = infl.schema_to_inflator(A)
a = fn({'a': 42})
assert a.a == 42
@@ -45,10 +45,10 @@ class CircB:
def test_circular():
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(CircA)
fn = infl.schema_to_inflator(CircA)
a = fn({'b': {'a': None}})
return isinstance(a.b, CircB)
assert isinstance(a.b, CircB)
def test_optional():
@@ -57,6 +57,6 @@ def test_optional():
a: Optional[int] = None
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(C)
fn = infl.schema_to_inflator(C)
c = fn({})
assert c.a is None

View File

@@ -12,7 +12,7 @@ def test_missing_field():
a: int
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(A)
fn = infl.schema_to_inflator(A)
with pytest.raises(MissingFieldException):
fn({})
@@ -23,7 +23,7 @@ def test_null():
a: int
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(A)
fn = infl.schema_to_inflator(A)
with pytest.raises(FieldValidationException):
fn({'a': None})
@@ -34,6 +34,6 @@ def test_invalid_field():
a: float | int | None
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(A)
fn = infl.schema_to_inflator(A)
with pytest.raises(FieldValidationException):
fn({'a': {}})

22
tests/test_iterables.py Normal file
View File

@@ -0,0 +1,22 @@
from dataclasses import dataclass
from megasniff import SchemaInflatorGenerator
# def test_list():
# @dataclass
# class A:
# l: list[int]
#
# infl = SchemaInflatorGenerator()
# fn = infl.schema_to_generator(A)
#
# a = fn({'l': []})
# assert isinstance(a.l, list)
# assert len(a.l) == 0
#
# a = fn({'l': [1, 2.1, '0']})
# print(a.l)
# assert isinstance(a.l, list)
# assert len(a.l) == 3
# assert all(map(lambda x: isinstance(x, int), a.l))