From b1e3e629cd0349969c4e4e4d997af89b5e90563e Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 1 Jan 2025 23:11:19 -0800 Subject: [PATCH 1/4] Fix `test_changing_options_when_using_yaml` (broke after #1141) --- tests/test_config_flow.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index af01fc11..a66c8c16 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -1,5 +1,9 @@ """Test Adaptive Lighting config flow.""" +from collections.abc import Generator +from unittest.mock import AsyncMock, patch + +import pytest from homeassistant.components.adaptive_lighting.const import ( CONF_SUNRISE_TIME, CONF_SUNSET_TIME, @@ -114,10 +118,24 @@ async def test_import_twice(hass): ) +@pytest.fixture +def mock_config_entries_async_forward_entry_setup() -> Generator[AsyncMock]: + """Mock async_forward_entry_setup.""" + with patch( + "homeassistant.config_entries.ConfigEntries.async_forward_entry_setups", + ) as mock_fn: + yield mock_fn + + # TODO: Fix, broken for all supported versions # But in ≤2024.5 it gives homeassistant.config_entries.UnknownEntry: cd69dbda65bd3f86e9a32d974cdfa23f # and ≥2024.6 it times out -async def test_changing_options_when_using_yaml(hass): + + +async def test_changing_options_when_using_yaml( + hass, + mock_config_entries_async_forward_entry_setup, +): """Test changing options when using YAML.""" entry = MockConfigEntry( domain=DOMAIN, From cf85e91b293634341acb6e5e56205e1d0fbf37bc Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 1 Jan 2025 23:14:30 -0800 Subject: [PATCH 2/4] change order --- tests/test_config_flow.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index a66c8c16..b8beb309 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -127,11 +127,6 @@ def mock_config_entries_async_forward_entry_setup() -> Generator[AsyncMock]: yield mock_fn -# TODO: Fix, broken for all supported versions -# But in ≤2024.5 it gives homeassistant.config_entries.UnknownEntry: cd69dbda65bd3f86e9a32d974cdfa23f -# and ≥2024.6 it times out - - async def test_changing_options_when_using_yaml( hass, mock_config_entries_async_forward_entry_setup, @@ -146,8 +141,8 @@ async def test_changing_options_when_using_yaml( ) entry.add_to_hass(hass) - await hass.block_till_done() await hass.config_entries.async_setup(entry.entry_id) + await hass.block_till_done() result = await hass.config_entries.options.async_init(entry.entry_id) result = await hass.config_entries.options.async_configure( From 728679e0122ea183da5036868b3f3127bb4d5733 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 1 Jan 2025 23:21:48 -0800 Subject: [PATCH 3/4] Patch differently --- tests/test_config_flow.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index b8beb309..63b26cfc 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -1,9 +1,7 @@ """Test Adaptive Lighting config flow.""" -from collections.abc import Generator -from unittest.mock import AsyncMock, patch +from unittest.mock import patch -import pytest from homeassistant.components.adaptive_lighting.const import ( CONF_SUNRISE_TIME, CONF_SUNSET_TIME, @@ -118,18 +116,8 @@ async def test_import_twice(hass): ) -@pytest.fixture -def mock_config_entries_async_forward_entry_setup() -> Generator[AsyncMock]: - """Mock async_forward_entry_setup.""" - with patch( - "homeassistant.config_entries.ConfigEntries.async_forward_entry_setups", - ) as mock_fn: - yield mock_fn - - async def test_changing_options_when_using_yaml( hass, - mock_config_entries_async_forward_entry_setup, ): """Test changing options when using YAML.""" entry = MockConfigEntry( @@ -140,9 +128,9 @@ async def test_changing_options_when_using_yaml( options={}, ) entry.add_to_hass(hass) - - await hass.config_entries.async_setup(entry.entry_id) - await hass.block_till_done() + with patch.object(hass.config_entries, "async_forward_entry_setups"): + await hass.config_entries.async_setup(entry.entry_id) + await hass.block_till_done() result = await hass.config_entries.options.async_init(entry.entry_id) result = await hass.config_entries.options.async_configure( From 3326bb2076fa88a47c558ec42eca3384081af4ca Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 1 Jan 2025 23:23:17 -0800 Subject: [PATCH 4/4] style --- tests/test_config_flow.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 63b26cfc..17e68994 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -116,9 +116,7 @@ async def test_import_twice(hass): ) -async def test_changing_options_when_using_yaml( - hass, -): +async def test_changing_options_when_using_yaml(hass): """Test changing options when using YAML.""" entry = MockConfigEntry( domain=DOMAIN,