Improve bad JSON data reporting (#47932)

* Improve bad data reporting

* Fix tests

Co-authored-by: Erik <erik@montnemery.com>
This commit is contained in:
Paulus Schoutsen 2021-03-15 02:41:25 -07:00 committed by GitHub
parent 9ec4c07753
commit 7fe3c472e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 10 deletions

View file

@ -67,7 +67,7 @@ async def test_pending_msg_peak(hass, mock_low_peak, hass_ws_client, caplog):
async def test_non_json_message(hass, websocket_client, caplog):
"""Test trying to serialze non JSON objects."""
"""Test trying to serialize non JSON objects."""
bad_data = object()
hass.states.async_set("test_domain.entity", "testing", {"bad": bad_data})
await websocket_client.send_json({"id": 5, "type": "get_states"})
@ -77,6 +77,6 @@ async def test_non_json_message(hass, websocket_client, caplog):
assert msg["type"] == const.TYPE_RESULT
assert not msg["success"]
assert (
f"Unable to serialize to JSON. Bad data found at $.result[0](state: test_domain.entity).attributes.bad={bad_data}(<class 'object'>"
f"Unable to serialize to JSON. Bad data found at $.result[0](State: test_domain.entity).attributes.bad={bad_data}(<class 'object'>"
in caplog.text
)