Fix import-outside-toplevel pylint warnings in core tests (#119394)

This commit is contained in:
epenet 2024-06-11 16:10:34 +02:00 committed by GitHub
parent 4bca0ad956
commit fce4fc663e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 12 deletions

View File

@ -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",

View File

@ -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__)

View File

@ -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()