From fce4fc663e2190c06824c5d6bd867006bd941c82 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 11 Jun 2024 16:10:34 +0200 Subject: [PATCH] Fix import-outside-toplevel pylint warnings in core tests (#119394) --- tests/conftest.py | 6 ++---- tests/helpers/test_frame.py | 2 ++ tests/helpers/test_sun.py | 10 ++-------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 01607484d70..4e720bc0bd2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,6 +26,7 @@ from aiohttp.test_utils import ( ) from aiohttp.typedefs import JSONDecoder from aiohttp.web import Application +import bcrypt import freezegun import multidict import pytest @@ -70,6 +71,7 @@ from homeassistant.helpers import ( recorder as recorder_helper, ) from homeassistant.helpers.dispatcher import async_dispatcher_send +from homeassistant.helpers.translation import _TranslationsCacheData from homeassistant.helpers.typing import ConfigType from homeassistant.setup import BASE_PLATFORMS, async_setup_component from homeassistant.util import location @@ -394,8 +396,6 @@ def reset_hass_threading_local_object() -> Generator[None]: @pytest.fixture(scope="session", autouse=True) def bcrypt_cost() -> Generator[None]: """Run with reduced rounds during tests, to speed up uses.""" - import bcrypt - gensalt_orig = bcrypt.gensalt def gensalt_mock(rounds=12, prefix=b"2b"): @@ -1174,8 +1174,6 @@ def mock_get_source_ip() -> Generator[_patch]: @pytest.fixture(autouse=True, scope="session") def translations_once() -> Generator[_patch]: """Only load translations once per session.""" - from homeassistant.helpers.translation import _TranslationsCacheData - cache = _TranslationsCacheData({}, {}) patcher = patch( "homeassistant.helpers.translation._TranslationsCacheData", diff --git a/tests/helpers/test_frame.py b/tests/helpers/test_frame.py index e6251963d36..b0b4a0be6ee 100644 --- a/tests/helpers/test_frame.py +++ b/tests/helpers/test_frame.py @@ -36,6 +36,7 @@ async def test_extract_frame_resolve_module( hass: HomeAssistant, enable_custom_integrations ) -> None: """Test extracting the current frame from integration context.""" + # pylint: disable-next=import-outside-toplevel from custom_components.test_integration_frame import call_get_integration_frame integration_frame = call_get_integration_frame() @@ -53,6 +54,7 @@ async def test_get_integration_logger_resolve_module( hass: HomeAssistant, enable_custom_integrations ) -> None: """Test getting the logger from integration context.""" + # pylint: disable-next=import-outside-toplevel from custom_components.test_integration_frame import call_get_integration_logger logger = call_get_integration_logger(__name__) diff --git a/tests/helpers/test_sun.py b/tests/helpers/test_sun.py index da436d799aa..54c26997422 100644 --- a/tests/helpers/test_sun.py +++ b/tests/helpers/test_sun.py @@ -2,6 +2,8 @@ from datetime import datetime, timedelta +from astral import LocationInfo +import astral.sun from freezegun import freeze_time import pytest @@ -14,8 +16,6 @@ import homeassistant.util.dt as dt_util def test_next_events(hass: HomeAssistant) -> None: """Test retrieving next sun events.""" utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC) - from astral import LocationInfo - import astral.sun utc_today = utc_now.date() @@ -89,8 +89,6 @@ def test_next_events(hass: HomeAssistant) -> None: def test_date_events(hass: HomeAssistant) -> None: """Test retrieving next sun events.""" utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC) - from astral import LocationInfo - import astral.sun utc_today = utc_now.date() @@ -116,8 +114,6 @@ def test_date_events(hass: HomeAssistant) -> None: def test_date_events_default_date(hass: HomeAssistant) -> None: """Test retrieving next sun events.""" utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC) - from astral import LocationInfo - import astral.sun utc_today = utc_now.date() @@ -144,8 +140,6 @@ def test_date_events_default_date(hass: HomeAssistant) -> None: def test_date_events_accepts_datetime(hass: HomeAssistant) -> None: """Test retrieving next sun events.""" utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC) - from astral import LocationInfo - import astral.sun utc_today = utc_now.date()