feat(gateway): safe type converter (1879 BUG-1/BUG-2)
This commit is contained in:
24
tests/unit/test_converters.py
Normal file
24
tests/unit/test_converters.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import pytest
|
||||
|
||||
from ingestor.converters import ConversionError, to_typed_value
|
||||
|
||||
|
||||
@pytest.mark.parametrize('raw,expected', [
|
||||
('false', False), ('False', False), ('0', False), ('no', False),
|
||||
('off', False), ('', False), ('true', True), ('1', True), (True, True),
|
||||
])
|
||||
def test_bool_from_json_string(raw, expected):
|
||||
assert to_typed_value(raw, 'boolean') is expected
|
||||
|
||||
|
||||
def test_float_and_int():
|
||||
assert to_typed_value('42.5', 'float') == 42.5
|
||||
assert to_typed_value('7', 'int') == 7
|
||||
|
||||
|
||||
@pytest.mark.parametrize('raw,dtype', [
|
||||
(None, 'int'), ('abc', 'float'), ('123.123', 'int'), (None, 'float'),
|
||||
])
|
||||
def test_invalid_raises_conversion_error(raw, dtype):
|
||||
with pytest.raises(ConversionError):
|
||||
to_typed_value(raw, dtype)
|
||||
Reference in New Issue
Block a user