Adjusts imports in tests to match our relative import rules (#86788)

This commit is contained in:
Franck Nijhof 2023-01-27 12:51:58 +01:00 committed by GitHub
parent 89c0b27b42
commit bfbf9b9751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 20 additions and 24 deletions

View File

@ -224,7 +224,10 @@ runtime-typing = false
max-line-length-suggestions = 72 max-line-length-suggestions = 72
[tool.pylint-per-file-ignores] [tool.pylint-per-file-ignores]
"/tests/"="protected-access,redefined-outer-name" # hass-component-root-import: Tests test non-public APIs
# protected-access: Tests do often test internals a lot
# redefined-outer-name: Tests reference fixtures in the test function
"/tests/"="hass-component-root-import,protected-access,redefined-outer-name"
[tool.pytest.ini_options] [tool.pytest.ini_options]
testpaths = [ testpaths = [

View File

@ -12,9 +12,10 @@ from homeassistant.const import CONF_IP_ADDRESS
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from ...common import MockConfigEntry
from .conftest import mock_config, mock_feature, mock_only_feature, setup_product_mock from .conftest import mock_config, mock_feature, mock_only_feature, setup_product_mock
from tests.common import MockConfigEntry
def create_valid_feature_mock(path="homeassistant.components.blebox.Products"): def create_valid_feature_mock(path="homeassistant.components.blebox.Products"):
"""Return a valid, complete BleBox feature mock.""" """Return a valid, complete BleBox feature mock."""

View File

@ -6,11 +6,7 @@ from unittest.mock import _patch, patch
from aioruuvigateway.models import HistoryResponse from aioruuvigateway.models import HistoryResponse
from tests.components.ruuvi_gateway.consts import ( from .consts import ASYNC_SETUP_ENTRY, GATEWAY_MAC, GET_GATEWAY_HISTORY_DATA
ASYNC_SETUP_ENTRY,
GATEWAY_MAC,
GET_GATEWAY_HISTORY_DATA,
)
def patch_gateway_ok() -> _patch: def patch_gateway_ok() -> _patch:

View File

@ -9,17 +9,13 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
from .api_responses import TEST_VIN_2_EV from .api_responses import TEST_VIN_2_EV
from .conftest import MOCK_API_FETCH, MOCK_API_GET_DATA, advance_time_to_next_fetch
from tests.common import load_fixture from tests.common import load_fixture
from tests.components.diagnostics import ( from tests.components.diagnostics import (
get_diagnostics_for_config_entry, get_diagnostics_for_config_entry,
get_diagnostics_for_device, get_diagnostics_for_device,
) )
from tests.components.subaru.conftest import (
MOCK_API_FETCH,
MOCK_API_GET_DATA,
advance_time_to_next_fetch,
)
async def test_config_entry_diagnostics(hass: HomeAssistant, hass_client, ev_entry): async def test_config_entry_diagnostics(hass: HomeAssistant, hass_client, ev_entry):

View File

@ -54,11 +54,11 @@ from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util, location from homeassistant.util import dt as dt_util, location
from tests.ignore_uncaught_exceptions import IGNORE_UNCAUGHT_EXCEPTIONS from .ignore_uncaught_exceptions import IGNORE_UNCAUGHT_EXCEPTIONS
pytest.register_assert_rewrite("tests.common") pytest.register_assert_rewrite("tests.common")
from tests.common import ( # noqa: E402, isort:skip from .common import ( # noqa: E402, isort:skip
CLIENT_ID, CLIENT_ID,
INSTANCES, INSTANCES,
MockConfigEntry, MockConfigEntry,
@ -70,7 +70,7 @@ from tests.common import ( # noqa: E402, isort:skip
init_recorder_component, init_recorder_component,
mock_storage as mock_storage, mock_storage as mock_storage,
) )
from tests.test_util.aiohttp import mock_aiohttp_client # noqa: E402, isort:skip from .test_util.aiohttp import mock_aiohttp_client # noqa: E402, isort:skip
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -1062,7 +1062,7 @@ async def async_setup_recorder_instance(
# testcase which does not use the recorder. # testcase which does not use the recorder.
from homeassistant.components import recorder from homeassistant.components import recorder
from tests.components.recorder.common import async_recorder_block_till_done from .components.recorder.common import async_recorder_block_till_done
nightly = recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None nightly = recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None
stats = recorder.Recorder.async_periodic_statistics if enable_statistics else None stats = recorder.Recorder.async_periodic_statistics if enable_statistics else None

View File

@ -13,7 +13,7 @@ from homeassistant.const import SIGNAL_BOOTSTRAP_INTEGRATIONS
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from tests.common import ( from .common import (
MockModule, MockModule,
MockPlatform, MockPlatform,
get_test_config_dir, get_test_config_dir,

View File

@ -40,7 +40,7 @@ from homeassistant.util.unit_system import (
) )
from homeassistant.util.yaml import SECRET_YAML from homeassistant.util.yaml import SECRET_YAML
from tests.common import MockUser, get_test_config_dir, patch_yaml_files from .common import MockUser, get_test_config_dir, patch_yaml_files
CONFIG_DIR = get_test_config_dir() CONFIG_DIR = get_test_config_dir()
YAML_PATH = os.path.join(CONFIG_DIR, config_util.YAML_CONFIG_FILE) YAML_PATH = os.path.join(CONFIG_DIR, config_util.YAML_CONFIG_FILE)

View File

@ -29,7 +29,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.setup import async_set_domains_to_be_loaded, async_setup_component from homeassistant.setup import async_set_domains_to_be_loaded, async_setup_component
from homeassistant.util import dt from homeassistant.util import dt
from tests.common import ( from .common import (
MockConfigEntry, MockConfigEntry,
MockEntity, MockEntity,
MockModule, MockModule,

View File

@ -43,7 +43,7 @@ import homeassistant.util.dt as dt_util
from homeassistant.util.read_only_dict import ReadOnlyDict from homeassistant.util.read_only_dict import ReadOnlyDict
from homeassistant.util.unit_system import METRIC_SYSTEM from homeassistant.util.unit_system import METRIC_SYSTEM
from tests.common import async_capture_events, async_mock_service from .common import async_capture_events, async_mock_service
PST = dt_util.get_time_zone("America/Los_Angeles") PST = dt_util.get_time_zone("America/Los_Angeles")

View File

@ -9,7 +9,7 @@ from homeassistant import config_entries, data_entry_flow
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.util.decorator import Registry from homeassistant.util.decorator import Registry
from tests.common import async_capture_events from .common import async_capture_events
@pytest.fixture @pytest.fixture

View File

@ -7,7 +7,7 @@ from homeassistant import core, loader
from homeassistant.components import http, hue from homeassistant.components import http, hue
from homeassistant.components.hue import light as hue_light from homeassistant.components.hue import light as hue_light
from tests.common import MockModule, mock_integration from .common import MockModule, mock_integration
async def test_component_dependencies(hass): async def test_component_dependencies(hass):

View File

@ -14,7 +14,7 @@ from homeassistant.requirements import (
async_process_requirements, async_process_requirements,
) )
from tests.common import MockModule, mock_integration from .common import MockModule, mock_integration
def env_without_wheel_links(): def env_without_wheel_links():

View File

@ -18,7 +18,7 @@ from homeassistant.helpers.config_validation import (
PLATFORM_SCHEMA_BASE, PLATFORM_SCHEMA_BASE,
) )
from tests.common import ( from .common import (
MockConfigEntry, MockConfigEntry,
MockModule, MockModule,
MockPlatform, MockPlatform,