mirror of
https://github.com/home-assistant/core.git
synced 2025-11-10 03:19:34 +00:00
Fix error reporting with unserializable json (#73908)
This commit is contained in:
@@ -11,6 +11,7 @@ import pytest
|
||||
|
||||
from homeassistant.core import Event, State
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.template import TupleWrapper
|
||||
from homeassistant.util.json import (
|
||||
SerializationError,
|
||||
find_paths_unserializable_data,
|
||||
@@ -72,7 +73,7 @@ def test_overwrite_and_reload(atomic_writes):
|
||||
|
||||
|
||||
def test_save_bad_data():
|
||||
"""Test error from trying to save unserialisable data."""
|
||||
"""Test error from trying to save unserializable data."""
|
||||
with pytest.raises(SerializationError) as excinfo:
|
||||
save_json("test4", {"hello": set()})
|
||||
|
||||
@@ -82,6 +83,17 @@ def test_save_bad_data():
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
|
||||
def test_load_bad_data():
|
||||
"""Test error from trying to load unserialisable data."""
|
||||
fname = _path_for("test5")
|
||||
|
||||
Reference in New Issue
Block a user