Add custom exceptions, simplify generation template

This commit is contained in:
2025-07-12 02:37:54 +03:00
parent ed5f975e87
commit 1994eaab0d
5 changed files with 99 additions and 51 deletions

39
tests/test_exceptions.py Normal file
View File

@@ -0,0 +1,39 @@
from dataclasses import dataclass
import pytest
from megasniff import SchemaInflatorGenerator
from megasniff.exceptions import MissingFieldException, FieldValidationException
def test_missing_field():
@dataclass
class A:
a: int
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(A)
with pytest.raises(MissingFieldException):
fn({})
def test_null():
@dataclass
class A:
a: int
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(A)
with pytest.raises(FieldValidationException):
fn({'a': None})
def test_invalid_field():
@dataclass
class A:
a: float | int | None
infl = SchemaInflatorGenerator()
fn = infl.schema_to_generator(A)
with pytest.raises(FieldValidationException):
fn({'a': {}})