From 18722aeccb79b4125043046be92c6a679e69bb46 Mon Sep 17 00:00:00 2001
From: epenet <6771947+epenet@users.noreply.github.com>
Date: Tue, 11 Jun 2024 15:07:40 +0200
Subject: [PATCH] Improve type hints and fix pylint warnings in util tests
 (#119355)

---
 tests/util/test_json.py        |  2 +-
 tests/util/test_location.py    | 13 ++++++++-----
 tests/util/test_unit_system.py |  5 ++---
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/tests/util/test_json.py b/tests/util/test_json.py
index 3eccb524538..c973ed1a91c 100644
--- a/tests/util/test_json.py
+++ b/tests/util/test_json.py
@@ -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):
diff --git a/tests/util/test_location.py b/tests/util/test_location.py
index b9252c33e9d..3af3ad2765a 100644
--- a/tests/util/test_location.py
+++ b/tests/util/test_location.py
@@ -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
diff --git a/tests/util/test_unit_system.py b/tests/util/test_unit_system.py
index 0fa11762490..033631563f4 100644
--- a/tests/util/test_unit_system.py
+++ b/tests/util/test_unit_system.py
@@ -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,
-- 
GitLab