Fix mock assert_called_with (#96929)
* Fix mock assert_called_with * Fix sonos test * Revert zeroconf test changespull/96537/head
parent
822d840f81
commit
23810752ed
|
@ -273,7 +273,7 @@ async def test_error_event_type(
|
|||
)
|
||||
)
|
||||
|
||||
assert voice_assistant_udp_server_v1.handle_event.called_with(
|
||||
voice_assistant_udp_server_v1.handle_event.assert_called_with(
|
||||
VoiceAssistantEventType.VOICE_ASSISTANT_ERROR,
|
||||
{"code": "code", "message": "message"},
|
||||
)
|
||||
|
|
|
@ -107,6 +107,9 @@ def config_entry_fixture():
|
|||
class MockSoCo(MagicMock):
|
||||
"""Mock the Soco Object."""
|
||||
|
||||
audio_delay = 2
|
||||
sub_gain = 5
|
||||
|
||||
@property
|
||||
def visible_zones(self):
|
||||
"""Return visible zones and allow property to be overridden by device classes."""
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Tests for the Sonos number platform."""
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import PropertyMock, patch
|
||||
|
||||
from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN, SERVICE_SET_VALUE
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
|
@ -37,24 +37,28 @@ async def test_number_entities(
|
|||
music_surround_level_state = hass.states.get(music_surround_level_number.entity_id)
|
||||
assert music_surround_level_state.state == "4"
|
||||
|
||||
with patch("soco.SoCo.audio_delay") as mock_audio_delay:
|
||||
with patch.object(
|
||||
type(soco), "audio_delay", new_callable=PropertyMock
|
||||
) as mock_audio_delay:
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
{ATTR_ENTITY_ID: audio_delay_number.entity_id, "value": 3},
|
||||
blocking=True,
|
||||
)
|
||||
assert mock_audio_delay.called_with(3)
|
||||
mock_audio_delay.assert_called_once_with(3)
|
||||
|
||||
sub_gain_number = entity_registry.entities["number.zone_a_sub_gain"]
|
||||
sub_gain_state = hass.states.get(sub_gain_number.entity_id)
|
||||
assert sub_gain_state.state == "5"
|
||||
|
||||
with patch("soco.SoCo.sub_gain") as mock_sub_gain:
|
||||
with patch.object(
|
||||
type(soco), "sub_gain", new_callable=PropertyMock
|
||||
) as mock_sub_gain:
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
{ATTR_ENTITY_ID: sub_gain_number.entity_id, "value": -8},
|
||||
blocking=True,
|
||||
)
|
||||
assert mock_sub_gain.called_with(-8)
|
||||
mock_sub_gain.assert_called_once_with(-8)
|
||||
|
|
Loading…
Reference in New Issue