From f60125b5c9dc08e58a8346da7825833e65c8f958 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 9 Dec 2019 16:52:24 +0100 Subject: [PATCH] Sort imports according to PEP8 for 'tests' (#29791) --- .../auth/mfa_modules/test_insecure_example.py | 1 + tests/auth/mfa_modules/test_notify.py | 3 +- tests/auth/mfa_modules/test_totp.py | 3 +- tests/auth/permissions/test_entities.py | 6 +-- .../auth/permissions/test_system_policies.py | 2 +- tests/auth/providers/test_command_line.py | 4 +- tests/auth/providers/test_insecure_example.py | 2 +- tests/auth/test_init.py | 5 ++- tests/common.py | 36 +++++++-------- tests/conftest.py | 17 +++---- tests/helpers/test_aiohttp_client.py | 2 +- tests/helpers/test_area_registry.py | 3 +- tests/helpers/test_check_config.py | 9 ++-- tests/helpers/test_config_entry_flow.py | 5 ++- .../helpers/test_config_entry_oauth2_flow.py | 6 +-- tests/helpers/test_deprecation.py | 4 +- tests/helpers/test_device_registry.py | 3 +- tests/helpers/test_discovery.py | 4 +- tests/helpers/test_dispatcher.py | 2 +- tests/helpers/test_entity.py | 10 ++--- tests/helpers/test_entity_component.py | 23 +++++----- tests/helpers/test_entity_platform.py | 17 ++++--- tests/helpers/test_entity_registry.py | 5 +-- tests/helpers/test_entity_values.py | 1 + tests/helpers/test_entityfilter.py | 2 +- tests/helpers/test_event.py | 8 ++-- tests/helpers/test_intent.py | 5 +-- tests/helpers/test_network.py | 2 +- tests/helpers/test_restore_state.py | 7 ++- tests/helpers/test_script.py | 14 +++--- tests/helpers/test_service.py | 19 ++++---- tests/helpers/test_state.py | 29 ++++++------ tests/helpers/test_storage.py | 3 +- tests/helpers/test_sun.py | 4 +- tests/helpers/test_temperature.py | 6 +-- tests/helpers/test_template.py | 4 +- tests/helpers/test_translation.py | 3 +- tests/scripts/test_auth.py | 2 +- tests/scripts/test_check_config.py | 3 +- tests/test_bootstrap.py | 8 ++-- tests/test_config.py | 28 ++++++------ tests/test_config_entries.py | 10 ++--- tests/test_core.py | 44 +++++++++---------- tests/test_loader.py | 2 +- tests/test_main.py | 2 +- tests/test_requirements.py | 11 ++--- tests/test_setup.py | 20 ++++----- tests/test_util/aiohttp.py | 3 +- tests/test_util/test_aiohttp.py | 4 +- .../test/alarm_control_panel.py | 13 +++--- .../custom_components/test/binary_sensor.py | 4 +- .../custom_components/test/cover.py | 2 +- .../custom_components/test/light.py | 4 +- .../custom_components/test/lock.py | 3 +- .../custom_components/test/sensor.py | 2 +- .../custom_components/test/switch.py | 4 +- .../test_package/__init__.py | 1 - tests/util/test_async.py | 2 +- tests/util/test_distance.py | 4 +- tests/util/test_init.py | 2 +- tests/util/test_json.py | 7 ++- tests/util/test_location.py | 2 +- tests/util/test_package.py | 3 +- tests/util/test_pressure.py | 4 +- tests/util/test_ruamel_yaml.py | 3 +- tests/util/test_unit_system.py | 14 +++--- tests/util/test_volume.py | 6 +-- tests/util/test_yaml.py | 9 ++-- 68 files changed, 254 insertions(+), 251 deletions(-) diff --git a/tests/auth/mfa_modules/test_insecure_example.py b/tests/auth/mfa_modules/test_insecure_example.py index dc233cb53ff9..5384ebee4bd6 100644 --- a/tests/auth/mfa_modules/test_insecure_example.py +++ b/tests/auth/mfa_modules/test_insecure_example.py @@ -2,6 +2,7 @@ from homeassistant import auth, data_entry_flow from homeassistant.auth.mfa_modules import auth_mfa_module_from_config from homeassistant.auth.models import Credentials + from tests.common import MockUser diff --git a/tests/auth/mfa_modules/test_notify.py b/tests/auth/mfa_modules/test_notify.py index 20ed104b3755..bc4ecaab712b 100644 --- a/tests/auth/mfa_modules/test_notify.py +++ b/tests/auth/mfa_modules/test_notify.py @@ -3,9 +3,10 @@ import asyncio from unittest.mock import patch from homeassistant import data_entry_flow -from homeassistant.auth import models as auth_models, auth_manager_from_config +from homeassistant.auth import auth_manager_from_config, models as auth_models from homeassistant.auth.mfa_modules import auth_mfa_module_from_config from homeassistant.components.notify import NOTIFY_SERVICE_SCHEMA + from tests.common import MockUser, async_mock_service MOCK_CODE = "123456" diff --git a/tests/auth/mfa_modules/test_totp.py b/tests/auth/mfa_modules/test_totp.py index e53e3030cd2e..d0a4f3cf3aca 100644 --- a/tests/auth/mfa_modules/test_totp.py +++ b/tests/auth/mfa_modules/test_totp.py @@ -3,8 +3,9 @@ import asyncio from unittest.mock import patch from homeassistant import data_entry_flow -from homeassistant.auth import models as auth_models, auth_manager_from_config +from homeassistant.auth import auth_manager_from_config, models as auth_models from homeassistant.auth.mfa_modules import auth_mfa_module_from_config + from tests.common import MockUser MOCK_CODE = "123456" diff --git a/tests/auth/permissions/test_entities.py b/tests/auth/permissions/test_entities.py index c2305b5c203f..a929984d1522 100644 --- a/tests/auth/permissions/test_entities.py +++ b/tests/auth/permissions/test_entities.py @@ -3,14 +3,14 @@ import pytest import voluptuous as vol from homeassistant.auth.permissions.entities import ( - compile_entities, ENTITY_POLICY_SCHEMA, + compile_entities, ) from homeassistant.auth.permissions.models import PermissionLookup -from homeassistant.helpers.entity_registry import RegistryEntry from homeassistant.helpers.device_registry import DeviceEntry +from homeassistant.helpers.entity_registry import RegistryEntry -from tests.common import mock_registry, mock_device_registry +from tests.common import mock_device_registry, mock_registry def test_entities_none(): diff --git a/tests/auth/permissions/test_system_policies.py b/tests/auth/permissions/test_system_policies.py index 2710fdd68c3f..58515e2ad2ae 100644 --- a/tests/auth/permissions/test_system_policies.py +++ b/tests/auth/permissions/test_system_policies.py @@ -1,8 +1,8 @@ """Test system policies.""" from homeassistant.auth.permissions import ( + POLICY_SCHEMA, PolicyPermissions, system_policies, - POLICY_SCHEMA, ) diff --git a/tests/auth/providers/test_command_line.py b/tests/auth/providers/test_command_line.py index 33b1735457f5..abcf124b9c46 100644 --- a/tests/auth/providers/test_command_line.py +++ b/tests/auth/providers/test_command_line.py @@ -1,13 +1,13 @@ """Tests for the command_line auth provider.""" -from unittest.mock import Mock import os +from unittest.mock import Mock import uuid import pytest from homeassistant import data_entry_flow -from homeassistant.auth import auth_store, models as auth_models, AuthManager +from homeassistant.auth import AuthManager, auth_store, models as auth_models from homeassistant.auth.providers import command_line from homeassistant.const import CONF_TYPE diff --git a/tests/auth/providers/test_insecure_example.py b/tests/auth/providers/test_insecure_example.py index 43f5aff290ed..c5b3a8db0383 100644 --- a/tests/auth/providers/test_insecure_example.py +++ b/tests/auth/providers/test_insecure_example.py @@ -4,7 +4,7 @@ import uuid import pytest -from homeassistant.auth import auth_store, models as auth_models, AuthManager +from homeassistant.auth import AuthManager, auth_store, models as auth_models from homeassistant.auth.providers import insecure_example from tests.common import mock_coro diff --git a/tests/auth/test_init.py b/tests/auth/test_init.py index 73b383fb0fec..aa047a12d545 100644 --- a/tests/auth/test_init.py +++ b/tests/auth/test_init.py @@ -7,11 +7,12 @@ import pytest import voluptuous as vol from homeassistant import auth, data_entry_flow -from homeassistant.auth import models as auth_models, auth_store, const as auth_const +from homeassistant.auth import auth_store, const as auth_const, models as auth_models from homeassistant.auth.const import MFA_SESSION_EXPIRATION from homeassistant.core import callback from homeassistant.util import dt as dt_util -from tests.common import MockUser, ensure_auth_manager_loaded, flush_store, CLIENT_ID + +from tests.common import CLIENT_ID, MockUser, ensure_auth_manager_loaded, flush_store @pytest.fixture diff --git a/tests/common.py b/tests/common.py index e652e10cc542..a54b3899698f 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,32 +1,32 @@ """Test the helper method for writing tests.""" import asyncio import collections -import functools as ft -import json -import logging -import os -import uuid -import sys -import threading - from collections import OrderedDict from contextlib import contextmanager from datetime import timedelta +import functools as ft from io import StringIO +import json +import logging +import os +import sys +import threading from unittest.mock import MagicMock, Mock, patch - -import homeassistant.util.dt as date_util -import homeassistant.util.yaml.loader as yaml_loader +import uuid from homeassistant import auth, config_entries, core as ha, loader from homeassistant.auth import ( - models as auth_models, auth_store, - providers as auth_providers, + models as auth_models, permissions as auth_permissions, + providers as auth_providers, ) from homeassistant.auth.permissions import system_policies from homeassistant.components import mqtt, recorder +from homeassistant.components.device_automation import ( # noqa: F401 + _async_get_device_automation_capabilities as async_get_device_automation_capabilities, + _async_get_device_automations as async_get_device_automations, +) from homeassistant.components.mqtt.models import Message from homeassistant.config import async_process_component_config from homeassistant.const import ( @@ -38,8 +38,8 @@ from homeassistant.const import ( EVENT_STATE_CHANGED, EVENT_TIME_CHANGED, SERVER_PORT, - STATE_ON, STATE_OFF, + STATE_ON, ) from homeassistant.core import State from homeassistant.helpers import ( @@ -54,12 +54,10 @@ from homeassistant.helpers import ( ) from homeassistant.helpers.json import JSONEncoder from homeassistant.setup import async_setup_component, setup_component -from homeassistant.util.unit_system import METRIC_SYSTEM from homeassistant.util.async_ import run_callback_threadsafe -from homeassistant.components.device_automation import ( # noqa: F401 - _async_get_device_automations as async_get_device_automations, - _async_get_device_automation_capabilities as async_get_device_automation_capabilities, -) +import homeassistant.util.dt as date_util +from homeassistant.util.unit_system import METRIC_SYSTEM +import homeassistant.util.yaml.loader as yaml_loader _TEST_INSTANCE_PORT = SERVER_PORT _LOGGER = logging.getLogger(__name__) diff --git a/tests/conftest.py b/tests/conftest.py index 5e1bbc76fb56..2b6a1a167391 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,22 +9,23 @@ import pytest import requests_mock as _requests_mock from homeassistant import util -from homeassistant.util import location from homeassistant.auth.const import GROUP_ID_ADMIN, GROUP_ID_READ_ONLY -from homeassistant.auth.providers import legacy_api_password, homeassistant +from homeassistant.auth.providers import homeassistant, legacy_api_password +from homeassistant.util import location -pytest.register_assert_rewrite("tests.common") from tests.common import ( # noqa: E402 module level import not at top of file - async_test_home_assistant, + CLIENT_ID, INSTANCES, + MockUser, + async_test_home_assistant, mock_coro, mock_storage as mock_storage, - MockUser, - CLIENT_ID, ) -from tests.test_util.aiohttp import ( +from tests.test_util.aiohttp import ( # noqa: E402 module level import not at top of file mock_aiohttp_client, -) # noqa: E402 module level import not at top of file +) + +pytest.register_assert_rewrite("tests.common") if os.environ.get("UVLOOP") == "1": import uvloop diff --git a/tests/helpers/test_aiohttp_client.py b/tests/helpers/test_aiohttp_client.py index 5494bc40a75c..de7057ae9c7a 100644 --- a/tests/helpers/test_aiohttp_client.py +++ b/tests/helpers/test_aiohttp_client.py @@ -6,8 +6,8 @@ import aiohttp import pytest from homeassistant.core import EVENT_HOMEASSISTANT_CLOSE -from homeassistant.setup import async_setup_component import homeassistant.helpers.aiohttp_client as client +from homeassistant.setup import async_setup_component from homeassistant.util.async_ import run_callback_threadsafe from tests.common import get_test_home_assistant diff --git a/tests/helpers/test_area_registry.py b/tests/helpers/test_area_registry.py index 48d32861a0ab..87e4b4c4d031 100644 --- a/tests/helpers/test_area_registry.py +++ b/tests/helpers/test_area_registry.py @@ -6,7 +6,8 @@ import pytest from homeassistant.core import callback from homeassistant.helpers import area_registry -from tests.common import mock_area_registry, flush_store + +from tests.common import flush_store, mock_area_registry @pytest.fixture diff --git a/tests/helpers/test_check_config.py b/tests/helpers/test_check_config.py index 0b34b263cafa..54c835895ca2 100644 --- a/tests/helpers/test_check_config.py +++ b/tests/helpers/test_check_config.py @@ -2,11 +2,12 @@ import logging from unittest.mock import patch -from homeassistant.helpers.check_config import ( - async_check_ha_config_file, - CheckConfigError, -) from homeassistant.config import YAML_CONFIG_FILE +from homeassistant.helpers.check_config import ( + CheckConfigError, + async_check_ha_config_file, +) + from tests.common import patch_yaml_files _LOGGER = logging.getLogger(__name__) diff --git a/tests/helpers/test_config_entry_flow.py b/tests/helpers/test_config_entry_flow.py index 3c3d1224e123..1c292e5ed481 100644 --- a/tests/helpers/test_config_entry_flow.py +++ b/tests/helpers/test_config_entry_flow.py @@ -1,16 +1,17 @@ """Tests for the Config Entry Flow helper.""" -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch import pytest from homeassistant import config_entries, data_entry_flow, setup from homeassistant.helpers import config_entry_flow + from tests.common import ( MockConfigEntry, MockModule, mock_coro, - mock_integration, mock_entity_platform, + mock_integration, ) diff --git a/tests/helpers/test_config_entry_oauth2_flow.py b/tests/helpers/test_config_entry_oauth2_flow.py index 773dfa09375d..366c295874d1 100644 --- a/tests/helpers/test_config_entry_oauth2_flow.py +++ b/tests/helpers/test_config_entry_oauth2_flow.py @@ -1,15 +1,15 @@ """Tests for the Somfy config flow.""" import asyncio import logging -from unittest.mock import patch import time +from unittest.mock import patch import pytest -from homeassistant import data_entry_flow, setup, config_entries +from homeassistant import config_entries, data_entry_flow, setup from homeassistant.helpers import config_entry_oauth2_flow -from tests.common import mock_platform, MockConfigEntry +from tests.common import MockConfigEntry, mock_platform TEST_DOMAIN = "oauth2_test" CLIENT_SECRET = "5678" diff --git a/tests/helpers/test_deprecation.py b/tests/helpers/test_deprecation.py index d0cb0eca55ab..38410c3bf0fd 100644 --- a/tests/helpers/test_deprecation.py +++ b/tests/helpers/test_deprecation.py @@ -1,7 +1,7 @@ """Test deprecation helpers.""" -from homeassistant.helpers.deprecation import deprecated_substitute, get_deprecated +from unittest.mock import MagicMock, patch -from unittest.mock import patch, MagicMock +from homeassistant.helpers.deprecation import deprecated_substitute, get_deprecated class MockBaseClass: diff --git a/tests/helpers/test_device_registry.py b/tests/helpers/test_device_registry.py index 1b146e9cb129..3846230e6d35 100644 --- a/tests/helpers/test_device_registry.py +++ b/tests/helpers/test_device_registry.py @@ -7,7 +7,8 @@ import pytest from homeassistant.core import callback from homeassistant.helpers import device_registry -from tests.common import mock_device_registry, flush_store + +from tests.common import flush_store, mock_device_registry @pytest.fixture diff --git a/tests/helpers/test_discovery.py b/tests/helpers/test_discovery.py index dbd837eb5c7a..3b0996d676a2 100644 --- a/tests/helpers/test_discovery.py +++ b/tests/helpers/test_discovery.py @@ -9,12 +9,12 @@ from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import discovery from tests.common import ( - get_test_home_assistant, MockModule, MockPlatform, + get_test_home_assistant, mock_coro, - mock_integration, mock_entity_platform, + mock_integration, ) diff --git a/tests/helpers/test_dispatcher.py b/tests/helpers/test_dispatcher.py index 789cb6c1dc8b..4cf266e88a26 100644 --- a/tests/helpers/test_dispatcher.py +++ b/tests/helpers/test_dispatcher.py @@ -4,8 +4,8 @@ import asyncio from homeassistant.core import callback from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, - dispatcher_send, dispatcher_connect, + dispatcher_send, ) from tests.common import get_test_home_assistant diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index cd852f5bfc06..749c11ff1a50 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -1,16 +1,16 @@ """Test the entity helper.""" # pylint: disable=protected-access import asyncio -import threading from datetime import timedelta -from unittest.mock import MagicMock, patch, PropertyMock +import threading +from unittest.mock import MagicMock, PropertyMock, patch import pytest -from homeassistant.helpers import entity, entity_registry -from homeassistant.core import Context -from homeassistant.const import ATTR_HIDDEN, ATTR_DEVICE_CLASS, STATE_UNAVAILABLE from homeassistant.config import DATA_CUSTOMIZE +from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_HIDDEN, STATE_UNAVAILABLE +from homeassistant.core import Context +from homeassistant.helpers import entity, entity_registry from homeassistant.helpers.entity_values import EntityValues from tests.common import get_test_home_assistant, mock_registry diff --git a/tests/helpers/test_entity_component.py b/tests/helpers/test_entity_component.py index 350aa88b6af2..81fbe2d65200 100644 --- a/tests/helpers/test_entity_component.py +++ b/tests/helpers/test_entity_component.py @@ -1,30 +1,29 @@ """The tests for the Entity component helper.""" # pylint: disable=protected-access from collections import OrderedDict -import logging -from unittest.mock import patch, Mock from datetime import timedelta +import logging +from unittest.mock import Mock, patch import asynctest import pytest -import homeassistant.core as ha -from homeassistant.const import ENTITY_MATCH_ALL -from homeassistant.exceptions import PlatformNotReady from homeassistant.components import group +from homeassistant.const import ENTITY_MATCH_ALL +import homeassistant.core as ha +from homeassistant.exceptions import PlatformNotReady +from homeassistant.helpers import discovery from homeassistant.helpers.entity_component import EntityComponent from homeassistant.setup import async_setup_component - -from homeassistant.helpers import discovery import homeassistant.util.dt as dt_util from tests.common import ( - MockPlatform, - MockModule, - mock_coro, - async_fire_time_changed, - MockEntity, MockConfigEntry, + MockEntity, + MockModule, + MockPlatform, + async_fire_time_changed, + mock_coro, mock_entity_platform, mock_integration, ) diff --git a/tests/helpers/test_entity_platform.py b/tests/helpers/test_entity_platform.py index caf8bb702afe..5909dfaf3aaa 100644 --- a/tests/helpers/test_entity_platform.py +++ b/tests/helpers/test_entity_platform.py @@ -1,30 +1,29 @@ """Tests for the EntityPlatform helper.""" import asyncio -import logging -from unittest.mock import patch, Mock, MagicMock from datetime import timedelta +import logging +from unittest.mock import MagicMock, Mock, patch import asynctest import pytest from homeassistant.exceptions import PlatformNotReady +from homeassistant.helpers import entity_platform, entity_registry from homeassistant.helpers.entity import async_generate_entity_id from homeassistant.helpers.entity_component import ( - EntityComponent, DEFAULT_SCAN_INTERVAL, + EntityComponent, ) -from homeassistant.helpers import entity_platform, entity_registry - import homeassistant.util.dt as dt_util from tests.common import ( - MockPlatform, - async_fire_time_changed, - mock_registry, + MockConfigEntry, MockEntity, MockEntityPlatform, - MockConfigEntry, + MockPlatform, + async_fire_time_changed, mock_entity_platform, + mock_registry, ) _LOGGER = logging.getLogger(__name__) diff --git a/tests/helpers/test_entity_registry.py b/tests/helpers/test_entity_registry.py index 9debbdbcba7c..b07c5237116b 100644 --- a/tests/helpers/test_entity_registry.py +++ b/tests/helpers/test_entity_registry.py @@ -5,11 +5,10 @@ from unittest.mock import patch import asynctest import pytest -from homeassistant.core import valid_entity_id, callback +from homeassistant.core import callback, valid_entity_id from homeassistant.helpers import entity_registry -from tests.common import MockConfigEntry, mock_registry, flush_store - +from tests.common import MockConfigEntry, flush_store, mock_registry YAML__OPEN_PATH = "homeassistant.util.yaml.loader.open" diff --git a/tests/helpers/test_entity_values.py b/tests/helpers/test_entity_values.py index d9be6c52b4e1..f5ad68ee2316 100644 --- a/tests/helpers/test_entity_values.py +++ b/tests/helpers/test_entity_values.py @@ -1,5 +1,6 @@ """Test the entity values helper.""" from collections import OrderedDict + from homeassistant.helpers.entity_values import EntityValues as EV ent = "test.test" diff --git a/tests/helpers/test_entityfilter.py b/tests/helpers/test_entityfilter.py index 8deea67ac169..726e6bd92d0e 100644 --- a/tests/helpers/test_entityfilter.py +++ b/tests/helpers/test_entityfilter.py @@ -1,5 +1,5 @@ """The tests for the EntityFilter component.""" -from homeassistant.helpers.entityfilter import generate_filter, FILTER_SCHEMA +from homeassistant.helpers.entityfilter import FILTER_SCHEMA, generate_filter def test_no_filters_case_1(): diff --git a/tests/helpers/test_event.py b/tests/helpers/test_event.py index 3d4804e5079f..d331da5d92d2 100644 --- a/tests/helpers/test_event.py +++ b/tests/helpers/test_event.py @@ -7,10 +7,10 @@ from unittest.mock import patch from astral import Astral import pytest -from homeassistant.core import callback -from homeassistant.setup import async_setup_component -import homeassistant.core as ha +from homeassistant.components import sun from homeassistant.const import MATCH_ALL +import homeassistant.core as ha +from homeassistant.core import callback from homeassistant.helpers.event import ( async_call_later, async_track_point_in_time, @@ -25,7 +25,7 @@ from homeassistant.helpers.event import ( async_track_utc_time_change, ) from homeassistant.helpers.template import Template -from homeassistant.components import sun +from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util from tests.common import async_fire_time_changed diff --git a/tests/helpers/test_intent.py b/tests/helpers/test_intent.py index 3988c86f5169..bbb6e394ee06 100644 --- a/tests/helpers/test_intent.py +++ b/tests/helpers/test_intent.py @@ -1,11 +1,10 @@ """Tests for the intent helpers.""" +import pytest import voluptuous as vol -import pytest - from homeassistant.core import State -from homeassistant.helpers import intent, config_validation as cv +from homeassistant.helpers import config_validation as cv, intent class MockIntentHandler(intent.IntentHandler): diff --git a/tests/helpers/test_network.py b/tests/helpers/test_network.py index afb9e88c5a49..d4c5366b8794 100644 --- a/tests/helpers/test_network.py +++ b/tests/helpers/test_network.py @@ -1,8 +1,8 @@ """Test network helper.""" from unittest.mock import Mock, patch -from homeassistant.helpers import network from homeassistant.components import cloud +from homeassistant.helpers import network async def test_get_external_url(hass): diff --git a/tests/helpers/test_restore_state.py b/tests/helpers/test_restore_state.py index 94a17697eb40..97004362d200 100644 --- a/tests/helpers/test_restore_state.py +++ b/tests/helpers/test_restore_state.py @@ -8,15 +8,14 @@ from homeassistant.core import CoreState, State from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity import Entity from homeassistant.helpers.restore_state import ( - RestoreStateData, - RestoreEntity, - StoredState, DATA_RESTORE_STATE_TASK, STORAGE_KEY, + RestoreEntity, + RestoreStateData, + StoredState, ) from homeassistant.util import dt as dt_util - from tests.common import mock_coro diff --git a/tests/helpers/test_script.py b/tests/helpers/test_script.py index 4b8be715f37c..a7fe2c252368 100644 --- a/tests/helpers/test_script.py +++ b/tests/helpers/test_script.py @@ -6,21 +6,19 @@ from unittest import mock import asynctest import jinja2 -import voluptuous as vol import pytest - -import homeassistant.components.scene as scene -from homeassistant import exceptions -from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON -from homeassistant.core import Context, callback +import voluptuous as vol # Otherwise can't test just this file (import order issue) +from homeassistant import exceptions +import homeassistant.components.scene as scene +from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON +from homeassistant.core import Context, callback +from homeassistant.helpers import config_validation as cv, script import homeassistant.util.dt as dt_util -from homeassistant.helpers import script, config_validation as cv from tests.common import async_fire_time_changed - ENTITY_ID = "script.test" diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index 20be7db42f54..2697c59b787b 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -5,28 +5,29 @@ from copy import deepcopy import unittest from unittest.mock import Mock, patch -import voluptuous as vol import pytest +import voluptuous as vol # To prevent circular import when running just this file -import homeassistant.components # noqa: F401 from homeassistant import core as ha, exceptions -from homeassistant.const import STATE_ON, STATE_OFF, ATTR_ENTITY_ID, ENTITY_MATCH_ALL -from homeassistant.setup import async_setup_component -import homeassistant.helpers.config_validation as cv from homeassistant.auth.permissions import PolicyPermissions +import homeassistant.components # noqa: F401 +from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, STATE_OFF, STATE_ON from homeassistant.helpers import ( - service, - template, device_registry as dev_reg, entity_registry as ent_reg, + service, + template, ) +import homeassistant.helpers.config_validation as cv +from homeassistant.setup import async_setup_component + from tests.common import ( get_test_home_assistant, - mock_service, mock_coro, - mock_registry, mock_device_registry, + mock_registry, + mock_service, ) diff --git a/tests/helpers/test_state.py b/tests/helpers/test_state.py index 14bcbde50949..567bac65f5ba 100644 --- a/tests/helpers/test_state.py +++ b/tests/helpers/test_state.py @@ -5,21 +5,22 @@ from unittest.mock import patch import pytest -import homeassistant.core as ha -from homeassistant.const import SERVICE_TURN_ON, SERVICE_TURN_OFF -from homeassistant.util import dt as dt_util -from homeassistant.helpers import state -from homeassistant.const import ( - STATE_OPEN, - STATE_CLOSED, - STATE_LOCKED, - STATE_UNLOCKED, - STATE_ON, - STATE_OFF, - STATE_HOME, - STATE_NOT_HOME, -) from homeassistant.components.sun import STATE_ABOVE_HORIZON, STATE_BELOW_HORIZON +from homeassistant.const import ( + SERVICE_TURN_OFF, + SERVICE_TURN_ON, + STATE_CLOSED, + STATE_HOME, + STATE_LOCKED, + STATE_NOT_HOME, + STATE_OFF, + STATE_ON, + STATE_OPEN, + STATE_UNLOCKED, +) +import homeassistant.core as ha +from homeassistant.helpers import state +from homeassistant.util import dt as dt_util from tests.common import async_mock_service diff --git a/tests/helpers/test_storage.py b/tests/helpers/test_storage.py index 87a22fcb845b..2fef58ad1156 100644 --- a/tests/helpers/test_storage.py +++ b/tests/helpers/test_storage.py @@ -2,7 +2,7 @@ import asyncio from datetime import timedelta import json -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch import pytest @@ -12,7 +12,6 @@ from homeassistant.util import dt from tests.common import async_fire_time_changed, mock_coro - MOCK_VERSION = 1 MOCK_KEY = "storage-test" MOCK_DATA = {"hello": "world"} diff --git a/tests/helpers/test_sun.py b/tests/helpers/test_sun.py index 1746c7e6fc02..b8ecd1ed86aa 100644 --- a/tests/helpers/test_sun.py +++ b/tests/helpers/test_sun.py @@ -1,11 +1,11 @@ """The tests for the Sun helpers.""" # pylint: disable=protected-access +from datetime import datetime, timedelta from unittest.mock import patch -from datetime import timedelta, datetime from homeassistant.const import SUN_EVENT_SUNRISE, SUN_EVENT_SUNSET -import homeassistant.util.dt as dt_util import homeassistant.helpers.sun as sun +import homeassistant.util.dt as dt_util def test_next_events(hass): diff --git a/tests/helpers/test_temperature.py b/tests/helpers/test_temperature.py index 840e6fd5d9d0..5808b6611506 100644 --- a/tests/helpers/test_temperature.py +++ b/tests/helpers/test_temperature.py @@ -2,11 +2,11 @@ import pytest from homeassistant.const import ( - TEMP_CELSIUS, - PRECISION_WHOLE, - TEMP_FAHRENHEIT, PRECISION_HALVES, PRECISION_TENTHS, + PRECISION_WHOLE, + TEMP_CELSIUS, + TEMP_FAHRENHEIT, ) from homeassistant.helpers.temperature import display_temp diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index f463149bc282..cbd530d0b4c4 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -1,13 +1,12 @@ """Test Home Assistant template helper methods.""" +from datetime import datetime import math import random -from datetime import datetime from unittest.mock import patch import pytest import pytz -import homeassistant.util.dt as dt_util from homeassistant.components import group from homeassistant.const import ( LENGTH_METERS, @@ -19,6 +18,7 @@ from homeassistant.const import ( ) from homeassistant.exceptions import TemplateError from homeassistant.helpers import template +import homeassistant.util.dt as dt_util from homeassistant.util.unit_system import UnitSystem diff --git a/tests/helpers/test_translation.py b/tests/helpers/test_translation.py index 1c3748250a5f..6b846703914e 100644 --- a/tests/helpers/test_translation.py +++ b/tests/helpers/test_translation.py @@ -5,9 +5,10 @@ from unittest.mock import patch import pytest +from homeassistant.generated import config_flows import homeassistant.helpers.translation as translation from homeassistant.setup import async_setup_component -from homeassistant.generated import config_flows + from tests.common import mock_coro diff --git a/tests/scripts/test_auth.py b/tests/scripts/test_auth.py index f762630a42a9..3ab194508793 100644 --- a/tests/scripts/test_auth.py +++ b/tests/scripts/test_auth.py @@ -3,8 +3,8 @@ from unittest.mock import Mock, patch import pytest -from homeassistant.scripts import auth as script_auth from homeassistant.auth.providers import homeassistant as hass_auth +from homeassistant.scripts import auth as script_auth from tests.common import register_auth_provider diff --git a/tests/scripts/test_check_config.py b/tests/scripts/test_check_config.py index 8e1ffe63e845..481efc6fb302 100644 --- a/tests/scripts/test_check_config.py +++ b/tests/scripts/test_check_config.py @@ -2,8 +2,9 @@ import logging from unittest.mock import patch -import homeassistant.scripts.check_config as check_config from homeassistant.config import YAML_CONFIG_FILE +import homeassistant.scripts.check_config as check_config + from tests.common import get_test_config_dir, patch_yaml_files _LOGGER = logging.getLogger(__name__) diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index eaabd61af4b8..f71be8fe9b1b 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -1,20 +1,20 @@ """Test the bootstrapping.""" # pylint: disable=protected-access import asyncio +import logging import os from unittest.mock import Mock, patch -import logging -import homeassistant.config as config_util from homeassistant import bootstrap +import homeassistant.config as config_util import homeassistant.util.dt as dt_util from tests.common import ( - patch_yaml_files, + MockModule, get_test_config_dir, mock_coro, mock_integration, - MockModule, + patch_yaml_files, ) ORIG_TIMEZONE = dt_util.DEFAULT_TIME_ZONE diff --git a/tests/test_config.py b/tests/test_config.py index 1c872369096c..1abb6ec7ff1a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,39 +1,39 @@ """Test config utils.""" # pylint: disable=protected-access import asyncio +from collections import OrderedDict import copy import os import unittest.mock as mock -from collections import OrderedDict import asynctest import pytest -from voluptuous import MultipleInvalid, Invalid +from voluptuous import Invalid, MultipleInvalid import yaml -from homeassistant.core import SOURCE_STORAGE, HomeAssistantError import homeassistant.config as config_util -from homeassistant.loader import async_get_integration from homeassistant.const import ( + ATTR_ASSUMED_STATE, ATTR_FRIENDLY_NAME, ATTR_HIDDEN, - ATTR_ASSUMED_STATE, + CONF_AUTH_MFA_MODULES, + CONF_AUTH_PROVIDERS, + CONF_CUSTOMIZE, CONF_LATITUDE, CONF_LONGITUDE, - CONF_UNIT_SYSTEM, CONF_NAME, - CONF_CUSTOMIZE, - __version__, - CONF_UNIT_SYSTEM_METRIC, - CONF_UNIT_SYSTEM_IMPERIAL, CONF_TEMPERATURE_UNIT, - CONF_AUTH_PROVIDERS, - CONF_AUTH_MFA_MODULES, + CONF_UNIT_SYSTEM, + CONF_UNIT_SYSTEM_IMPERIAL, + CONF_UNIT_SYSTEM_METRIC, + __version__, ) +from homeassistant.core import SOURCE_STORAGE, HomeAssistantError +import homeassistant.helpers.check_config as check_config +from homeassistant.helpers.entity import Entity +from homeassistant.loader import async_get_integration from homeassistant.util import dt as dt_util from homeassistant.util.yaml import SECRET_YAML -from homeassistant.helpers.entity import Entity -import homeassistant.helpers.check_config as check_config from tests.common import get_test_config_dir, patch_yaml_files diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index d9dd614c9a5e..24a0b0939bef 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -12,14 +12,14 @@ from homeassistant.setup import async_setup_component from homeassistant.util import dt from tests.common import ( - MockModule, - mock_coro, MockConfigEntry, - async_fire_time_changed, - MockPlatform, MockEntity, - mock_integration, + MockModule, + MockPlatform, + async_fire_time_changed, + mock_coro, mock_entity_platform, + mock_integration, mock_registry, ) diff --git a/tests/test_core.py b/tests/test_core.py index 5ac13027f288..1999065e31dc 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,40 +1,40 @@ """Test to verify that Home Assistant core works.""" # pylint: disable=protected-access import asyncio +from datetime import datetime, timedelta import functools import logging import os -import unittest -from unittest.mock import patch, MagicMock -from datetime import datetime, timedelta from tempfile import TemporaryDirectory +import unittest +from unittest.mock import MagicMock, patch -import voluptuous as vol -import pytz import pytest +import pytz +import voluptuous as vol +from homeassistant.const import ( + ATTR_FRIENDLY_NAME, + ATTR_NOW, + ATTR_SECONDS, + CONF_UNIT_SYSTEM, + EVENT_CALL_SERVICE, + EVENT_CORE_CONFIG_UPDATE, + EVENT_HOMEASSISTANT_CLOSE, + EVENT_HOMEASSISTANT_STOP, + EVENT_SERVICE_REGISTERED, + EVENT_SERVICE_REMOVED, + EVENT_STATE_CHANGED, + EVENT_TIME_CHANGED, + EVENT_TIMER_OUT_OF_SYNC, + __version__, +) import homeassistant.core as ha from homeassistant.exceptions import InvalidEntityFormatError, InvalidStateError import homeassistant.util.dt as dt_util from homeassistant.util.unit_system import METRIC_SYSTEM -from homeassistant.const import ( - __version__, - EVENT_STATE_CHANGED, - ATTR_FRIENDLY_NAME, - CONF_UNIT_SYSTEM, - ATTR_NOW, - EVENT_TIME_CHANGED, - EVENT_TIMER_OUT_OF_SYNC, - ATTR_SECONDS, - EVENT_HOMEASSISTANT_STOP, - EVENT_HOMEASSISTANT_CLOSE, - EVENT_SERVICE_REGISTERED, - EVENT_SERVICE_REMOVED, - EVENT_CALL_SERVICE, - EVENT_CORE_CONFIG_UPDATE, -) -from tests.common import get_test_home_assistant, async_mock_service +from tests.common import async_mock_service, get_test_home_assistant PST = pytz.timezone("America/Los_Angeles") diff --git a/tests/test_loader.py b/tests/test_loader.py index e7011997f736..f3e7c3bd884f 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -2,9 +2,9 @@ from asynctest.mock import ANY, patch import pytest -import homeassistant.loader as loader from homeassistant.components import http, hue from homeassistant.components.hue import light as hue_light +import homeassistant.loader as loader from tests.common import MockModule, async_mock_service, mock_integration diff --git a/tests/test_main.py b/tests/test_main.py index 29454d269af4..5ec6460301f1 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,5 +1,5 @@ """Test methods in __main__.""" -from unittest.mock import patch, PropertyMock +from unittest.mock import PropertyMock, patch from homeassistant import __main__ as main from homeassistant.const import REQUIRED_PYTHON_VER diff --git a/tests/test_requirements.py b/tests/test_requirements.py index 2627a077a87c..b807188e8a52 100644 --- a/tests/test_requirements.py +++ b/tests/test_requirements.py @@ -1,20 +1,21 @@ """Test requirements module.""" import os from pathlib import Path -from unittest.mock import patch, call +from unittest.mock import call, patch + from pytest import raises from homeassistant import setup from homeassistant.requirements import ( CONSTRAINT_FILE, + PROGRESS_FILE, + RequirementsNotFound, + _install, async_get_integration_with_requirements, async_process_requirements, - PROGRESS_FILE, - _install, - RequirementsNotFound, ) -from tests.common import get_test_home_assistant, MockModule, mock_integration +from tests.common import MockModule, get_test_home_assistant, mock_integration def env_without_wheel_links(): diff --git a/tests/test_setup.py b/tests/test_setup.py index 8fd25091eb68..c19d92db4b66 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -1,32 +1,32 @@ """Test component/platform setup.""" # pylint: disable=protected-access import asyncio -import os -from unittest import mock -import threading import logging +import os +import threading +from unittest import mock import voluptuous as vol -from homeassistant.core import callback -from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_COMPONENT_LOADED -import homeassistant.config as config_util from homeassistant import setup -import homeassistant.util.dt as dt_util +import homeassistant.config as config_util +from homeassistant.const import EVENT_COMPONENT_LOADED, EVENT_HOMEASSISTANT_START +from homeassistant.core import callback +from homeassistant.helpers import discovery from homeassistant.helpers.config_validation import ( PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE, ) -from homeassistant.helpers import discovery +import homeassistant.util.dt as dt_util from tests.common import ( - get_test_home_assistant, MockModule, MockPlatform, assert_setup_component, get_test_config_dir, - mock_integration, + get_test_home_assistant, mock_entity_platform, + mock_integration, ) ORIG_TIMEZONE = dt_util.DEFAULT_TIME_ZONE diff --git a/tests/test_util/aiohttp.py b/tests/test_util/aiohttp.py index ce13ca5a594a..e0e1ded32c33 100644 --- a/tests/test_util/aiohttp.py +++ b/tests/test_util/aiohttp.py @@ -7,11 +7,10 @@ from unittest import mock from urllib.parse import parse_qs from aiohttp import ClientSession +from aiohttp.client_exceptions import ClientResponseError from aiohttp.streams import StreamReader from yarl import URL -from aiohttp.client_exceptions import ClientResponseError - from homeassistant.const import EVENT_HOMEASSISTANT_CLOSE retype = type(re.compile("")) diff --git a/tests/test_util/test_aiohttp.py b/tests/test_util/test_aiohttp.py index 0a0ead54dcaa..2761f5b9ea39 100644 --- a/tests/test_util/test_aiohttp.py +++ b/tests/test_util/test_aiohttp.py @@ -1,8 +1,8 @@ """Tests for our aiohttp mocker.""" -from .aiohttp import AiohttpClientMocker - import pytest +from .aiohttp import AiohttpClientMocker + async def test_matching_url(): """Test we can match urls.""" diff --git a/tests/testing_config/custom_components/test/alarm_control_panel.py b/tests/testing_config/custom_components/test/alarm_control_panel.py index 1ffa52086e7b..065ea3e39807 100644 --- a/tests/testing_config/custom_components/test/alarm_control_panel.py +++ b/tests/testing_config/custom_components/test/alarm_control_panel.py @@ -4,6 +4,12 @@ Provide a mock alarm_control_panel platform. Call init before using it in your tests to ensure clean test data. """ from homeassistant.components.alarm_control_panel import AlarmControlPanel +from homeassistant.components.alarm_control_panel.const import ( + SUPPORT_ALARM_ARM_AWAY, + SUPPORT_ALARM_ARM_HOME, + SUPPORT_ALARM_ARM_NIGHT, + SUPPORT_ALARM_TRIGGER, +) from homeassistant.const import ( STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, @@ -11,12 +17,7 @@ from homeassistant.const import ( STATE_ALARM_DISARMED, STATE_ALARM_TRIGGERED, ) -from homeassistant.components.alarm_control_panel.const import ( - SUPPORT_ALARM_ARM_HOME, - SUPPORT_ALARM_ARM_AWAY, - SUPPORT_ALARM_ARM_NIGHT, - SUPPORT_ALARM_TRIGGER, -) + from tests.common import MockEntity ENTITIES = {} diff --git a/tests/testing_config/custom_components/test/binary_sensor.py b/tests/testing_config/custom_components/test/binary_sensor.py index 5052b8e47f10..bcff0adb4e48 100644 --- a/tests/testing_config/custom_components/test/binary_sensor.py +++ b/tests/testing_config/custom_components/test/binary_sensor.py @@ -3,9 +3,9 @@ Provide a mock binary sensor platform. Call init before using it in your tests to ensure clean test data. """ -from homeassistant.components.binary_sensor import BinarySensorDevice, DEVICE_CLASSES -from tests.common import MockEntity +from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorDevice +from tests.common import MockEntity ENTITIES = {} diff --git a/tests/testing_config/custom_components/test/cover.py b/tests/testing_config/custom_components/test/cover.py index d7c771e2b282..ce5462790bb6 100644 --- a/tests/testing_config/custom_components/test/cover.py +++ b/tests/testing_config/custom_components/test/cover.py @@ -4,8 +4,8 @@ Provide a mock cover platform. Call init before using it in your tests to ensure clean test data. """ from homeassistant.components.cover import CoverDevice -from tests.common import MockEntity +from tests.common import MockEntity ENTITIES = {} diff --git a/tests/testing_config/custom_components/test/light.py b/tests/testing_config/custom_components/test/light.py index 0a48388b718b..4b018adb5cbd 100644 --- a/tests/testing_config/custom_components/test/light.py +++ b/tests/testing_config/custom_components/test/light.py @@ -3,9 +3,9 @@ Provide a mock light platform. Call init before using it in your tests to ensure clean test data. """ -from homeassistant.const import STATE_ON, STATE_OFF -from tests.common import MockToggleEntity +from homeassistant.const import STATE_OFF, STATE_ON +from tests.common import MockToggleEntity ENTITIES = [] diff --git a/tests/testing_config/custom_components/test/lock.py b/tests/testing_config/custom_components/test/lock.py index db6ce38b097a..24b04903541a 100644 --- a/tests/testing_config/custom_components/test/lock.py +++ b/tests/testing_config/custom_components/test/lock.py @@ -3,7 +3,8 @@ Provide a mock lock platform. Call init before using it in your tests to ensure clean test data. """ -from homeassistant.components.lock import LockDevice, SUPPORT_OPEN +from homeassistant.components.lock import SUPPORT_OPEN, LockDevice + from tests.common import MockEntity ENTITIES = {} diff --git a/tests/testing_config/custom_components/test/sensor.py b/tests/testing_config/custom_components/test/sensor.py index 651ee17bd65d..26497b16a165 100644 --- a/tests/testing_config/custom_components/test/sensor.py +++ b/tests/testing_config/custom_components/test/sensor.py @@ -4,8 +4,8 @@ Provide a mock sensor platform. Call init before using it in your tests to ensure clean test data. """ import homeassistant.components.sensor as sensor -from tests.common import MockEntity +from tests.common import MockEntity DEVICE_CLASSES = list(sensor.DEVICE_CLASSES) DEVICE_CLASSES.append("none") diff --git a/tests/testing_config/custom_components/test/switch.py b/tests/testing_config/custom_components/test/switch.py index 484c47d1190e..7dd1862d88f0 100644 --- a/tests/testing_config/custom_components/test/switch.py +++ b/tests/testing_config/custom_components/test/switch.py @@ -3,9 +3,9 @@ Provide a mock switch platform. Call init before using it in your tests to ensure clean test data. """ -from homeassistant.const import STATE_ON, STATE_OFF -from tests.common import MockToggleEntity +from homeassistant.const import STATE_OFF, STATE_ON +from tests.common import MockToggleEntity ENTITIES = [] diff --git a/tests/testing_config/custom_components/test_package/__init__.py b/tests/testing_config/custom_components/test_package/__init__.py index f5cd2c34edfd..44f62380c92c 100644 --- a/tests/testing_config/custom_components/test_package/__init__.py +++ b/tests/testing_config/custom_components/test_package/__init__.py @@ -1,7 +1,6 @@ """Provide a mock package component.""" from .const import TEST # noqa: F401 - DOMAIN = "test_package" diff --git a/tests/util/test_async.py b/tests/util/test_async.py index 9cda40c1b8b4..ec16fa2ae67e 100644 --- a/tests/util/test_async.py +++ b/tests/util/test_async.py @@ -1,8 +1,8 @@ """Tests for async util methods from Python source.""" import asyncio import sys -from unittest.mock import MagicMock, patch from unittest import TestCase +from unittest.mock import MagicMock, patch import pytest diff --git a/tests/util/test_distance.py b/tests/util/test_distance.py index 581257d6f49d..27b77a883c78 100644 --- a/tests/util/test_distance.py +++ b/tests/util/test_distance.py @@ -2,13 +2,13 @@ import pytest -import homeassistant.util.distance as distance_util from homeassistant.const import ( + LENGTH_FEET, LENGTH_KILOMETERS, LENGTH_METERS, - LENGTH_FEET, LENGTH_MILES, ) +import homeassistant.util.distance as distance_util INVALID_SYMBOL = "bob" VALID_SYMBOL = LENGTH_KILOMETERS diff --git a/tests/util/test_init.py b/tests/util/test_init.py index 261280cc20e2..2ffca07082bc 100644 --- a/tests/util/test_init.py +++ b/tests/util/test_init.py @@ -1,6 +1,6 @@ """Test Home Assistant util methods.""" -from unittest.mock import patch, MagicMock from datetime import datetime, timedelta +from unittest.mock import MagicMock, patch import pytest diff --git a/tests/util/test_json.py b/tests/util/test_json.py index bec3230c01ea..26245482c2f3 100644 --- a/tests/util/test_json.py +++ b/tests/util/test_json.py @@ -1,16 +1,15 @@ """Test Home Assistant json utility functions.""" from json import JSONEncoder import os -import unittest -from unittest.mock import Mock import sys from tempfile import mkdtemp +import unittest +from unittest.mock import Mock import pytest -from homeassistant.util.json import SerializationError, load_json, save_json from homeassistant.exceptions import HomeAssistantError - +from homeassistant.util.json import SerializationError, load_json, save_json # Test data that can be saved as JSON TEST_JSON_A = {"a": 1, "B": "two"} diff --git a/tests/util/test_location.py b/tests/util/test_location.py index 4908018410b5..6dd6eafca1dd 100644 --- a/tests/util/test_location.py +++ b/tests/util/test_location.py @@ -1,5 +1,5 @@ """Test Home Assistant location util methods.""" -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch import aiohttp import pytest diff --git a/tests/util/test_package.py b/tests/util/test_package.py index 79676cbfcd99..ca4ed83734a3 100644 --- a/tests/util/test_package.py +++ b/tests/util/test_package.py @@ -2,8 +2,8 @@ import asyncio import logging import os -import sys from subprocess import PIPE +import sys from unittest.mock import MagicMock, call, patch import pkg_resources @@ -11,7 +11,6 @@ import pytest import homeassistant.util.package as package - RESOURCE_DIR = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "resources") ) diff --git a/tests/util/test_pressure.py b/tests/util/test_pressure.py index 18fa238e43b2..df65618dc484 100644 --- a/tests/util/test_pressure.py +++ b/tests/util/test_pressure.py @@ -2,10 +2,10 @@ import pytest from homeassistant.const import ( - PRESSURE_PA, PRESSURE_HPA, - PRESSURE_MBAR, PRESSURE_INHG, + PRESSURE_MBAR, + PRESSURE_PA, PRESSURE_PSI, ) import homeassistant.util.pressure as pressure_util diff --git a/tests/util/test_ruamel_yaml.py b/tests/util/test_ruamel_yaml.py index 9ae806f31ea7..79ed4a4f4d11 100644 --- a/tests/util/test_ruamel_yaml.py +++ b/tests/util/test_ruamel_yaml.py @@ -1,14 +1,13 @@ """Test Home Assistant ruamel.yaml loader.""" import os from tempfile import mkdtemp -import pytest +import pytest from ruamel.yaml import YAML from homeassistant.exceptions import HomeAssistantError import homeassistant.util.ruamel_yaml as util_yaml - TEST_YAML_A = """\ title: My Awesome Home # Include external resources diff --git a/tests/util/test_unit_system.py b/tests/util/test_unit_system.py index 827143bc4475..e0e4524a2f2e 100644 --- a/tests/util/test_unit_system.py +++ b/tests/util/test_unit_system.py @@ -1,20 +1,20 @@ """Test the unit system helper.""" import pytest -from homeassistant.util.unit_system import UnitSystem, METRIC_SYSTEM, IMPERIAL_SYSTEM from homeassistant.const import ( - LENGTH_METERS, - LENGTH_KILOMETERS, - MASS_GRAMS, - PRESSURE_PA, - VOLUME_LITERS, - TEMP_CELSIUS, LENGTH, + LENGTH_KILOMETERS, + LENGTH_METERS, MASS, + MASS_GRAMS, PRESSURE, + PRESSURE_PA, + TEMP_CELSIUS, TEMPERATURE, VOLUME, + VOLUME_LITERS, ) +from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM, UnitSystem SYSTEM_NAME = "TEST" INVALID_UNIT = "INVALID" diff --git a/tests/util/test_volume.py b/tests/util/test_volume.py index 4bf9b7c075d0..9bd3e4b1a98e 100644 --- a/tests/util/test_volume.py +++ b/tests/util/test_volume.py @@ -2,13 +2,13 @@ import pytest -import homeassistant.util.volume as volume_util from homeassistant.const import ( + VOLUME_FLUID_OUNCE, + VOLUME_GALLONS, VOLUME_LITERS, VOLUME_MILLILITERS, - VOLUME_GALLONS, - VOLUME_FLUID_OUNCE, ) +import homeassistant.util.volume as volume_util INVALID_SYMBOL = "bob" VALID_SYMBOL = VOLUME_LITERS diff --git a/tests/util/test_yaml.py b/tests/util/test_yaml.py index 1e5797e33e7c..ba31ce57010d 100644 --- a/tests/util/test_yaml.py +++ b/tests/util/test_yaml.py @@ -1,16 +1,17 @@ """Test Home Assistant yaml loader.""" import io +import logging import os import unittest -import logging from unittest.mock import patch import pytest -from homeassistant.exceptions import HomeAssistantError -from homeassistant.util.yaml import loader as yaml_loader -import homeassistant.util.yaml as yaml from homeassistant.config import YAML_CONFIG_FILE, load_yaml_config_file +from homeassistant.exceptions import HomeAssistantError +import homeassistant.util.yaml as yaml +from homeassistant.util.yaml import loader as yaml_loader + from tests.common import get_test_config_dir, patch_yaml_files