Skip to content

Commit

Permalink
Improve type hints in enphase_envoy tests (#120676)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Jun 27, 2024
1 parent c419d22 commit 629dab2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
31 changes: 17 additions & 14 deletions tests/components/enphase_envoy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
EnvoyPhaseMode,
)
import pytest
from typing_extensions import AsyncGenerator

from homeassistant.components.enphase_envoy import DOMAIN
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
Expand All @@ -31,7 +32,9 @@


@pytest.fixture(name="config_entry")
def config_entry_fixture(hass: HomeAssistant, config, serial_number):
def config_entry_fixture(
hass: HomeAssistant, config: dict[str, str], serial_number: str
) -> MockConfigEntry:
"""Define a config entry fixture."""
entry = MockConfigEntry(
domain=DOMAIN,
Expand All @@ -45,7 +48,7 @@ def config_entry_fixture(hass: HomeAssistant, config, serial_number):


@pytest.fixture(name="config")
def config_fixture():
def config_fixture() -> dict[str, str]:
"""Define a config entry data fixture."""
return {
CONF_HOST: "1.1.1.1",
Expand All @@ -57,11 +60,11 @@ def config_fixture():

@pytest.fixture(name="mock_envoy")
def mock_envoy_fixture(
serial_number,
mock_authenticate,
mock_setup,
mock_auth,
):
serial_number: str,
mock_authenticate: AsyncMock,
mock_setup: AsyncMock,
mock_auth: EnvoyTokenAuth,
) -> Mock:
"""Define a mocked Envoy fixture."""
mock_envoy = Mock(spec=Envoy)
mock_envoy.serial_number = serial_number
Expand Down Expand Up @@ -352,9 +355,9 @@ def mock_envoy_fixture(
@pytest.fixture(name="setup_enphase_envoy")
async def setup_enphase_envoy_fixture(
hass: HomeAssistant,
config,
mock_envoy,
):
config: dict[str, str],
mock_envoy: Mock,
) -> AsyncGenerator[None]:
"""Define a fixture to set up Enphase Envoy."""
with (
patch(
Expand All @@ -372,13 +375,13 @@ async def setup_enphase_envoy_fixture(


@pytest.fixture(name="mock_authenticate")
def mock_authenticate():
def mock_authenticate() -> AsyncMock:
"""Define a mocked Envoy.authenticate fixture."""
return AsyncMock()


@pytest.fixture(name="mock_auth")
def mock_auth(serial_number):
def mock_auth(serial_number: str) -> EnvoyTokenAuth:
"""Define a mocked EnvoyAuth fixture."""
token = jwt.encode(
payload={"name": "envoy", "exp": 1907837780}, key="secret", algorithm="HS256"
Expand All @@ -387,12 +390,12 @@ def mock_auth(serial_number):


@pytest.fixture(name="mock_setup")
def mock_setup():
def mock_setup() -> AsyncMock:
"""Define a mocked Envoy.setup fixture."""
return AsyncMock()


@pytest.fixture(name="serial_number")
def serial_number_fixture():
def serial_number_fixture() -> str:
"""Define a serial number fixture."""
return "1234"
9 changes: 6 additions & 3 deletions tests/components/enphase_envoy/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Test Enphase Envoy sensors."""

from unittest.mock import patch
from unittest.mock import Mock, patch

import pytest
from syrupy.assertion import SnapshotAssertion
from typing_extensions import AsyncGenerator

from homeassistant.components.enphase_envoy import DOMAIN
from homeassistant.components.enphase_envoy.const import Platform
Expand All @@ -15,7 +16,9 @@


@pytest.fixture(name="setup_enphase_envoy_sensor")
async def setup_enphase_envoy_sensor_fixture(hass, config, mock_envoy):
async def setup_enphase_envoy_sensor_fixture(
hass: HomeAssistant, config: dict[str, str], mock_envoy: Mock
) -> AsyncGenerator[None]:
"""Define a fixture to set up Enphase Envoy with sensor platform only."""
with (
patch(
Expand All @@ -41,7 +44,7 @@ async def test_sensor(
entity_registry: er.EntityRegistry,
config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
setup_enphase_envoy_sensor,
setup_enphase_envoy_sensor: None,
) -> None:
"""Test enphase_envoy sensor entities."""
# compare registered entities against snapshot of prior run
Expand Down

0 comments on commit 629dab2

Please sign in to comment.