40 lines
826 B
Python
40 lines
826 B
Python
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_inflator(A)
|
|
with pytest.raises(MissingFieldException):
|
|
fn({})
|
|
|
|
|
|
def test_null():
|
|
@dataclass
|
|
class A:
|
|
a: int
|
|
|
|
infl = SchemaInflatorGenerator()
|
|
fn = infl.schema_to_inflator(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_inflator(A)
|
|
with pytest.raises(FieldValidationException):
|
|
fn({'a': {}})
|