Add monkeypatch type hints to numato tests (#121056)
* Add monkeypatch type hints to numato tests * Adjust * Improve
This commit is contained in:
parent
4958e8e5c1
commit
a6f6221f16
5 changed files with 17 additions and 12 deletions
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -21,7 +21,7 @@ MOCKUP_ENTITY_IDS = {
|
|||
|
||||
|
||||
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)
|
||||
|
|
|
@ -11,7 +11,7 @@ from .common import NUMATO_CFG, mockup_raise, mockup_return
|
|||
|
||||
|
||||
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.
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
@ -13,7 +15,7 @@ MOCKUP_ENTITY_IDS = {
|
|||
|
||||
|
||||
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)
|
||||
|
@ -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)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Tests for the numato switch platform."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import switch
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
|
@ -20,7 +22,7 @@ MOCKUP_ENTITY_IDS = {
|
|||
|
||||
|
||||
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)
|
||||
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue