Add custom exceptions, simplify generation template
This commit is contained in:
39
tests/test_exceptions.py
Normal file
39
tests/test_exceptions.py
Normal 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': {}})
|
||||
Reference in New Issue
Block a user