Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add monkeypatch type hints to numato tests #121056

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tests/components/numato/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"""Fixtures for numato tests."""

from copy import deepcopy
from typing import Any

import pytest

from homeassistant.components import numato

from . import numato_mock
from .common import NUMATO_CFG
from .numato_mock import NumatoModuleMock


@pytest.fixture
def config():
def config() -> dict[str, Any]:
"""Provide a copy of the numato domain's test configuration.

This helps to quickly change certain aspects of the configuration scoped
Expand All @@ -21,8 +22,8 @@ def config():


@pytest.fixture
def numato_fixture(monkeypatch):
def numato_fixture(monkeypatch: pytest.MonkeyPatch) -> NumatoModuleMock:
"""Inject the numato mockup into numato homeassistant module."""
module_mock = numato_mock.NumatoModuleMock()
module_mock = NumatoModuleMock()
monkeypatch.setattr(numato, "gpio", module_mock)
return module_mock
2 changes: 1 addition & 1 deletion tests/components/numato/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


async def test_failing_setups_no_entities(
hass: HomeAssistant, numato_fixture, monkeypatch
hass: HomeAssistant, numato_fixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""When port setup fails, no entity shall be created."""
monkeypatch.setattr(numato_fixture.NumatoDeviceMock, "setup", mockup_raise)
Expand Down
6 changes: 3 additions & 3 deletions tests/components/numato/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


async def test_setup_no_devices(
hass: HomeAssistant, numato_fixture, monkeypatch
hass: HomeAssistant, numato_fixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test handling of an 'empty' discovery.

Expand All @@ -24,7 +24,7 @@ async def test_setup_no_devices(


async def test_fail_setup_raising_discovery(
hass: HomeAssistant, numato_fixture, caplog: pytest.LogCaptureFixture, monkeypatch
hass: HomeAssistant, numato_fixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test handling of an exception during discovery.

Expand Down Expand Up @@ -57,7 +57,7 @@ async def test_hass_numato_api_wrong_port_directions(


async def test_hass_numato_api_errors(
hass: HomeAssistant, numato_fixture, monkeypatch
hass: HomeAssistant, numato_fixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test whether Home Assistant numato API (re-)raises errors."""
numato_fixture.discover()
Expand Down
6 changes: 4 additions & 2 deletions tests/components/numato/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for the numato sensor platform."""

import pytest

from homeassistant.const import STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery
Expand All @@ -13,7 +15,7 @@


async def test_failing_setups_no_entities(
hass: HomeAssistant, numato_fixture, monkeypatch
hass: HomeAssistant, numato_fixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""When port setup fails, no entity shall be created."""
monkeypatch.setattr(numato_fixture.NumatoDeviceMock, "setup", mockup_raise)
Expand All @@ -24,7 +26,7 @@ async def test_failing_setups_no_entities(


async def test_failing_sensor_update(
hass: HomeAssistant, numato_fixture, monkeypatch
hass: HomeAssistant, numato_fixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test condition when a sensor update fails."""
monkeypatch.setattr(numato_fixture.NumatoDeviceMock, "adc_read", mockup_raise)
Expand Down
6 changes: 4 additions & 2 deletions tests/components/numato/test_switch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for the numato switch platform."""

import pytest

from homeassistant.components import switch
from homeassistant.const import (
ATTR_ENTITY_ID,
Expand All @@ -20,7 +22,7 @@


async def test_failing_setups_no_entities(
hass: HomeAssistant, numato_fixture, monkeypatch
hass: HomeAssistant, numato_fixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""When port setup fails, no entity shall be created."""
monkeypatch.setattr(numato_fixture.NumatoDeviceMock, "setup", mockup_raise)
Expand Down Expand Up @@ -69,7 +71,7 @@ async def test_regular_hass_operations(hass: HomeAssistant, numato_fixture) -> N


async def test_failing_hass_operations(
hass: HomeAssistant, numato_fixture, monkeypatch
hass: HomeAssistant, numato_fixture, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test failing operations called from within Home Assistant.

Expand Down