Add flat types deflator tests
This commit is contained in:
53
tests/test_flat_types_deflator.py
Normal file
53
tests/test_flat_types_deflator.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
|
||||
from megasniff.deflator import SchemaDeflatorGenerator
|
||||
from src.megasniff import SchemaInflatorGenerator
|
||||
|
||||
|
||||
def test_str_deflator():
|
||||
defl = SchemaDeflatorGenerator()
|
||||
fn = defl.schema_to_deflator(str, explicit_casts_override=True)
|
||||
a = fn('asdf')
|
||||
|
||||
assert a == 'asdf'
|
||||
a = fn(1234)
|
||||
|
||||
assert a == '1234'
|
||||
|
||||
fn1 = defl.schema_to_deflator(str, strict_mode_override=True)
|
||||
with pytest.raises(Exception):
|
||||
fn1(1234)
|
||||
|
||||
|
||||
def test_int_deflator():
|
||||
defl = SchemaDeflatorGenerator()
|
||||
fn = defl.schema_to_deflator(int, explicit_casts_override=True)
|
||||
a = fn(1234)
|
||||
|
||||
assert a == 1234
|
||||
a = fn('1234')
|
||||
|
||||
assert a == 1234
|
||||
|
||||
fn1 = defl.schema_to_deflator(int, strict_mode_override=True)
|
||||
with pytest.raises(Exception):
|
||||
fn1('1234')
|
||||
|
||||
|
||||
def test_float_deflator():
|
||||
defl = SchemaDeflatorGenerator()
|
||||
fn = defl.schema_to_deflator(float, explicit_casts_override=True)
|
||||
a = fn(1234.1)
|
||||
|
||||
assert a == 1234.1
|
||||
a = fn('1234')
|
||||
|
||||
assert a == 1234.0
|
||||
|
||||
fn1 = defl.schema_to_deflator(float, strict_mode_override=True)
|
||||
with pytest.raises(Exception):
|
||||
fn1(1234)
|
||||
Reference in New Issue
Block a user