Skip to content

Commit a6c3fb6

Browse files
committed
Add test_util.test_data_conversion
Signed-off-by: David Rapan <[email protected]>
1 parent 6c56fb0 commit a6c3fb6

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/components/sql/test_util.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
"""Test the sql utils."""
22

3+
from datetime import date
4+
from decimal import Decimal
5+
36
import pytest
47
import voluptuous as vol
58

69
from homeassistant.components.recorder import Recorder, get_instance
7-
from homeassistant.components.sql.util import resolve_db_url, validate_sql_select
10+
from homeassistant.components.sql.util import (
11+
ensure_serializable,
12+
resolve_db_url,
13+
validate_sql_select,
14+
)
815
from homeassistant.core import HomeAssistant
916

1017

@@ -64,3 +71,22 @@ async def test_invalid_sql_queries(
6471
"""Test that various invalid or disallowed SQL queries raise the correct exception."""
6572
with pytest.raises(vol.Invalid, match=expected_error_message):
6673
validate_sql_select(sql_query)
74+
75+
76+
@pytest.mark.parametrize(
77+
("input", "expected_output"),
78+
[
79+
(Decimal("199.99"), 199.99),
80+
(date(2023, 1, 15), "2023-01-15"),
81+
(b"\xde\xad\xbe\xef", "0xdeadbeef"),
82+
("deadbeef", "deadbeef"),
83+
(199.99, 199.99),
84+
(69, 69),
85+
],
86+
)
87+
async def test_data_conversion(
88+
input: Decimal | date | bytes | str | float,
89+
expected_output: str | float,
90+
) -> None:
91+
"""Test data conversion to serializable type."""
92+
assert ensure_serializable(input) == expected_output

0 commit comments

Comments
 (0)