Add warnings for deprecated json helpers (#121161)
This commit is contained in:
parent
04a6285e62
commit
fe0bafd067
2 changed files with 84 additions and 5 deletions
|
@ -13,6 +13,7 @@ from unittest.mock import Mock, patch
|
|||
import pytest
|
||||
|
||||
from homeassistant.core import Event, HomeAssistant, State
|
||||
from homeassistant.helpers import json as json_helper
|
||||
from homeassistant.helpers.json import (
|
||||
ExtendedJSONEncoder,
|
||||
JSONEncoder as DefaultHASSJSONEncoder,
|
||||
|
@ -25,9 +26,14 @@ from homeassistant.helpers.json import (
|
|||
)
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.color import RGBColor
|
||||
from homeassistant.util.json import SerializationError, load_json
|
||||
from homeassistant.util.json import (
|
||||
JSON_DECODE_EXCEPTIONS,
|
||||
JSON_ENCODE_EXCEPTIONS,
|
||||
SerializationError,
|
||||
load_json,
|
||||
)
|
||||
|
||||
from tests.common import json_round_trip
|
||||
from tests.common import import_and_test_deprecated_constant, json_round_trip
|
||||
|
||||
# Test data that can be saved as JSON
|
||||
TEST_JSON_A = {"a": 1, "B": "two"}
|
||||
|
@ -335,3 +341,50 @@ def test_find_unserializable_data() -> None:
|
|||
BadData(),
|
||||
dump=partial(json.dumps, cls=MockJSONEncoder),
|
||||
) == {"$(BadData).bla": bad_data}
|
||||
|
||||
|
||||
def test_deprecated_json_loads(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test deprecated json_loads function.
|
||||
|
||||
It was moved from helpers to util in #88099
|
||||
"""
|
||||
json_helper.json_loads("{}")
|
||||
assert (
|
||||
"json_loads is a deprecated function which will be removed in "
|
||||
"HA Core 2025.8. Use homeassistant.util.json.json_loads instead"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("constant_name", "replacement_name", "replacement"),
|
||||
[
|
||||
(
|
||||
"JSON_DECODE_EXCEPTIONS",
|
||||
"homeassistant.util.json.JSON_DECODE_EXCEPTIONS",
|
||||
JSON_DECODE_EXCEPTIONS,
|
||||
),
|
||||
(
|
||||
"JSON_ENCODE_EXCEPTIONS",
|
||||
"homeassistant.util.json.JSON_ENCODE_EXCEPTIONS",
|
||||
JSON_ENCODE_EXCEPTIONS,
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_deprecated_aliases(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
constant_name: str,
|
||||
replacement_name: str,
|
||||
replacement: Any,
|
||||
) -> None:
|
||||
"""Test deprecated JSON_DECODE_EXCEPTIONS and JSON_ENCODE_EXCEPTIONS constants.
|
||||
|
||||
They were moved from helpers to util in #88099
|
||||
"""
|
||||
import_and_test_deprecated_constant(
|
||||
caplog,
|
||||
json_helper,
|
||||
constant_name,
|
||||
replacement_name,
|
||||
replacement,
|
||||
"2025.8",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue