From f803c541f420aa7d23e11308b62cba389298e128 Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Sat, 16 Mar 2024 09:04:04 -0500 Subject: [PATCH] Somre reorg --- tests/common.py | 8 ++ tests/conftest.py | 13 ++- tests/test_binary_sensor.py | 58 ++++++++----- tests/test_config_flow.py | 28 ++++-- tests/test_init.py | 168 ++++++++++++++++++------------------ 5 files changed, 160 insertions(+), 115 deletions(-) create mode 100644 tests/common.py diff --git a/tests/common.py b/tests/common.py new file mode 100644 index 0000000..f46b002 --- /dev/null +++ b/tests/common.py @@ -0,0 +1,8 @@ +"""Sun2 test common functions, etc.""" +from __future__ import annotations + +from collections.abc import Callable +from datetime import datetime, tzinfo +from unittest.mock import MagicMock + +DtNowMock = tuple[Callable[[tzinfo | None], datetime], MagicMock] diff --git a/tests/conftest.py b/tests/conftest.py index d4e6d59..06ba975 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,9 @@ """Sun2 test configuration.""" from __future__ import annotations -from collections.abc import AsyncGenerator +from collections.abc import AsyncGenerator, Generator import logging +from unittest.mock import patch from custom_components.sun2.const import DOMAIN import pytest @@ -10,6 +11,8 @@ from homeassistant.const import MAJOR_VERSION, MINOR_VERSION from homeassistant.core import HomeAssistant +from homeassistant.util import dt as dt_util +from tests.common import DtNowMock pytest_plugins = ["pytest_homeassistant_custom_component"] @@ -71,6 +74,14 @@ async def test_abc() -> None: await hass.config_entries.async_unload(entry.entry_id) +@pytest.fixture +def dt_now() -> Generator[DtNowMock, None, None]: + """Mock util.dt.now.""" + real = dt_util.now + with patch("homeassistant.util.dt.now") as mock: + yield real, mock + + # @pytest.fixture # def mock_setup_and_unload() -> Generator[tuple[AsyncMock, AsyncMock], None, None]: # """Mock async_setup_entry & async_unload_entry.""" diff --git a/tests/test_binary_sensor.py b/tests/test_binary_sensor.py index 2b4b814..34cf6be 100644 --- a/tests/test_binary_sensor.py +++ b/tests/test_binary_sensor.py @@ -2,7 +2,6 @@ from __future__ import annotations from datetime import date, datetime, time, timedelta -from unittest.mock import patch from astral import LocationInfo from astral.location import Location @@ -19,9 +18,15 @@ from homeassistant.helpers.entity_registry import EntityRegistry from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util, slugify +from tests.common import DtNowMock from .const import NY_CONFIG +# ========== Fixtures ================================================================== + + +# ========== Tests ===================================================================== + @pytest.mark.parametrize( "elevation,name,slug", @@ -35,11 +40,14 @@ async def test_yaml_binary_sensor( hass: HomeAssistant, entity_registry: EntityRegistry, + dt_now: DtNowMock, elevation: str | float, name: str | None, slug: str, ) -> None: """Test YAML configured elevation binary sensor.""" + dt_now_real, dt_now_mock = dt_now + config = NY_CONFIG | { "binary_sensors": [ { @@ -52,15 +60,15 @@ async def test_yaml_binary_sensor( config["binary_sensors"][0]["name"] = name tz = dt_util.get_time_zone(NY_CONFIG["time_zone"]) - base_time = dt_util.now(tz) + base_time = dt_now_real(tz) # Set time to 00:00:00 tommorow. now = datetime.combine((base_time + timedelta(1)).date(), time()).replace(tzinfo=tz) - with patch("homeassistant.util.dt.now", return_value=now): - with assert_setup_component(1, DOMAIN): - await async_setup_component(hass, DOMAIN, {DOMAIN: [config]}) - await hass.async_block_till_done() + dt_now_mock.return_value = now + with assert_setup_component(1, DOMAIN): + await async_setup_component(hass, DOMAIN, {DOMAIN: [config]}) + await hass.async_block_till_done() config_entry = hass.config_entries.async_entries(DOMAIN)[0] @@ -83,9 +91,9 @@ async def test_yaml_binary_sensor( assert now < next_change < noon # Move time to next_change and make sure state has changed. - with patch("homeassistant.util.dt.now", return_value=next_change): - async_fire_time_changed(hass, next_change) - await hass.async_block_till_done() + dt_now_mock.return_value = next_change + async_fire_time_changed(hass, next_change) + await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.state == STATE_ON @@ -105,11 +113,14 @@ async def test_yaml_binary_sensor( async def test_always_on_or_off( hass: HomeAssistant, entity_registry: EntityRegistry, + dt_now: DtNowMock, caplog: LogCaptureFixture, elevation: float, expected_state: str, ) -> None: """Test a binary sensor that is always on or off.""" + dt_now_real, dt_now_mock = dt_now + config = NY_CONFIG | { "binary_sensors": [ { @@ -120,15 +131,15 @@ async def test_always_on_or_off( } tz = dt_util.get_time_zone(NY_CONFIG["time_zone"]) - base_time = dt_util.now(tz) + base_time = dt_now_real(tz) # Set time to 00:00:00 tommorow. now = datetime.combine((base_time + timedelta(1)).date(), time()).replace(tzinfo=tz) - with patch("homeassistant.util.dt.now", return_value=now): - with assert_setup_component(1, DOMAIN): - await async_setup_component(hass, DOMAIN, {DOMAIN: [config]}) - await hass.async_block_till_done() + dt_now_mock.return_value = now + with assert_setup_component(1, DOMAIN): + await async_setup_component(hass, DOMAIN, {DOMAIN: [config]}) + await hass.async_block_till_done() config_entry = hass.config_entries.async_entries(DOMAIN)[0] entity_id = entity_registry.async_get_entity_id( @@ -150,9 +161,9 @@ async def test_always_on_or_off( # Move time to noon. noon = now.replace(hour=12) - with patch("homeassistant.util.dt.now", return_value=noon): - async_fire_time_changed(hass, noon) - await hass.async_block_till_done() + dt_now_mock.return_value = noon + async_fire_time_changed(hass, noon) + await hass.async_block_till_done() # Check that state is still the same. state = hass.states.get(entity_id) @@ -167,12 +178,15 @@ async def test_always_on_or_off( async def test_next_change_greater_than_one_day( hass: HomeAssistant, entity_registry: EntityRegistry, + dt_now: DtNowMock, caplog: LogCaptureFixture, func: str, offset: int, expected_state: str, ) -> None: """Test when binary sensor won't change for more than one day.""" + dt_now_real, dt_now_mock = dt_now + config = NY_CONFIG | { "binary_sensors": [ { @@ -190,7 +204,7 @@ async def test_next_change_greater_than_one_day( # Get next year's September 20, since on this date neither the min nor max elevation # is near their extremes in New York, NY. Then get the min or max sun elevations. - now_date = date(dt_util.now().year + 1, 9, 20) + now_date = date(dt_now_real(tz).year + 1, 9, 20) elv = loc.solar_elevation(getattr(loc, func)(now_date), obs_elv) # Configure sensor with an elevation threshold just below or above. @@ -199,10 +213,10 @@ async def test_next_change_greater_than_one_day( # Set time to midnight on that date. now = datetime.combine(now_date, time()).replace(tzinfo=tz) - with patch("homeassistant.util.dt.now", return_value=now): - with assert_setup_component(1, DOMAIN): - await async_setup_component(hass, DOMAIN, {DOMAIN: [config]}) - await hass.async_block_till_done() + dt_now_mock.return_value = now + with assert_setup_component(1, DOMAIN): + await async_setup_component(hass, DOMAIN, {DOMAIN: [config]}) + await hass.async_block_till_done() config_entry = hass.config_entries.async_entries(DOMAIN)[0] entity_id = entity_registry.async_get_entity_id( diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index deaa3f6..ca98fdf 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -1,9 +1,10 @@ """Test config flow module.""" from __future__ import annotations +from collections.abc import Generator import logging from typing import Any -from unittest.mock import patch +from unittest.mock import AsyncMock, patch from custom_components.sun2.const import DOMAIN import pytest @@ -17,18 +18,25 @@ _LOGGER = logging.getLogger(__name__) +# ========== Fixtures ================================================================== + + +@pytest.fixture +def reload_mock(hass: HomeAssistant) -> Generator[AsyncMock, None, None]: + """Mock config_entries.async_reload.""" + with patch.object(hass.config_entries, "async_reload") as mock: + yield mock + # ========== Import Flow Tests ========================================================= -async def test_import_min_new(hass: HomeAssistant): +async def test_import_min_new(hass: HomeAssistant, reload_mock: AsyncMock): """Test minimum YAML config with new location.""" - - with patch.object(hass.config_entries, "async_reload") as reload_mock: - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=HOME_CONFIG.copy() - ) - await hass.async_block_till_done() + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_IMPORT}, data=HOME_CONFIG.copy() + ) + await hass.async_block_till_done() assert result["type"] == FlowResultType.CREATE_ENTRY config_entry: ConfigEntry = result["result"] @@ -37,6 +45,7 @@ async def test_import_min_new(hass: HomeAssistant): assert config_entry.data == {} assert config_entry.options == {} assert config_entry.unique_id == HOME_CONFIG["unique_id"] + reload_mock.assert_not_called reload_mock.assert_not_awaited @@ -71,4 +80,7 @@ async def test_import_min_old( assert changed ^ (config_entry.as_dict() == old_values) # When config changes, entry_updated will take care of reloading it. But when config # does not change, config flow will make sure it gets reloaded. + assert changed ^ (reload_mock.call_count == 1) assert changed ^ (reload_mock.await_count == 1) + if reload_mock.call_count == 1: + reload_mock.assert_called_with(config_entry.entry_id) diff --git a/tests/test_init.py b/tests/test_init.py index aaa6502..57d1b3a 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -28,7 +28,7 @@ @pytest.fixture -def mock_setup_entry() -> Generator[AsyncMock, None, None]: +def setup_entry_mock() -> Generator[AsyncMock, None, None]: """Mock async_setup_entry.""" with patch("custom_components.sun2.async_setup_entry", autospec=True) as mock: mock.return_value = True @@ -36,7 +36,7 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]: @pytest.fixture -def mock_unload_entry() -> Generator[AsyncMock, None, None]: +def unload_entry_mock() -> Generator[AsyncMock, None, None]: """Mock async_setup_entry.""" with patch("custom_components.sun2.async_unload_entry", autospec=True) as mock: mock.return_value = True @@ -44,7 +44,7 @@ def mock_unload_entry() -> Generator[AsyncMock, None, None]: @pytest.fixture -def mock_yaml_load(hass: HomeAssistant) -> Generator[AsyncMock, None, None]: +def yaml_load_mock(hass: HomeAssistant) -> Generator[AsyncMock, None, None]: """Mock async_integration_yaml_config.""" with patch( "custom_components.sun2.async_integration_yaml_config", autospec=True @@ -53,7 +53,7 @@ def mock_yaml_load(hass: HomeAssistant) -> Generator[AsyncMock, None, None]: @pytest.fixture -def mock_dispatch_listener(hass: HomeAssistant) -> AsyncMock: +def dispatch_listener_mock(hass: HomeAssistant) -> AsyncMock: """Mock SIG_HA_LOC_UPDATED listener.""" mock = AsyncMock() async_dispatcher_connect(hass, SIG_HA_LOC_UPDATED, mock) @@ -61,7 +61,7 @@ def mock_dispatch_listener(hass: HomeAssistant) -> AsyncMock: @pytest.fixture -def mock_fwd_entry_setup(hass: HomeAssistant) -> Generator[AsyncMock, None, None]: +def fwd_entry_setups_mock(hass: HomeAssistant) -> Generator[AsyncMock, None, None]: """Mock config_entries.async_reload.""" with patch.object( hass.config_entries, "async_forward_entry_setups", autospec=True @@ -72,10 +72,10 @@ def mock_fwd_entry_setup(hass: HomeAssistant) -> Generator[AsyncMock, None, None @pytest.fixture async def basic_setup( hass: HomeAssistant, - mock_setup_entry: AsyncMock, - mock_unload_entry: AsyncMock, - mock_yaml_load: AsyncMock, - mock_dispatch_listener: AsyncMock, + setup_entry_mock: AsyncMock, + unload_entry_mock: AsyncMock, + yaml_load_mock: AsyncMock, + dispatch_listener_mock: AsyncMock, ) -> tuple[MockConfigEntry, MockConfigEntry, MockConfigEntry]: """Set up integration with existing config entries. @@ -100,11 +100,11 @@ async def basic_setup( await async_setup_component(hass, DOMAIN, {DOMAIN: [TWINE_CONFIG]}) await hass.async_block_till_done() - mock_setup_entry.reset_mock() - mock_unload_entry.reset_mock() - mock_yaml_load.reset_mock() - mock_dispatch_listener.reset_mock() - mock_yaml_load.return_value = {DOMAIN: [TWINE_CONFIG]} + setup_entry_mock.reset_mock() + unload_entry_mock.reset_mock() + yaml_load_mock.reset_mock() + dispatch_listener_mock.reset_mock() + yaml_load_mock.return_value = {DOMAIN: [TWINE_CONFIG]} for config_entry in hass.config_entries.async_entries(DOMAIN): if config_entry.source == SOURCE_IMPORT: @@ -118,7 +118,7 @@ async def basic_setup( async def test_setup_no_config( - hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_unload_entry: AsyncMock + hass: HomeAssistant, setup_entry_mock: AsyncMock, unload_entry_mock: AsyncMock ) -> None: """Test setup with no config.""" with assert_setup_component(0, DOMAIN): @@ -126,15 +126,15 @@ async def test_setup_no_config( await hass.async_block_till_done() assert hass.services.has_service(DOMAIN, "reload") - assert not mock_setup_entry.called - assert not mock_unload_entry.called + assert not setup_entry_mock.called + assert not unload_entry_mock.called # ========== async_setup Tests: YAML Config ============================================ async def test_setup_yaml_config_new( - hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_unload_entry: AsyncMock + hass: HomeAssistant, setup_entry_mock: AsyncMock, unload_entry_mock: AsyncMock ) -> None: """Test setup with new YAML configs.""" with assert_setup_component(2, DOMAIN): @@ -149,16 +149,16 @@ async def test_setup_yaml_config_new( assert config_entries[0] != config_entries[1] unique_ids = {config_entry.unique_id for config_entry in config_entries} assert unique_ids == {HOME_CONFIG["unique_id"], NY_CONFIG["unique_id"]} - mock_setup_entry.call_count == 2 - mock_setup_entry.await_count == 2 + setup_entry_mock.call_count == 2 + setup_entry_mock.await_count == 2 for config_entry in config_entries: assert config_entry.source == SOURCE_IMPORT - mock_setup_entry.assert_any_call(hass, config_entry) - assert not mock_unload_entry.called + setup_entry_mock.assert_any_call(hass, config_entry) + assert not unload_entry_mock.called async def test_setup_yaml_config_changed( - hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_unload_entry: AsyncMock + hass: HomeAssistant, setup_entry_mock: AsyncMock, unload_entry_mock: AsyncMock ) -> None: """Test setup with a changed YAML config.""" # Create and register an existing YAML config entry and save its values. @@ -186,12 +186,12 @@ async def test_setup_yaml_config_changed( assert config_entries[0] is config_entry assert config_entry.unique_id == old_values["unique_id"] assert config_entry.as_dict() != old_values - mock_setup_entry.assert_called_once_with(hass, config_entry) - assert not mock_unload_entry.called + setup_entry_mock.assert_called_once_with(hass, config_entry) + assert not unload_entry_mock.called async def test_setup_yaml_config_removed( - hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_unload_entry: AsyncMock + hass: HomeAssistant, setup_entry_mock: AsyncMock, unload_entry_mock: AsyncMock ) -> None: """Test setup with a removed YAML config.""" # Create and register an existing YAML config entry. @@ -210,55 +210,55 @@ async def test_setup_yaml_config_removed( # Check that the config entry is gone. config_entries = hass.config_entries.async_entries(DOMAIN) assert len(config_entries) == 0 - assert not mock_setup_entry.called - assert not mock_unload_entry.called + assert not setup_entry_mock.called + assert not unload_entry_mock.called async def test_setup_yaml_config_reload_same( hass: HomeAssistant, - mock_setup_entry: AsyncMock, - mock_unload_entry: AsyncMock, - mock_yaml_load: AsyncMock, + setup_entry_mock: AsyncMock, + unload_entry_mock: AsyncMock, + yaml_load_mock: AsyncMock, ) -> None: """Test reloading same YAML config.""" with assert_setup_component(1, DOMAIN): await async_setup_component(hass, DOMAIN, {DOMAIN: [HOME_CONFIG]}) await hass.async_block_till_done() - mock_setup_entry.reset_mock() - mock_unload_entry.reset_mock() - mock_yaml_load.reset_mock() + setup_entry_mock.reset_mock() + unload_entry_mock.reset_mock() + yaml_load_mock.reset_mock() config_entry = hass.config_entries.async_entries(DOMAIN)[0] # Call reload service with same config. - mock_yaml_load.return_value = {DOMAIN: [HOME_CONFIG]} + yaml_load_mock.return_value = {DOMAIN: [HOME_CONFIG]} await hass.services.async_call(DOMAIN, "reload") await hass.async_block_till_done() # With no change, config flow will directly reload config, so both # async_unload_entry and async_setup_entry should be called. - mock_unload_entry.assert_called_once_with(hass, config_entry) - mock_unload_entry.assert_awaited_once() - mock_setup_entry.assert_called_once_with(hass, config_entry) - mock_setup_entry.assert_awaited_once() + unload_entry_mock.assert_called_once_with(hass, config_entry) + unload_entry_mock.assert_awaited_once() + setup_entry_mock.assert_called_once_with(hass, config_entry) + setup_entry_mock.assert_awaited_once() async def test_setup_yaml_config_reload_diff( hass: HomeAssistant, - mock_setup_entry: AsyncMock, - mock_unload_entry: AsyncMock, - mock_yaml_load: AsyncMock, + setup_entry_mock: AsyncMock, + unload_entry_mock: AsyncMock, + yaml_load_mock: AsyncMock, ) -> None: """Test reloading a different YAML config.""" with assert_setup_component(1, DOMAIN): await async_setup_component(hass, DOMAIN, {DOMAIN: [HOME_CONFIG]}) await hass.async_block_till_done() - mock_setup_entry.reset_mock() - mock_unload_entry.reset_mock() - mock_yaml_load.reset_mock() + setup_entry_mock.reset_mock() + unload_entry_mock.reset_mock() + yaml_load_mock.reset_mock() # Call reload service with a changed config, keeping unique_id the same. new_config = NY_CONFIG | {"unique_id": HOME_CONFIG["unique_id"]} - mock_yaml_load.return_value = {DOMAIN: [new_config]} + yaml_load_mock.return_value = {DOMAIN: [new_config]} await hass.services.async_call(DOMAIN, "reload") await hass.async_block_till_done() @@ -266,15 +266,15 @@ async def test_setup_yaml_config_reload_diff( # async_unload_entry nor async_setup_entry should be called. (Normally, # async_setup_entry would have set up a listener for changed configs, and that # listener would reload the config.) - assert not mock_setup_entry.called - assert not mock_unload_entry.called + assert not setup_entry_mock.called + assert not unload_entry_mock.called # ========== async_setup Tests: UI Config ============================================== async def test_setup_ui_config( - hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_unload_entry: AsyncMock + hass: HomeAssistant, setup_entry_mock: AsyncMock, unload_entry_mock: AsyncMock ) -> None: """Test setup with a changed YAML config.""" # Create and register an existing UI config entry and save its values. @@ -292,9 +292,9 @@ async def test_setup_ui_config( # Check that UI config entry hasn't changed and was setup. assert config_entry.as_dict() == old_values - mock_setup_entry.assert_called_once_with(hass, config_entry) - mock_setup_entry.assert_awaited_once() - assert not mock_unload_entry.called + setup_entry_mock.assert_called_once_with(hass, config_entry) + setup_entry_mock.assert_awaited_once() + assert not unload_entry_mock.called # ========== async_setup Tests: HA Config Updated ====================================== @@ -302,9 +302,9 @@ async def test_setup_ui_config( async def test_setup_ha_config_updated_no_data( hass: HomeAssistant, - mock_setup_entry: AsyncMock, - mock_unload_entry: AsyncMock, - mock_dispatch_listener: AsyncMock, + setup_entry_mock: AsyncMock, + unload_entry_mock: AsyncMock, + dispatch_listener_mock: AsyncMock, basic_setup: tuple[MockConfigEntry, MockConfigEntry, MockConfigEntry], ) -> None: """Test EVENT_CORE_CONFIG_UPDATE with no data.""" @@ -312,16 +312,16 @@ async def test_setup_ha_config_updated_no_data( await hass.async_block_till_done() # Check that none of the monitored functions have been called. - assert mock_setup_entry.call_count == 0 - assert mock_unload_entry.call_count == 0 - assert mock_dispatch_listener.call_count == 0 + assert setup_entry_mock.call_count == 0 + assert unload_entry_mock.call_count == 0 + assert dispatch_listener_mock.call_count == 0 async def test_setup_ha_config_updated_loc_only( hass: HomeAssistant, - mock_setup_entry: AsyncMock, - mock_unload_entry: AsyncMock, - mock_dispatch_listener: AsyncMock, + setup_entry_mock: AsyncMock, + unload_entry_mock: AsyncMock, + dispatch_listener_mock: AsyncMock, basic_setup: tuple[MockConfigEntry, MockConfigEntry, MockConfigEntry], ) -> None: """Test EVENT_CORE_CONFIG_UPDATE w/ location data only.""" @@ -329,9 +329,9 @@ async def test_setup_ha_config_updated_loc_only( await hass.async_block_till_done() # Check that only the dispatch listener was called. - assert mock_setup_entry.call_count == 0 - assert mock_unload_entry.call_count == 0 - mock_dispatch_listener.assert_called_once_with( + assert setup_entry_mock.call_count == 0 + assert unload_entry_mock.call_count == 0 + dispatch_listener_mock.assert_called_once_with( LocData( LocParams( hass.config.elevation, @@ -341,15 +341,15 @@ async def test_setup_ha_config_updated_loc_only( ) ) ) - mock_dispatch_listener.assert_awaited_once() + dispatch_listener_mock.assert_awaited_once() async def test_setup_ha_config_updated_name( hass: HomeAssistant, - mock_setup_entry: AsyncMock, - mock_unload_entry: AsyncMock, - mock_yaml_load: AsyncMock, - mock_dispatch_listener: AsyncMock, + setup_entry_mock: AsyncMock, + unload_entry_mock: AsyncMock, + yaml_load_mock: AsyncMock, + dispatch_listener_mock: AsyncMock, basic_setup: tuple[MockConfigEntry, MockConfigEntry, MockConfigEntry], ) -> None: """Test EVENT_CORE_CONFIG_UPDATE w/ name changed.""" @@ -364,17 +364,17 @@ async def test_setup_ha_config_updated_name( # Check that UI NY & YAML configs were reloaded, YAML was loaded, and dispatch # listener was not called. - assert mock_setup_entry.call_count == 2 - assert mock_setup_entry.await_count == 2 - assert mock_unload_entry.call_count == 2 - assert mock_unload_entry.await_count == 2 + assert setup_entry_mock.call_count == 2 + assert setup_entry_mock.await_count == 2 + assert unload_entry_mock.call_count == 2 + assert unload_entry_mock.await_count == 2 calls = [call(hass, ui_ny_entry), call(hass, yaml_twine_entry)] - for a_call in mock_setup_entry.call_args_list: + for a_call in setup_entry_mock.call_args_list: assert a_call in calls - for a_call in mock_unload_entry.call_args_list: + for a_call in unload_entry_mock.call_args_list: assert a_call in calls - mock_yaml_load.assert_called_once() - assert mock_dispatch_listener.call_count == 0 + yaml_load_mock.assert_called_once() + assert dispatch_listener_mock.call_count == 0 # Check that only the UI Home entry has changed, and only its title. assert ui_home_entry.as_dict() == ui_home_values | {"title": new_home_name} @@ -388,8 +388,8 @@ async def test_setup_ha_config_updated_name( async def test_entry_updated( hass: HomeAssistant, entity_registry: EntityRegistry, - mock_unload_entry: AsyncMock, - mock_fwd_entry_setup: AsyncMock, + unload_entry_mock: AsyncMock, + fwd_entry_setups_mock: AsyncMock, ) -> None: """Test entry_updated.""" @@ -426,14 +426,14 @@ def create_options(uid: Callable[[int], str]) -> dict[str, Any]: yaml_ny_entry = config_entry break - assert mock_fwd_entry_setup.call_count == 2 - assert mock_fwd_entry_setup.await_count == 2 + assert fwd_entry_setups_mock.call_count == 2 + assert fwd_entry_setups_mock.await_count == 2 calls = [call(ui_home_entry, PLATFORMS), call(yaml_ny_entry, PLATFORMS)] - for a_call in mock_fwd_entry_setup.call_args_list: + for a_call in fwd_entry_setups_mock.call_args_list: assert a_call in calls - mock_unload_entry.reset_mock() - mock_fwd_entry_setup.reset_mock() + unload_entry_mock.reset_mock() + fwd_entry_setups_mock.reset_mock() # Config entries are now loaded, but entities have not been created due to test # patching, and therefore, entities have not been added to entity registry. Do that