mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Improve type hints and fix pylint warnings in util tests (#119355)
This commit is contained in:
parent
e14146d7c9
commit
18722aeccb
@ -159,7 +159,7 @@ async def test_deprecated_save_json(
|
||||
assert "should be updated to use homeassistant.helpers.json module" in caplog.text
|
||||
|
||||
|
||||
async def test_loading_derived_class():
|
||||
async def test_loading_derived_class() -> None:
|
||||
"""Test loading data from classes derived from str."""
|
||||
|
||||
class MyStr(str):
|
||||
|
@ -5,6 +5,7 @@ from unittest.mock import Mock, patch
|
||||
import aiohttp
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.util.location as location_util
|
||||
|
||||
@ -28,13 +29,13 @@ DISTANCE_MILES = 3632.78
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def session(hass):
|
||||
async def session(hass: HomeAssistant) -> aiohttp.ClientSession:
|
||||
"""Return aioclient session."""
|
||||
return async_get_clientsession(hass)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def raising_session():
|
||||
async def raising_session() -> Mock:
|
||||
"""Return an aioclient session that only fails."""
|
||||
return Mock(get=Mock(side_effect=aiohttp.ClientError))
|
||||
|
||||
@ -76,7 +77,7 @@ def test_get_miles() -> None:
|
||||
|
||||
|
||||
async def test_detect_location_info_whoami(
|
||||
aioclient_mock: AiohttpClientMocker, session
|
||||
aioclient_mock: AiohttpClientMocker, session: aiohttp.ClientSession
|
||||
) -> None:
|
||||
"""Test detect location info using services.home-assistant.io/whoami."""
|
||||
aioclient_mock.get(location_util.WHOAMI_URL, text=load_fixture("whoami.json"))
|
||||
@ -99,7 +100,9 @@ async def test_detect_location_info_whoami(
|
||||
assert info.use_metric
|
||||
|
||||
|
||||
async def test_dev_url(aioclient_mock: AiohttpClientMocker, session) -> None:
|
||||
async def test_dev_url(
|
||||
aioclient_mock: AiohttpClientMocker, session: aiohttp.ClientSession
|
||||
) -> None:
|
||||
"""Test usage of dev URL."""
|
||||
aioclient_mock.get(location_util.WHOAMI_URL_DEV, text=load_fixture("whoami.json"))
|
||||
with patch("homeassistant.util.location.HA_VERSION", "1.0.dev0"):
|
||||
@ -110,7 +113,7 @@ async def test_dev_url(aioclient_mock: AiohttpClientMocker, session) -> None:
|
||||
assert info.currency == "XXX"
|
||||
|
||||
|
||||
async def test_whoami_query_raises(raising_session) -> None:
|
||||
async def test_whoami_query_raises(raising_session: Mock) -> None:
|
||||
"""Test whoami query when the request to API fails."""
|
||||
info = await location_util._get_whoami(raising_session)
|
||||
assert info is None
|
||||
|
@ -4,8 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.sensor import SensorDeviceClass
|
||||
from homeassistant.components.sensor.const import DEVICE_CLASS_UNITS
|
||||
from homeassistant.components.sensor import DEVICE_CLASS_UNITS, SensorDeviceClass
|
||||
from homeassistant.const import (
|
||||
ACCUMULATED_PRECIPITATION,
|
||||
LENGTH,
|
||||
@ -23,7 +22,7 @@ from homeassistant.const import (
|
||||
UnitOfVolumetricFlux,
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.util.unit_system import (
|
||||
from homeassistant.util.unit_system import ( # pylint: disable=hass-deprecated-import
|
||||
_CONF_UNIT_SYSTEM_IMPERIAL,
|
||||
_CONF_UNIT_SYSTEM_METRIC,
|
||||
_CONF_UNIT_SYSTEM_US_CUSTOMARY,
|
||||
|
Loading…
x
Reference in New Issue
Block a user