Rename IMPERIAL_SYSTEM to US_CUSTOMARY_SYSTEM (#80253)
* Rename IMPERIAL_SYSTEM * Deprecate is_metric property and adjust tests * Adjust unit_system config validation * Add yaml tests * Add tests for private name * Fix incorrect rebase * Adjust docstring * Add store migration * Update unit_system.py * Minimise test tweaks * Fix tests * Add conversion to migration * Rename new key and adjust tests * Adjust websocket_detect_config * Move original_unit_system tracking to subclass
This commit is contained in:
parent
f4951a4f31
commit
67d1dde69f
5 changed files with 125 additions and 22 deletions
|
@ -22,8 +22,10 @@ from homeassistant.exceptions import HomeAssistantError
|
|||
from homeassistant.util.unit_system import (
|
||||
_CONF_UNIT_SYSTEM_IMPERIAL,
|
||||
_CONF_UNIT_SYSTEM_METRIC,
|
||||
_CONF_UNIT_SYSTEM_US_CUSTOMARY,
|
||||
IMPERIAL_SYSTEM,
|
||||
METRIC_SYSTEM,
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
UnitSystem,
|
||||
get_unit_system,
|
||||
)
|
||||
|
@ -320,17 +322,26 @@ def test_is_metric(
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"unit_system, expected_name",
|
||||
"unit_system, expected_name, expected_private_name",
|
||||
[
|
||||
(METRIC_SYSTEM, _CONF_UNIT_SYSTEM_METRIC),
|
||||
(IMPERIAL_SYSTEM, _CONF_UNIT_SYSTEM_IMPERIAL),
|
||||
(METRIC_SYSTEM, _CONF_UNIT_SYSTEM_METRIC, _CONF_UNIT_SYSTEM_METRIC),
|
||||
(IMPERIAL_SYSTEM, _CONF_UNIT_SYSTEM_IMPERIAL, _CONF_UNIT_SYSTEM_US_CUSTOMARY),
|
||||
(
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
_CONF_UNIT_SYSTEM_IMPERIAL,
|
||||
_CONF_UNIT_SYSTEM_US_CUSTOMARY,
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_deprecated_name(
|
||||
caplog: pytest.LogCaptureFixture, unit_system: UnitSystem, expected_name: str
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
unit_system: UnitSystem,
|
||||
expected_name: str,
|
||||
expected_private_name: str,
|
||||
) -> None:
|
||||
"""Test the name is deprecated."""
|
||||
assert unit_system.name == expected_name
|
||||
assert unit_system._name == expected_private_name
|
||||
assert (
|
||||
"Detected code that accesses the `name` property of the unit system."
|
||||
in caplog.text
|
||||
|
@ -341,7 +352,7 @@ def test_deprecated_name(
|
|||
"key, expected_system",
|
||||
[
|
||||
(_CONF_UNIT_SYSTEM_METRIC, METRIC_SYSTEM),
|
||||
(_CONF_UNIT_SYSTEM_IMPERIAL, IMPERIAL_SYSTEM),
|
||||
(_CONF_UNIT_SYSTEM_US_CUSTOMARY, US_CUSTOMARY_SYSTEM),
|
||||
],
|
||||
)
|
||||
def test_get_unit_system(key: str, expected_system: UnitSystem) -> None:
|
||||
|
@ -349,7 +360,9 @@ def test_get_unit_system(key: str, expected_system: UnitSystem) -> None:
|
|||
assert get_unit_system(key) is expected_system
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key", [None, "", "invalid_custom"])
|
||||
@pytest.mark.parametrize(
|
||||
"key", [None, "", "invalid_custom", _CONF_UNIT_SYSTEM_IMPERIAL]
|
||||
)
|
||||
def test_get_unit_system_invalid(key: str) -> None:
|
||||
"""Test get_unit_system with an invalid key."""
|
||||
with pytest.raises(ValueError, match=f"`{key}` is not a valid unit system key"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue