Improve type hints in nzbget tests (#123798)

This commit is contained in:
epenet 2024-08-13 14:57:24 +02:00 committed by GitHub
parent f0247e942e
commit ae74fdf252
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 7 deletions

View File

@ -1,5 +1,6 @@
"""Define fixtures available for all tests."""
from collections.abc import Generator
from unittest.mock import MagicMock, patch
import pytest
@ -8,7 +9,7 @@ from . import MOCK_HISTORY, MOCK_STATUS, MOCK_VERSION
@pytest.fixture
def nzbget_api(hass):
def nzbget_api() -> Generator[MagicMock]:
"""Mock NZBGetApi for easier testing."""
with patch("homeassistant.components.nzbget.coordinator.NZBGetAPI") as mock_api:
instance = mock_api.return_value

View File

@ -3,6 +3,7 @@
from unittest.mock import patch
from pynzbgetapi import NZBGetAPIException
import pytest
from homeassistant.components.nzbget.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
@ -13,7 +14,8 @@ from . import ENTRY_CONFIG, _patch_version, init_integration
from tests.common import MockConfigEntry
async def test_unload_entry(hass: HomeAssistant, nzbget_api) -> None:
@pytest.mark.usefixtures("nzbget_api")
async def test_unload_entry(hass: HomeAssistant) -> None:
"""Test successful unload of entry."""
entry = await init_integration(hass)

View File

@ -3,6 +3,8 @@
from datetime import timedelta
from unittest.mock import patch
import pytest
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT,
@ -16,9 +18,8 @@ from homeassistant.util import dt as dt_util
from . import init_integration
async def test_sensors(
hass: HomeAssistant, entity_registry: er.EntityRegistry, nzbget_api
) -> None:
@pytest.mark.usefixtures("nzbget_api")
async def test_sensors(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
"""Test the creation and values of the sensors."""
now = dt_util.utcnow().replace(microsecond=0)
with patch("homeassistant.components.nzbget.sensor.utcnow", return_value=now):

View File

@ -1,5 +1,7 @@
"""Test the NZBGet switches."""
from unittest.mock import MagicMock
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -16,7 +18,7 @@ from . import init_integration
async def test_download_switch(
hass: HomeAssistant, entity_registry: er.EntityRegistry, nzbget_api
hass: HomeAssistant, entity_registry: er.EntityRegistry, nzbget_api: MagicMock
) -> None:
"""Test the creation and values of the download switch."""
instance = nzbget_api.return_value
@ -44,7 +46,9 @@ async def test_download_switch(
assert state.state == STATE_OFF
async def test_download_switch_services(hass: HomeAssistant, nzbget_api) -> None:
async def test_download_switch_services(
hass: HomeAssistant, nzbget_api: MagicMock
) -> None:
"""Test download switch services."""
instance = nzbget_api.return_value