mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Fix consider-using-enumerate warnings in tests (#119506)
This commit is contained in:
parent
fb1b0058ee
commit
4962895f19
@ -51,8 +51,8 @@ MOCK_TELEGRAMS = [
|
|||||||
def assert_telegram_history(telegrams: list[TelegramDict]) -> bool:
|
def assert_telegram_history(telegrams: list[TelegramDict]) -> bool:
|
||||||
"""Assert that the mock telegrams are equal to the given telegrams. Omitting timestamp."""
|
"""Assert that the mock telegrams are equal to the given telegrams. Omitting timestamp."""
|
||||||
assert len(telegrams) == len(MOCK_TELEGRAMS)
|
assert len(telegrams) == len(MOCK_TELEGRAMS)
|
||||||
for index in range(len(telegrams)):
|
for index, value in enumerate(telegrams):
|
||||||
test_telegram = copy(telegrams[index]) # don't modify the original
|
test_telegram = copy(value) # don't modify the original
|
||||||
comp_telegram = MOCK_TELEGRAMS[index]
|
comp_telegram = MOCK_TELEGRAMS[index]
|
||||||
assert datetime.fromisoformat(test_telegram["timestamp"])
|
assert datetime.fromisoformat(test_telegram["timestamp"])
|
||||||
if isinstance(test_telegram["payload"], tuple):
|
if isinstance(test_telegram["payload"], tuple):
|
||||||
|
@ -901,7 +901,7 @@ async def test_virtual_sensor(
|
|||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_do_cycle, expected
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_do_cycle, expected
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Run test for sensor."""
|
"""Run test for sensor."""
|
||||||
for i in range(len(expected)):
|
for i, expected_value in enumerate(expected):
|
||||||
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}".replace(" ", "_")
|
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}".replace(" ", "_")
|
||||||
unique_id = f"{SLAVE_UNIQUE_ID}"
|
unique_id = f"{SLAVE_UNIQUE_ID}"
|
||||||
if i:
|
if i:
|
||||||
@ -909,7 +909,7 @@ async def test_virtual_sensor(
|
|||||||
unique_id = f"{unique_id}_{i}"
|
unique_id = f"{unique_id}_{i}"
|
||||||
entry = entity_registry.async_get(entity_id)
|
entry = entity_registry.async_get(entity_id)
|
||||||
state = hass.states.get(entity_id).state
|
state = hass.states.get(entity_id).state
|
||||||
assert state == expected[i]
|
assert state == expected_value
|
||||||
assert entry.unique_id == unique_id
|
assert entry.unique_id == unique_id
|
||||||
|
|
||||||
|
|
||||||
@ -1071,12 +1071,12 @@ async def test_virtual_swap_sensor(
|
|||||||
hass: HomeAssistant, mock_do_cycle, expected
|
hass: HomeAssistant, mock_do_cycle, expected
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Run test for sensor."""
|
"""Run test for sensor."""
|
||||||
for i in range(len(expected)):
|
for i, expected_value in enumerate(expected):
|
||||||
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}".replace(" ", "_")
|
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}".replace(" ", "_")
|
||||||
if i:
|
if i:
|
||||||
entity_id = f"{entity_id}_{i}"
|
entity_id = f"{entity_id}_{i}"
|
||||||
state = hass.states.get(entity_id).state
|
state = hass.states.get(entity_id).state
|
||||||
assert state == expected[i]
|
assert state == expected_value
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -204,8 +204,8 @@ def test_daily_history_one_day(hass: HomeAssistant) -> None:
|
|||||||
"""Test storing data for the same day."""
|
"""Test storing data for the same day."""
|
||||||
dh = plant.DailyHistory(3)
|
dh = plant.DailyHistory(3)
|
||||||
values = [-2, 10, 0, 5, 20]
|
values = [-2, 10, 0, 5, 20]
|
||||||
for i in range(len(values)):
|
for i, value in enumerate(values):
|
||||||
dh.add_measurement(values[i])
|
dh.add_measurement(value)
|
||||||
max_value = max(values[0 : i + 1])
|
max_value = max(values[0 : i + 1])
|
||||||
assert len(dh._days) == 1
|
assert len(dh._days) == 1
|
||||||
assert dh.max == max_value
|
assert dh.max == max_value
|
||||||
@ -222,6 +222,6 @@ def test_daily_history_multiple_days(hass: HomeAssistant) -> None:
|
|||||||
values = [10, 1, 7, 3]
|
values = [10, 1, 7, 3]
|
||||||
max_values = [10, 10, 10, 7]
|
max_values = [10, 10, 10, 7]
|
||||||
|
|
||||||
for i in range(len(days)):
|
for i, value in enumerate(days):
|
||||||
dh.add_measurement(values[i], days[i])
|
dh.add_measurement(values[i], value)
|
||||||
assert max_values[i] == dh.max
|
assert max_values[i] == dh.max
|
||||||
|
@ -4786,10 +4786,10 @@ async def test_validate_statistics_unit_change_no_conversion(
|
|||||||
with session_scope(hass=hass, read_only=True) as session:
|
with session_scope(hass=hass, read_only=True) as session:
|
||||||
db_states = list(session.query(StatisticsMeta))
|
db_states = list(session.query(StatisticsMeta))
|
||||||
assert len(db_states) == len(expected_result)
|
assert len(db_states) == len(expected_result)
|
||||||
for i in range(len(db_states)):
|
for i, db_state in enumerate(db_states):
|
||||||
assert db_states[i].statistic_id == expected_result[i]["statistic_id"]
|
assert db_state.statistic_id == expected_result[i]["statistic_id"]
|
||||||
assert (
|
assert (
|
||||||
db_states[i].unit_of_measurement
|
db_state.unit_of_measurement
|
||||||
== expected_result[i]["unit_of_measurement"]
|
== expected_result[i]["unit_of_measurement"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -4920,10 +4920,10 @@ async def test_validate_statistics_unit_change_equivalent_units(
|
|||||||
with session_scope(hass=hass, read_only=True) as session:
|
with session_scope(hass=hass, read_only=True) as session:
|
||||||
db_states = list(session.query(StatisticsMeta))
|
db_states = list(session.query(StatisticsMeta))
|
||||||
assert len(db_states) == len(expected_result)
|
assert len(db_states) == len(expected_result)
|
||||||
for i in range(len(db_states)):
|
for i, db_state in enumerate(db_states):
|
||||||
assert db_states[i].statistic_id == expected_result[i]["statistic_id"]
|
assert db_state.statistic_id == expected_result[i]["statistic_id"]
|
||||||
assert (
|
assert (
|
||||||
db_states[i].unit_of_measurement
|
db_state.unit_of_measurement
|
||||||
== expected_result[i]["unit_of_measurement"]
|
== expected_result[i]["unit_of_measurement"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -5005,10 +5005,10 @@ async def test_validate_statistics_unit_change_equivalent_units_2(
|
|||||||
with session_scope(hass=hass, read_only=True) as session:
|
with session_scope(hass=hass, read_only=True) as session:
|
||||||
db_states = list(session.query(StatisticsMeta))
|
db_states = list(session.query(StatisticsMeta))
|
||||||
assert len(db_states) == len(expected_result)
|
assert len(db_states) == len(expected_result)
|
||||||
for i in range(len(db_states)):
|
for i, db_state in enumerate(db_states):
|
||||||
assert db_states[i].statistic_id == expected_result[i]["statistic_id"]
|
assert db_state.statistic_id == expected_result[i]["statistic_id"]
|
||||||
assert (
|
assert (
|
||||||
db_states[i].unit_of_measurement
|
db_state.unit_of_measurement
|
||||||
== expected_result[i]["unit_of_measurement"]
|
== expected_result[i]["unit_of_measurement"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1314,13 +1314,13 @@ async def test_state_characteristics(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
# With all values in buffer
|
# With all values in buffer
|
||||||
|
|
||||||
for i in range(len(VALUES_NUMERIC)):
|
for i, value in enumerate(VALUES_NUMERIC):
|
||||||
current_time += timedelta(minutes=1)
|
current_time += timedelta(minutes=1)
|
||||||
freezer.move_to(current_time)
|
freezer.move_to(current_time)
|
||||||
async_fire_time_changed(hass, current_time)
|
async_fire_time_changed(hass, current_time)
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
"sensor.test_monitored",
|
"sensor.test_monitored",
|
||||||
str(VALUES_NUMERIC[i]),
|
str(value),
|
||||||
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
{ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS},
|
||||||
)
|
)
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user