Use default encoder when saving storage (#75319)

This commit is contained in:
J. Nick Koston 2022-07-17 07:25:19 -05:00 committed by GitHub
parent 2eebda63fd
commit 9a27f1437d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 36 deletions

View file

@ -12,7 +12,6 @@ import pytest
from homeassistant.core import Event, State
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.json import JSONEncoder as DefaultHASSJSONEncoder
from homeassistant.helpers.template import TupleWrapper
from homeassistant.util.json import (
SerializationError,
find_paths_unserializable_data,
@ -83,23 +82,15 @@ def test_overwrite_and_reload(atomic_writes):
def test_save_bad_data():
"""Test error from trying to save unserializable data."""
class CannotSerializeMe:
"""Cannot serialize this."""
with pytest.raises(SerializationError) as excinfo:
save_json("test4", {"hello": set()})
save_json("test4", {"hello": CannotSerializeMe()})
assert (
"Failed to serialize to JSON: test4. Bad data at $.hello=set()(<class 'set'>"
in str(excinfo.value)
)
def test_save_bad_data_tuple_wrapper():
"""Test error from trying to save unserializable data."""
with pytest.raises(SerializationError) as excinfo:
save_json("test4", {"hello": TupleWrapper(("4", "5"))})
assert (
"Failed to serialize to JSON: test4. Bad data at $.hello=('4', '5')(<class 'homeassistant.helpers.template.TupleWrapper'>"
in str(excinfo.value)
assert "Failed to serialize to JSON: test4. Bad data at $.hello=" in str(
excinfo.value
)