diff --git a/src/pt_snap_cli/query/config.py b/src/pt_snap_cli/query/config.py index 1918c69..d2fdfde 100644 --- a/src/pt_snap_cli/query/config.py +++ b/src/pt_snap_cli/query/config.py @@ -41,7 +41,7 @@ def validate(self, value: Any) -> Any: "str": str, "int": int, "float": float, - "bool": lambda x: bool(x) if isinstance(x, str) else x, + "bool": lambda x: x.lower() in ("true", "1", "yes") if isinstance(x, str) else bool(x), } converter = type_converters.get(self.type, str) diff --git a/src/pt_snap_cli/query/mapper.py b/src/pt_snap_cli/query/mapper.py index a62bb0a..a9f2cf8 100644 --- a/src/pt_snap_cli/query/mapper.py +++ b/src/pt_snap_cli/query/mapper.py @@ -16,7 +16,7 @@ def __init__(self): "int": int, "float": float, "str": str, - "bool": bool, + "bool": lambda x: x.lower() in ("true", "1", "yes") if isinstance(x, str) else bool(x), "hex": lambda x: hex(x) if isinstance(x, int) else x, "datetime": lambda x: x, } diff --git a/tests/query/test_config.py b/tests/query/test_config.py index d81b494..e464f1e 100644 --- a/tests/query/test_config.py +++ b/tests/query/test_config.py @@ -24,7 +24,14 @@ def test_validate_float(self): def test_validate_bool(self): param = QueryParameter(name="test", type="bool", required=False) assert param.validate("true") is True + assert param.validate("false") is False + assert param.validate("True") is True + assert param.validate("False") is False + assert param.validate("1") is True + assert param.validate("0") is False + assert param.validate("yes") is True assert param.validate(False) is False + assert param.validate(True) is True def test_validate_missing_optional(self): param = QueryParameter(name="test", type="str", required=False, default="default")