From bfbf9b97516840a25e54293eda85e5efc5f66cde Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 27 Jan 2023 12:51:58 +0100 Subject: [PATCH] Adjusts imports in tests to match our relative import rules (#86788) --- pyproject.toml | 5 ++++- tests/components/blebox/test_config_flow.py | 3 ++- tests/components/ruuvi_gateway/utils.py | 6 +----- tests/components/subaru/test_diagnostics.py | 6 +----- tests/conftest.py | 8 ++++---- tests/test_bootstrap.py | 2 +- tests/test_config.py | 2 +- tests/test_config_entries.py | 2 +- tests/test_core.py | 2 +- tests/test_data_entry_flow.py | 2 +- tests/test_loader.py | 2 +- tests/test_requirements.py | 2 +- tests/test_setup.py | 2 +- 13 files changed, 20 insertions(+), 24 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 47127052375..9f16822970f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -224,7 +224,10 @@ runtime-typing = false max-line-length-suggestions = 72 [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] testpaths = [ diff --git a/tests/components/blebox/test_config_flow.py b/tests/components/blebox/test_config_flow.py index 030da33fcfe..265b7128a55 100644 --- a/tests/components/blebox/test_config_flow.py +++ b/tests/components/blebox/test_config_flow.py @@ -12,9 +12,10 @@ from homeassistant.const import CONF_IP_ADDRESS from homeassistant.data_entry_flow import FlowResultType 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 tests.common import MockConfigEntry + def create_valid_feature_mock(path="homeassistant.components.blebox.Products"): """Return a valid, complete BleBox feature mock.""" diff --git a/tests/components/ruuvi_gateway/utils.py b/tests/components/ruuvi_gateway/utils.py index d3181ca8f5f..76bde687321 100644 --- a/tests/components/ruuvi_gateway/utils.py +++ b/tests/components/ruuvi_gateway/utils.py @@ -6,11 +6,7 @@ from unittest.mock import _patch, patch from aioruuvigateway.models import HistoryResponse -from tests.components.ruuvi_gateway.consts import ( - ASYNC_SETUP_ENTRY, - GATEWAY_MAC, - GET_GATEWAY_HISTORY_DATA, -) +from .consts import ASYNC_SETUP_ENTRY, GATEWAY_MAC, GET_GATEWAY_HISTORY_DATA def patch_gateway_ok() -> _patch: diff --git a/tests/components/subaru/test_diagnostics.py b/tests/components/subaru/test_diagnostics.py index 547bb0edc4f..3d5950cf3aa 100644 --- a/tests/components/subaru/test_diagnostics.py +++ b/tests/components/subaru/test_diagnostics.py @@ -9,17 +9,13 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr 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.components.diagnostics import ( get_diagnostics_for_config_entry, 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): diff --git a/tests/conftest.py b/tests/conftest.py index e131cf6cdc3..ede6abab54f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -54,11 +54,11 @@ from homeassistant.helpers.typing import ConfigType from homeassistant.setup import async_setup_component 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") -from tests.common import ( # noqa: E402, isort:skip +from .common import ( # noqa: E402, isort:skip CLIENT_ID, INSTANCES, MockConfigEntry, @@ -70,7 +70,7 @@ from tests.common import ( # noqa: E402, isort:skip init_recorder_component, 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__) @@ -1062,7 +1062,7 @@ async def async_setup_recorder_instance( # testcase which does not use the 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 stats = recorder.Recorder.async_periodic_statistics if enable_statistics else None diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 9606d1968c4..f3526901d3d 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -13,7 +13,7 @@ from homeassistant.const import SIGNAL_BOOTSTRAP_INTEGRATIONS from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.dispatcher import async_dispatcher_connect -from tests.common import ( +from .common import ( MockModule, MockPlatform, get_test_config_dir, diff --git a/tests/test_config.py b/tests/test_config.py index 1d804736c9d..e535aaebe76 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -40,7 +40,7 @@ from homeassistant.util.unit_system import ( ) 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() YAML_PATH = os.path.join(CONFIG_DIR, config_util.YAML_CONFIG_FILE) diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 087ccaaae28..f7e3802e3c8 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -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.util import dt -from tests.common import ( +from .common import ( MockConfigEntry, MockEntity, MockModule, diff --git a/tests/test_core.py b/tests/test_core.py index 765c33cef40..d3fa14c7d22 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -43,7 +43,7 @@ import homeassistant.util.dt as dt_util from homeassistant.util.read_only_dict import ReadOnlyDict 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") diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index b39635e0ca5..f5871a95e7c 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -9,7 +9,7 @@ from homeassistant import config_entries, data_entry_flow from homeassistant.core import HomeAssistant from homeassistant.util.decorator import Registry -from tests.common import async_capture_events +from .common import async_capture_events @pytest.fixture diff --git a/tests/test_loader.py b/tests/test_loader.py index b3ba5d29724..2e853c33960 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -7,7 +7,7 @@ from homeassistant import core, loader from homeassistant.components import http, hue 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): diff --git a/tests/test_requirements.py b/tests/test_requirements.py index 6dadeba3797..21e119fd631 100644 --- a/tests/test_requirements.py +++ b/tests/test_requirements.py @@ -14,7 +14,7 @@ from homeassistant.requirements import ( async_process_requirements, ) -from tests.common import MockModule, mock_integration +from .common import MockModule, mock_integration def env_without_wheel_links(): diff --git a/tests/test_setup.py b/tests/test_setup.py index 82878ab217c..db6717dad99 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -18,7 +18,7 @@ from homeassistant.helpers.config_validation import ( PLATFORM_SCHEMA_BASE, ) -from tests.common import ( +from .common import ( MockConfigEntry, MockModule, MockPlatform,