Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pt_snap_cli/query/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/pt_snap_cli/query/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
7 changes: 7 additions & 0 deletions tests/query/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading