Skip to content

Commit c7df6c0

Browse files
committed
Try alternative test-method
1 parent 04c021f commit c7df6c0

1 file changed

Lines changed: 41 additions & 19 deletions

File tree

tests/components/plugwise/test_init.py

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from freezegun.api import FrozenDateTimeFactory
1717
from homeassistant.components.plugwise.const import DOMAIN
18-
from homeassistant.components.plugwise.coordinator import PlugwiseDataUpdateCoordinator
1918
from homeassistant.config_entries import ConfigEntryState
2019
from homeassistant.const import (
2120
CONF_HOST,
@@ -27,9 +26,11 @@
2726
Platform,
2827
)
2928
from homeassistant.core import HomeAssistant
30-
from homeassistant.exceptions import ConfigEntryError
29+
30+
# from homeassistant.exceptions import ConfigEntryError
3131
from homeassistant.helpers import device_registry as dr, entity_registry as er
32-
from homeassistant.helpers.update_coordinator import UpdateFailed
32+
33+
# from homeassistant.helpers.update_coordinator import UpdateFailed
3334
from homeassistant.setup import async_setup_component
3435

3536
from tests.common import MockConfigEntry, async_fire_time_changed
@@ -118,32 +119,53 @@ async def test_gateway_config_entry_not_ready(
118119
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
119120
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
120121
@pytest.mark.parametrize(
121-
("side_effect", "expected_raise"),
122+
"side_effect",
122123
[
123-
(ConnectionFailedError, UpdateFailed),
124-
(InvalidAuthentication, ConfigEntryError),
125-
(InvalidSetupError, ConfigEntryError),
126-
(InvalidXMLError, UpdateFailed),
127-
(ResponseError, UpdateFailed),
128-
(UnsupportedDeviceError, ConfigEntryError),
124+
ConnectionFailedError,
125+
InvalidXMLError,
126+
ResponseError,
129127
],
130128
)
131-
async def test_coordinator_connect_exceptions(
129+
async def test_coordinator_connect_exceptions_1(
132130
hass: HomeAssistant,
133131
mock_config_entry: MockConfigEntry,
134132
mock_smile_anna: MagicMock,
135133
side_effect: Exception,
136-
expected_raise: Exception,
137134
) -> None:
138135
"""Ensure _connect raises translated errors."""
139136
mock_smile_anna.connect.side_effect = side_effect
140-
coordinator = PlugwiseDataUpdateCoordinator(
141-
hass,
142-
cooldown=0,
143-
config_entry=mock_config_entry,
144-
)
145-
with pytest.raises(expected_raise):
146-
await coordinator._connect()
137+
138+
mock_config_entry.add_to_hass(hass)
139+
await hass.config_entries.async_setup(mock_config_entry.entry_id)
140+
await hass.async_block_till_done()
141+
142+
assert len(mock_smile_anna.connect.mock_calls) == 1
143+
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
144+
145+
146+
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
147+
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
148+
@pytest.mark.parametrize(
149+
("side_effect", "raise_match"),
150+
[
151+
(InvalidAuthentication, "Invalid authentication"),
152+
(InvalidSetupError, "invalid_setup"),
153+
(UnsupportedDeviceError, "Device with unsupported firmware"),
154+
],
155+
)
156+
async def test_coordinator_connect_exceptions_2(
157+
hass: HomeAssistant,
158+
mock_config_entry: MockConfigEntry,
159+
mock_smile_anna: MagicMock,
160+
side_effect: Exception,
161+
raise_match: str,
162+
) -> None:
163+
"""Ensure _connect raises translated errors."""
164+
mock_smile_anna.connect.side_effect = side_effect
165+
166+
mock_config_entry.add_to_hass(hass)
167+
with pytest.raises(side_effect, match=raise_match):
168+
await hass.config_entries.async_setup(mock_config_entry.entry_id)
147169

148170

149171
@pytest.mark.parametrize("chosen_env", ["p1v4_442_single"], indirect=True)

0 commit comments

Comments
 (0)