mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Improve type hints in nzbget tests (#123798)
This commit is contained in:
parent
f0247e942e
commit
ae74fdf252
@ -1,5 +1,6 @@
|
|||||||
"""Define fixtures available for all tests."""
|
"""Define fixtures available for all tests."""
|
||||||
|
|
||||||
|
from collections.abc import Generator
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -8,7 +9,7 @@ from . import MOCK_HISTORY, MOCK_STATUS, MOCK_VERSION
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def nzbget_api(hass):
|
def nzbget_api() -> Generator[MagicMock]:
|
||||||
"""Mock NZBGetApi for easier testing."""
|
"""Mock NZBGetApi for easier testing."""
|
||||||
with patch("homeassistant.components.nzbget.coordinator.NZBGetAPI") as mock_api:
|
with patch("homeassistant.components.nzbget.coordinator.NZBGetAPI") as mock_api:
|
||||||
instance = mock_api.return_value
|
instance = mock_api.return_value
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from pynzbgetapi import NZBGetAPIException
|
from pynzbgetapi import NZBGetAPIException
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.nzbget.const import DOMAIN
|
from homeassistant.components.nzbget.const import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
@ -13,7 +14,8 @@ from . import ENTRY_CONFIG, _patch_version, init_integration
|
|||||||
from tests.common import MockConfigEntry
|
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."""
|
"""Test successful unload of entry."""
|
||||||
entry = await init_integration(hass)
|
entry = await init_integration(hass)
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass
|
from homeassistant.components.sensor import SensorDeviceClass
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
@ -16,9 +18,8 @@ from homeassistant.util import dt as dt_util
|
|||||||
from . import init_integration
|
from . import init_integration
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors(
|
@pytest.mark.usefixtures("nzbget_api")
|
||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, nzbget_api
|
async def test_sensors(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
|
||||||
) -> None:
|
|
||||||
"""Test the creation and values of the sensors."""
|
"""Test the creation and values of the sensors."""
|
||||||
now = dt_util.utcnow().replace(microsecond=0)
|
now = dt_util.utcnow().replace(microsecond=0)
|
||||||
with patch("homeassistant.components.nzbget.sensor.utcnow", return_value=now):
|
with patch("homeassistant.components.nzbget.sensor.utcnow", return_value=now):
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""Test the NZBGet switches."""
|
"""Test the NZBGet switches."""
|
||||||
|
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
@ -16,7 +18,7 @@ from . import init_integration
|
|||||||
|
|
||||||
|
|
||||||
async def test_download_switch(
|
async def test_download_switch(
|
||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, nzbget_api
|
hass: HomeAssistant, entity_registry: er.EntityRegistry, nzbget_api: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the creation and values of the download switch."""
|
"""Test the creation and values of the download switch."""
|
||||||
instance = nzbget_api.return_value
|
instance = nzbget_api.return_value
|
||||||
@ -44,7 +46,9 @@ async def test_download_switch(
|
|||||||
assert state.state == STATE_OFF
|
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."""
|
"""Test download switch services."""
|
||||||
instance = nzbget_api.return_value
|
instance = nzbget_api.return_value
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user