Use US_CUSTOMARY_SYSTEM in tests (#80658)

* Use US_CUSTOMARY_SYSTEM in tests

* Don't update test_unit_system
This commit is contained in:
epenet 2022-10-20 15:42:23 +02:00 committed by GitHub
parent 4e4682d2e0
commit e84e5f134e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 147 additions and 93 deletions

View file

@ -35,7 +35,7 @@ from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.restore_state import STORAGE_KEY as RESTORE_STATE_KEY
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM
from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM
from tests.common import mock_restore_cache_with_extra_data
@ -43,8 +43,8 @@ from tests.common import mock_restore_cache_with_extra_data
@pytest.mark.parametrize(
"unit_system,native_unit,state_unit,native_value,state_value",
[
(IMPERIAL_SYSTEM, TEMP_FAHRENHEIT, TEMP_FAHRENHEIT, 100, 100),
(IMPERIAL_SYSTEM, TEMP_CELSIUS, TEMP_FAHRENHEIT, 38, 100),
(US_CUSTOMARY_SYSTEM, TEMP_FAHRENHEIT, TEMP_FAHRENHEIT, 100, 100),
(US_CUSTOMARY_SYSTEM, TEMP_CELSIUS, TEMP_FAHRENHEIT, 38, 100),
(METRIC_SYSTEM, TEMP_FAHRENHEIT, TEMP_CELSIUS, 100, 38),
(METRIC_SYSTEM, TEMP_CELSIUS, TEMP_CELSIUS, 38, 38),
],

View file

@ -26,7 +26,7 @@ from homeassistant.components.recorder.util import get_instance, session_scope
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.setup import async_setup_component, setup_component
import homeassistant.util.dt as dt_util
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM
from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM
from tests.components.recorder.common import (
async_recorder_block_till_done,
@ -403,18 +403,18 @@ def test_compile_hourly_statistics_wrong_unit(hass_recorder, caplog, attributes)
@pytest.mark.parametrize(
"units, device_class, state_unit, display_unit, statistics_unit, unit_class, factor",
[
(IMPERIAL_SYSTEM, "distance", "m", "m", "m", "distance", 1),
(IMPERIAL_SYSTEM, "distance", "mi", "mi", "mi", "distance", 1),
(IMPERIAL_SYSTEM, "energy", "kWh", "kWh", "kWh", "energy", 1),
(IMPERIAL_SYSTEM, "energy", "Wh", "Wh", "Wh", "energy", 1),
(IMPERIAL_SYSTEM, "gas", "", "", "", "volume", 1),
(IMPERIAL_SYSTEM, "gas", "ft³", "ft³", "ft³", "volume", 1),
(IMPERIAL_SYSTEM, "monetary", "EUR", "EUR", "EUR", None, 1),
(IMPERIAL_SYSTEM, "monetary", "SEK", "SEK", "SEK", None, 1),
(IMPERIAL_SYSTEM, "volume", "", "", "", "volume", 1),
(IMPERIAL_SYSTEM, "volume", "ft³", "ft³", "ft³", "volume", 1),
(IMPERIAL_SYSTEM, "weight", "g", "g", "g", "mass", 1),
(IMPERIAL_SYSTEM, "weight", "oz", "oz", "oz", "mass", 1),
(US_CUSTOMARY_SYSTEM, "distance", "m", "m", "m", "distance", 1),
(US_CUSTOMARY_SYSTEM, "distance", "mi", "mi", "mi", "distance", 1),
(US_CUSTOMARY_SYSTEM, "energy", "kWh", "kWh", "kWh", "energy", 1),
(US_CUSTOMARY_SYSTEM, "energy", "Wh", "Wh", "Wh", "energy", 1),
(US_CUSTOMARY_SYSTEM, "gas", "", "", "", "volume", 1),
(US_CUSTOMARY_SYSTEM, "gas", "ft³", "ft³", "ft³", "volume", 1),
(US_CUSTOMARY_SYSTEM, "monetary", "EUR", "EUR", "EUR", None, 1),
(US_CUSTOMARY_SYSTEM, "monetary", "SEK", "SEK", "SEK", None, 1),
(US_CUSTOMARY_SYSTEM, "volume", "", "", "", "volume", 1),
(US_CUSTOMARY_SYSTEM, "volume", "ft³", "ft³", "ft³", "volume", 1),
(US_CUSTOMARY_SYSTEM, "weight", "g", "g", "g", "mass", 1),
(US_CUSTOMARY_SYSTEM, "weight", "oz", "oz", "oz", "mass", 1),
(METRIC_SYSTEM, "distance", "m", "m", "m", "distance", 1),
(METRIC_SYSTEM, "distance", "mi", "mi", "mi", "distance", 1),
(METRIC_SYSTEM, "energy", "kWh", "kWh", "kWh", "energy", 1),
@ -3307,12 +3307,18 @@ def record_states(hass, zero, entity_id, attributes, seq=None):
@pytest.mark.parametrize(
"units, attributes, unit, unit2, supported_unit",
[
(IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
(METRIC_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
(IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, "°F", "K", "K, °C, °F"),
(
US_CUSTOMARY_SYSTEM,
TEMPERATURE_SENSOR_ATTRIBUTES,
"°F",
"K",
"K, °C, °F",
),
(METRIC_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, "°C", "K", "K, °C, °F"),
(
IMPERIAL_SYSTEM,
US_CUSTOMARY_SYSTEM,
PRESSURE_SENSOR_ATTRIBUTES,
"psi",
"bar",
@ -3439,7 +3445,7 @@ async def test_validate_unit_change_convertible(
@pytest.mark.parametrize(
"units, attributes",
[
(IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES),
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES),
],
)
async def test_validate_statistics_unit_ignore_device_class(
@ -3493,12 +3499,18 @@ async def test_validate_statistics_unit_ignore_device_class(
@pytest.mark.parametrize(
"units, attributes, unit, unit2, supported_unit",
[
(IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
(METRIC_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"),
(IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, "°F", "K", "K, °C, °F"),
(
US_CUSTOMARY_SYSTEM,
TEMPERATURE_SENSOR_ATTRIBUTES,
"°F",
"K",
"K, °C, °F",
),
(METRIC_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, "°C", "K", "K, °C, °F"),
(
IMPERIAL_SYSTEM,
US_CUSTOMARY_SYSTEM,
PRESSURE_SENSOR_ATTRIBUTES,
"psi",
"bar",
@ -3625,7 +3637,7 @@ async def test_validate_statistics_unit_change_no_device_class(
@pytest.mark.parametrize(
"units, attributes, unit",
[
(IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
],
)
async def test_validate_statistics_unsupported_state_class(
@ -3689,7 +3701,7 @@ async def test_validate_statistics_unsupported_state_class(
@pytest.mark.parametrize(
"units, attributes, unit",
[
(IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
],
)
async def test_validate_statistics_sensor_no_longer_recorded(
@ -3750,7 +3762,7 @@ async def test_validate_statistics_sensor_no_longer_recorded(
@pytest.mark.parametrize(
"units, attributes, unit",
[
(IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
],
)
async def test_validate_statistics_sensor_not_recorded(
@ -3808,7 +3820,7 @@ async def test_validate_statistics_sensor_not_recorded(
@pytest.mark.parametrize(
"units, attributes, unit",
[
(IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
],
)
async def test_validate_statistics_sensor_removed(