Skip to content

Commit

Permalink
Sort imports according to PEP8 for 'tests' (home-assistant#29791)
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt authored and frenck committed Dec 9, 2019
1 parent 67c56c8 commit f60125b
Show file tree
Hide file tree
Showing 68 changed files with 235 additions and 232 deletions.
1 change: 1 addition & 0 deletions tests/auth/mfa_modules/test_insecure_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion tests/auth/mfa_modules/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
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"
Expand Down
3 changes: 2 additions & 1 deletion tests/auth/mfa_modules/test_totp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
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"
Expand Down
6 changes: 3 additions & 3 deletions tests/auth/permissions/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
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():
Expand Down
2 changes: 1 addition & 1 deletion tests/auth/permissions/test_system_policies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Test system policies."""
from homeassistant.auth.permissions import (
POLICY_SCHEMA,
PolicyPermissions,
system_policies,
POLICY_SCHEMA,
)


Expand Down
4 changes: 2 additions & 2 deletions tests/auth/providers/test_command_line.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/auth/providers/test_insecure_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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
Expand Down
5 changes: 3 additions & 2 deletions tests/auth/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
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
Expand Down
32 changes: 15 additions & 17 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
"""Test the helper method for writing tests."""
import asyncio
import collections
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 uuid
import sys
import threading

from collections import OrderedDict
from contextlib import contextmanager
from datetime import timedelta
from io import StringIO
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 (
Expand All @@ -38,8 +38,8 @@
EVENT_STATE_CHANGED,
EVENT_TIME_CHANGED,
SERVER_PORT,
STATE_ON,
STATE_OFF,
STATE_ON,
)
from homeassistant.core import State
from homeassistant.helpers import (
Expand All @@ -54,12 +54,10 @@
)
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__)
Expand Down
17 changes: 9 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@
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
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/test_aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
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
Expand Down
3 changes: 2 additions & 1 deletion tests/helpers/test_area_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

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
Expand Down
5 changes: 3 additions & 2 deletions tests/helpers/test_check_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import logging
from unittest.mock import patch

from homeassistant.config import YAML_CONFIG_FILE
from homeassistant.helpers.check_config import (
async_check_ha_config_file,
CheckConfigError,
async_check_ha_config_file,
)
from homeassistant.config import YAML_CONFIG_FILE

from tests.common import patch_yaml_files

_LOGGER = logging.getLogger(__name__)
Expand Down
5 changes: 3 additions & 2 deletions tests/helpers/test_config_entry_flow.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down
6 changes: 3 additions & 3 deletions tests/helpers/test_config_entry_oauth2_flow.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/test_deprecation.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 2 additions & 1 deletion tests/helpers/test_device_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

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
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
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,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
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
Expand Down
10 changes: 5 additions & 5 deletions tests/helpers/test_entity.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 9 additions & 10 deletions tests/helpers/test_entity_component.py
Original file line number Diff line number Diff line change
@@ -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.components import group
from homeassistant.const import ENTITY_MATCH_ALL
import homeassistant.core as ha
from homeassistant.exceptions import PlatformNotReady
from homeassistant.components import group
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,
MockConfigEntry,
MockEntity,
MockModule,
mock_coro,
MockPlatform,
async_fire_time_changed,
MockEntity,
MockConfigEntry,
mock_coro,
mock_entity_platform,
mock_integration,
)
Expand Down
Loading

0 comments on commit f60125b

Please sign in to comment.