Initial upload: ConfigConvert CLI with full test suite and CI/CD
This commit is contained in:
96
tests/test_type_inference.py
Normal file
96
tests/test_type_inference.py
Normal file
@@ -0,0 +1,96 @@
|
||||
"""Tests for type inference module."""
|
||||
|
||||
import pytest
|
||||
|
||||
from config_convert.utils import detect_type, convert_value, infer_types
|
||||
|
||||
|
||||
class TestDetectType:
|
||||
def test_boolean_true_values(self):
|
||||
for value in ["true", "True", "TRUE", "yes", "Yes", "YES", "on", "ON"]:
|
||||
assert detect_type(value) == "boolean"
|
||||
|
||||
def test_boolean_false_values(self):
|
||||
for value in ["false", "False", "FALSE", "no", "No", "NO", "off", "OFF"]:
|
||||
assert detect_type(value) == "boolean"
|
||||
|
||||
def test_null_values(self):
|
||||
for value in ["null", "Null", "NULL", "~", ""]:
|
||||
assert detect_type(value) == "null"
|
||||
|
||||
def test_integers(self):
|
||||
assert detect_type("123") == "integer"
|
||||
assert detect_type("-456") == "integer"
|
||||
assert detect_type("0") == "integer"
|
||||
assert detect_type("1") == "integer"
|
||||
|
||||
def test_floats(self):
|
||||
assert detect_type("3.14") == "float"
|
||||
assert detect_type("-2.5") == "float"
|
||||
assert detect_type("1e10") == "float"
|
||||
assert detect_type("2.5e-3") == "float"
|
||||
|
||||
def test_arrays(self):
|
||||
assert detect_type("[1,2,3]") == "array"
|
||||
assert detect_type('["a","b"]') == "array"
|
||||
|
||||
def test_strings(self):
|
||||
assert detect_type("hello") == "string"
|
||||
assert detect_type("hello world") == "string"
|
||||
assert detect_type("123abc") == "string"
|
||||
|
||||
|
||||
class TestConvertValue:
|
||||
def test_convert_boolean_true(self):
|
||||
assert convert_value("true") is True
|
||||
assert convert_value("yes") is True
|
||||
|
||||
def test_convert_boolean_false(self):
|
||||
assert convert_value("false") is False
|
||||
assert convert_value("no") is False
|
||||
|
||||
def test_convert_integer_one_zero(self):
|
||||
assert convert_value("1") == 1
|
||||
assert convert_value("0") == 0
|
||||
|
||||
def test_convert_null(self):
|
||||
assert convert_value("null") is None
|
||||
assert convert_value("~") is None
|
||||
|
||||
def test_convert_integer(self):
|
||||
assert convert_value("123") == 123
|
||||
assert convert_value("-456") == -456
|
||||
|
||||
def test_convert_float(self):
|
||||
assert convert_value("3.14") == 3.14
|
||||
assert convert_value("1e10") == 1e10
|
||||
|
||||
def test_convert_string(self):
|
||||
assert convert_value("hello") == "hello"
|
||||
assert convert_value("hello world") == "hello world"
|
||||
|
||||
def test_convert_array(self):
|
||||
result = convert_value("[1,2,3]")
|
||||
assert result == [1, 2, 3]
|
||||
|
||||
|
||||
class TestInferTypes:
|
||||
def test_infer_types_dict(self):
|
||||
data = {"count": "123", "enabled": "true"}
|
||||
result = infer_types(data)
|
||||
assert result == {"count": 123, "enabled": True}
|
||||
|
||||
def test_infer_types_nested(self):
|
||||
data = {"database": {"host": "localhost", "port": "5432"}}
|
||||
result = infer_types(data)
|
||||
assert result["database"]["port"] == 5432
|
||||
|
||||
def test_infer_types_list(self):
|
||||
data = {"tags": ["1", "2", "3"]}
|
||||
result = infer_types(data)
|
||||
assert result["tags"] == [1, 2, 3]
|
||||
|
||||
def test_infer_types_preserves_non_strings(self):
|
||||
data = {"count": 123, "enabled": True, "ratio": 3.14}
|
||||
result = infer_types(data)
|
||||
assert result == data
|
||||
Reference in New Issue
Block a user