Rename calls fixture in components tests (#118355)

This commit is contained in:
epenet 2024-05-29 09:26:44 +02:00 committed by GitHub
parent 0f8588a857
commit 0c38aa56f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 29 deletions

View File

@ -9,7 +9,7 @@ from homeassistant.components import notify
from homeassistant.components.demo import DOMAIN from homeassistant.components.demo import DOMAIN
import homeassistant.components.demo.notify as demo import homeassistant.components.demo.notify as demo
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import Event, HomeAssistant, callback from homeassistant.core import Event, HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry, async_capture_events from tests.common import MockConfigEntry, async_capture_events
@ -42,24 +42,6 @@ def events(hass: HomeAssistant) -> list[Event]:
return async_capture_events(hass, demo.EVENT_NOTIFY) return async_capture_events(hass, demo.EVENT_NOTIFY)
@pytest.fixture
def calls():
"""Fixture to calls."""
return []
@pytest.fixture
def record_calls(calls):
"""Fixture to record calls."""
@callback
def record_calls(*args):
"""Record calls."""
calls.append(args)
return record_calls
async def test_sending_message(hass: HomeAssistant, events: list[Event]) -> None: async def test_sending_message(hass: HomeAssistant, events: list[Event]) -> None:
"""Test sending a message.""" """Test sending a message."""
data = { data = {

View File

@ -76,7 +76,7 @@ async def test_full_flow(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("fixture", "abort_reason", "placeholders", "calls", "access_token"), ("fixture", "abort_reason", "placeholders", "call_count", "access_token"),
[ [
("get_profile", "reauth_successful", None, 1, "updated-access-token"), ("get_profile", "reauth_successful", None, 1, "updated-access-token"),
( (
@ -97,7 +97,7 @@ async def test_reauth(
fixture: str, fixture: str,
abort_reason: str, abort_reason: str,
placeholders: dict[str, str], placeholders: dict[str, str],
calls: int, call_count: int,
access_token: str, access_token: str,
) -> None: ) -> None:
"""Test the re-authentication case updates the correct config entry. """Test the re-authentication case updates the correct config entry.
@ -164,7 +164,7 @@ async def test_reauth(
assert result.get("type") is FlowResultType.ABORT assert result.get("type") is FlowResultType.ABORT
assert result["reason"] == abort_reason assert result["reason"] == abort_reason
assert result["description_placeholders"] == placeholders assert result["description_placeholders"] == placeholders
assert len(mock_setup.mock_calls) == calls assert len(mock_setup.mock_calls) == call_count
assert config_entry.unique_id == TITLE assert config_entry.unique_id == TITLE
assert "token" in config_entry.data assert "token" in config_entry.data

View File

@ -277,7 +277,7 @@ async def test_service_update_devices(hass: HomeAssistant, create_hdmi_network)
@pytest.mark.parametrize( @pytest.mark.parametrize(
("count", "calls"), ("count", "call_count"),
[ [
(3, 3), (3, 3),
(1, 1), (1, 1),
@ -294,7 +294,12 @@ async def test_service_update_devices(hass: HomeAssistant, create_hdmi_network)
) )
@pytest.mark.parametrize(("direction", "key"), [("up", 65), ("down", 66)]) @pytest.mark.parametrize(("direction", "key"), [("up", 65), ("down", 66)])
async def test_service_volume_x_times( async def test_service_volume_x_times(
hass: HomeAssistant, create_hdmi_network, count, calls, direction, key hass: HomeAssistant,
create_hdmi_network,
count: int,
call_count: int,
direction,
key,
) -> None: ) -> None:
"""Test the volume service call with steps.""" """Test the volume service call with steps."""
mock_hdmi_network_instance = await create_hdmi_network() mock_hdmi_network_instance = await create_hdmi_network()
@ -306,8 +311,8 @@ async def test_service_volume_x_times(
blocking=True, blocking=True,
) )
assert mock_hdmi_network_instance.send_command.call_count == calls * 2 assert mock_hdmi_network_instance.send_command.call_count == call_count * 2
for i in range(calls): for i in range(call_count):
assert_key_press_release( assert_key_press_release(
mock_hdmi_network_instance.send_command, i, dst=5, key=key mock_hdmi_network_instance.send_command, i, dst=5, key=key
) )

View File

@ -211,7 +211,7 @@ async def test_flow_http_error(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("fixture", "abort_reason", "placeholders", "calls", "access_token"), ("fixture", "abort_reason", "placeholders", "call_count", "access_token"),
[ [
( (
"get_channel", "get_channel",
@ -238,7 +238,7 @@ async def test_reauth(
fixture: str, fixture: str,
abort_reason: str, abort_reason: str,
placeholders: dict[str, str], placeholders: dict[str, str],
calls: int, call_count: int,
access_token: str, access_token: str,
) -> None: ) -> None:
"""Test the re-authentication case updates the correct config entry. """Test the re-authentication case updates the correct config entry.
@ -303,7 +303,7 @@ async def test_reauth(
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
assert result["reason"] == abort_reason assert result["reason"] == abort_reason
assert result["description_placeholders"] == placeholders assert result["description_placeholders"] == placeholders
assert len(mock_setup.mock_calls) == calls assert len(mock_setup.mock_calls) == call_count
assert config_entry.unique_id == "UC_x5XG1OV2P6uZZ5FSM9Ttw" assert config_entry.unique_id == "UC_x5XG1OV2P6uZZ5FSM9Ttw"
assert "token" in config_entry.data assert "token" in config_entry.data