mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Fix tests for Python 3.8 (#34672)
This commit is contained in:
parent
d53cb951e7
commit
0d700f6a63
@ -1,7 +1,6 @@
|
|||||||
"""Tests for the Ambiclimate config flow."""
|
"""Tests for the Ambiclimate config flow."""
|
||||||
from unittest.mock import Mock, patch
|
|
||||||
|
|
||||||
import ambiclimate
|
import ambiclimate
|
||||||
|
from asynctest import Mock, patch
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.ambiclimate import config_flow
|
from homeassistant.components.ambiclimate import config_flow
|
||||||
|
@ -4,7 +4,8 @@ from contextlib import contextmanager
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from unittest.mock import patch
|
|
||||||
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant.components.awair.sensor import (
|
from homeassistant.components.awair.sensor import (
|
||||||
ATTR_LAST_API_UPDATE,
|
ATTR_LAST_API_UPDATE,
|
||||||
@ -28,7 +29,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util.dt import parse_datetime, utcnow
|
from homeassistant.util.dt import parse_datetime, utcnow
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed, load_fixture, mock_coro
|
from tests.common import async_fire_time_changed, load_fixture
|
||||||
|
|
||||||
DISCOVERY_CONFIG = {"sensor": {"platform": "awair", "access_token": "qwerty"}}
|
DISCOVERY_CONFIG = {"sensor": {"platform": "awair", "access_token": "qwerty"}}
|
||||||
|
|
||||||
@ -68,9 +69,9 @@ def alter_time(retval):
|
|||||||
async def setup_awair(hass, config=None, data_fixture=AIR_DATA_FIXTURE):
|
async def setup_awair(hass, config=None, data_fixture=AIR_DATA_FIXTURE):
|
||||||
"""Load the Awair platform."""
|
"""Load the Awair platform."""
|
||||||
devices_json = json.loads(load_fixture("awair_devices.json"))
|
devices_json = json.loads(load_fixture("awair_devices.json"))
|
||||||
devices_mock = mock_coro(devices_json)
|
devices_mock = devices_json
|
||||||
devices_patch = patch("python_awair.AwairClient.devices", return_value=devices_mock)
|
devices_patch = patch("python_awair.AwairClient.devices", return_value=devices_mock)
|
||||||
air_data_mock = mock_coro(data_fixture)
|
air_data_mock = data_fixture
|
||||||
air_data_patch = patch(
|
air_data_patch = patch(
|
||||||
"python_awair.AwairClient.air_data_latest", return_value=air_data_mock
|
"python_awair.AwairClient.air_data_latest", return_value=air_data_mock
|
||||||
)
|
)
|
||||||
@ -233,8 +234,7 @@ async def test_availability(hass):
|
|||||||
|
|
||||||
future = NOW + timedelta(minutes=30)
|
future = NOW + timedelta(minutes=30)
|
||||||
data_patch = patch(
|
data_patch = patch(
|
||||||
"python_awair.AwairClient.air_data_latest",
|
"python_awair.AwairClient.air_data_latest", return_value=AIR_DATA_FIXTURE,
|
||||||
return_value=mock_coro(AIR_DATA_FIXTURE),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
with data_patch, alter_time(future):
|
with data_patch, alter_time(future):
|
||||||
@ -246,9 +246,7 @@ async def test_availability(hass):
|
|||||||
future = NOW + timedelta(hours=1)
|
future = NOW + timedelta(hours=1)
|
||||||
fixture = AIR_DATA_FIXTURE_UPDATED
|
fixture = AIR_DATA_FIXTURE_UPDATED
|
||||||
fixture[0][ATTR_TIMESTAMP] = str(future)
|
fixture[0][ATTR_TIMESTAMP] = str(future)
|
||||||
data_patch = patch(
|
data_patch = patch("python_awair.AwairClient.air_data_latest", return_value=fixture)
|
||||||
"python_awair.AwairClient.air_data_latest", return_value=mock_coro(fixture)
|
|
||||||
)
|
|
||||||
|
|
||||||
with data_patch, alter_time(future):
|
with data_patch, alter_time(future):
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
@ -258,9 +256,7 @@ async def test_availability(hass):
|
|||||||
|
|
||||||
future = NOW + timedelta(minutes=90)
|
future = NOW + timedelta(minutes=90)
|
||||||
fixture = AIR_DATA_FIXTURE_EMPTY
|
fixture = AIR_DATA_FIXTURE_EMPTY
|
||||||
data_patch = patch(
|
data_patch = patch("python_awair.AwairClient.air_data_latest", return_value=fixture)
|
||||||
"python_awair.AwairClient.air_data_latest", return_value=mock_coro(fixture)
|
|
||||||
)
|
|
||||||
|
|
||||||
with data_patch, alter_time(future):
|
with data_patch, alter_time(future):
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
@ -276,7 +272,7 @@ async def test_async_update(hass):
|
|||||||
future = NOW + timedelta(minutes=10)
|
future = NOW + timedelta(minutes=10)
|
||||||
data_patch = patch(
|
data_patch = patch(
|
||||||
"python_awair.AwairClient.air_data_latest",
|
"python_awair.AwairClient.air_data_latest",
|
||||||
return_value=mock_coro(AIR_DATA_FIXTURE_UPDATED),
|
return_value=AIR_DATA_FIXTURE_UPDATED,
|
||||||
)
|
)
|
||||||
|
|
||||||
with data_patch, alter_time(future):
|
with data_patch, alter_time(future):
|
||||||
@ -300,7 +296,7 @@ async def test_throttle_async_update(hass):
|
|||||||
future = NOW + timedelta(minutes=1)
|
future = NOW + timedelta(minutes=1)
|
||||||
data_patch = patch(
|
data_patch = patch(
|
||||||
"python_awair.AwairClient.air_data_latest",
|
"python_awair.AwairClient.air_data_latest",
|
||||||
return_value=mock_coro(AIR_DATA_FIXTURE_UPDATED),
|
return_value=AIR_DATA_FIXTURE_UPDATED,
|
||||||
)
|
)
|
||||||
|
|
||||||
with data_patch, alter_time(future):
|
with data_patch, alter_time(future):
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
"""Test Axis config flow."""
|
"""Test Axis config flow."""
|
||||||
from unittest.mock import Mock, patch
|
from asynctest import Mock, patch
|
||||||
|
|
||||||
from homeassistant.components import axis
|
from homeassistant.components import axis
|
||||||
from homeassistant.components.axis import config_flow
|
from homeassistant.components.axis import config_flow
|
||||||
|
|
||||||
from .test_device import MAC, MODEL, NAME, setup_axis_integration
|
from .test_device import MAC, MODEL, NAME, setup_axis_integration
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_coro
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
def setup_mock_axis_device(mock_device):
|
def setup_mock_axis_device(mock_device):
|
||||||
@ -80,7 +80,7 @@ async def test_manual_configuration_update_configuration(hass):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.axis.config_flow.get_device",
|
"homeassistant.components.axis.config_flow.get_device",
|
||||||
return_value=mock_coro(mock_device),
|
return_value=mock_device,
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
@ -113,7 +113,7 @@ async def test_flow_fails_already_configured(hass):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.axis.config_flow.get_device",
|
"homeassistant.components.axis.config_flow.get_device",
|
||||||
return_value=mock_coro(mock_device),
|
return_value=mock_device,
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
@ -232,7 +232,7 @@ async def test_flow_create_entry_multiple_existing_entries_of_same_model(hass):
|
|||||||
|
|
||||||
async def test_zeroconf_flow(hass):
|
async def test_zeroconf_flow(hass):
|
||||||
"""Test that zeroconf discovery for new devices work."""
|
"""Test that zeroconf discovery for new devices work."""
|
||||||
with patch.object(axis, "get_device", return_value=mock_coro(Mock())):
|
with patch.object(axis, "get_device", return_value=Mock()):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN,
|
config_flow.DOMAIN,
|
||||||
data={
|
data={
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
"""The tests for the Cast Media player platform."""
|
"""The tests for the Cast Media player platform."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from unittest.mock import MagicMock, Mock, patch
|
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
|
from asynctest import MagicMock, Mock, patch
|
||||||
import attr
|
import attr
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ from homeassistant.exceptions import PlatformNotReady
|
|||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_coro
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -468,7 +468,6 @@ async def test_entry_setup_no_config(hass: HomeAssistantType):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.cast.media_player._async_setup_platform",
|
"homeassistant.components.cast.media_player._async_setup_platform",
|
||||||
return_value=mock_coro(),
|
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
||||||
|
|
||||||
@ -484,7 +483,6 @@ async def test_entry_setup_single_config(hass: HomeAssistantType):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.cast.media_player._async_setup_platform",
|
"homeassistant.components.cast.media_player._async_setup_platform",
|
||||||
return_value=mock_coro(),
|
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
||||||
|
|
||||||
@ -500,7 +498,6 @@ async def test_entry_setup_list_config(hass: HomeAssistantType):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.cast.media_player._async_setup_platform",
|
"homeassistant.components.cast.media_player._async_setup_platform",
|
||||||
return_value=mock_coro(),
|
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
||||||
|
|
||||||
@ -517,7 +514,7 @@ async def test_entry_setup_platform_not_ready(hass: HomeAssistantType):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.cast.media_player._async_setup_platform",
|
"homeassistant.components.cast.media_player._async_setup_platform",
|
||||||
return_value=mock_coro(exception=Exception),
|
side_effect=Exception,
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
with pytest.raises(PlatformNotReady):
|
with pytest.raises(PlatformNotReady):
|
||||||
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
await cast.async_setup_entry(hass, MockConfigEntry(), None)
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from time import time
|
from time import time
|
||||||
from unittest.mock import Mock, patch
|
|
||||||
|
|
||||||
|
from asynctest import CoroutineMock, Mock, patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
@ -11,7 +11,7 @@ from homeassistant.components.cloud import account_link
|
|||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed, mock_coro, mock_platform
|
from tests.common import async_fire_time_changed, mock_platform
|
||||||
|
|
||||||
TEST_DOMAIN = "oauth2_test"
|
TEST_DOMAIN = "oauth2_test"
|
||||||
|
|
||||||
@ -42,12 +42,10 @@ async def test_setup_provide_implementation(hass):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.cloud.account_link._get_services",
|
"homeassistant.components.cloud.account_link._get_services",
|
||||||
side_effect=lambda _: mock_coro(
|
return_value=[
|
||||||
[
|
{"service": "test", "min_version": "0.1.0"},
|
||||||
{"service": "test", "min_version": "0.1.0"},
|
{"service": "too_new", "min_version": "100.0.0"},
|
||||||
{"service": "too_new", "min_version": "100.0.0"},
|
],
|
||||||
]
|
|
||||||
),
|
|
||||||
):
|
):
|
||||||
assert (
|
assert (
|
||||||
await config_entry_oauth2_flow.async_get_implementations(
|
await config_entry_oauth2_flow.async_get_implementations(
|
||||||
@ -77,7 +75,7 @@ async def test_get_services_cached(hass):
|
|||||||
|
|
||||||
with patch.object(account_link, "CACHE_TIMEOUT", 0), patch(
|
with patch.object(account_link, "CACHE_TIMEOUT", 0), patch(
|
||||||
"hass_nabucasa.account_link.async_fetch_available_services",
|
"hass_nabucasa.account_link.async_fetch_available_services",
|
||||||
side_effect=lambda _: mock_coro(services),
|
side_effect=lambda _: services,
|
||||||
) as mock_fetch:
|
) as mock_fetch:
|
||||||
assert await account_link._get_services(hass) == 1
|
assert await account_link._get_services(hass) == 1
|
||||||
|
|
||||||
@ -111,7 +109,7 @@ async def test_implementation(hass, flow_handler):
|
|||||||
flow_finished = asyncio.Future()
|
flow_finished = asyncio.Future()
|
||||||
|
|
||||||
helper = Mock(
|
helper = Mock(
|
||||||
async_get_authorize_url=Mock(return_value=mock_coro("http://example.com/auth")),
|
async_get_authorize_url=CoroutineMock(return_value="http://example.com/auth"),
|
||||||
async_get_tokens=Mock(return_value=flow_finished),
|
async_get_tokens=Mock(return_value=flow_finished),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""Test hassbian config."""
|
"""Test hassbian config."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.bootstrap import async_setup_component
|
from homeassistant.bootstrap import async_setup_component
|
||||||
@ -9,8 +8,6 @@ from homeassistant.components.websocket_api.const import TYPE_RESULT
|
|||||||
from homeassistant.const import CONF_UNIT_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL
|
from homeassistant.const import CONF_UNIT_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL
|
||||||
from homeassistant.util import dt as dt_util, location
|
from homeassistant.util import dt as dt_util, location
|
||||||
|
|
||||||
from tests.common import mock_coro
|
|
||||||
|
|
||||||
ORIG_TIME_ZONE = dt_util.DEFAULT_TIME_ZONE
|
ORIG_TIME_ZONE = dt_util.DEFAULT_TIME_ZONE
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +28,7 @@ async def test_validate_config_ok(hass, hass_client):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.config.core.async_check_ha_config_file",
|
"homeassistant.components.config.core.async_check_ha_config_file",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
):
|
):
|
||||||
resp = await client.post("/api/config/core/check_config")
|
resp = await client.post("/api/config/core/check_config")
|
||||||
|
|
||||||
@ -42,7 +39,7 @@ async def test_validate_config_ok(hass, hass_client):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.config.core.async_check_ha_config_file",
|
"homeassistant.components.config.core.async_check_ha_config_file",
|
||||||
return_value=mock_coro("beer"),
|
return_value="beer",
|
||||||
):
|
):
|
||||||
resp = await client.post("/api/config/core/check_config")
|
resp = await client.post("/api/config/core/check_config")
|
||||||
|
|
||||||
@ -121,8 +118,7 @@ async def test_websocket_bad_core_update(hass, client):
|
|||||||
async def test_detect_config(hass, client):
|
async def test_detect_config(hass, client):
|
||||||
"""Test detect config."""
|
"""Test detect config."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.util.location.async_detect_location_info",
|
"homeassistant.util.location.async_detect_location_info", return_value=None,
|
||||||
return_value=mock_coro(None),
|
|
||||||
):
|
):
|
||||||
await client.send_json({"id": 1, "type": "config/core/detect"})
|
await client.send_json({"id": 1, "type": "config/core/detect"})
|
||||||
|
|
||||||
@ -136,20 +132,18 @@ async def test_detect_config_fail(hass, client):
|
|||||||
"""Test detect config."""
|
"""Test detect config."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.util.location.async_detect_location_info",
|
"homeassistant.util.location.async_detect_location_info",
|
||||||
return_value=mock_coro(
|
return_value=location.LocationInfo(
|
||||||
location.LocationInfo(
|
ip=None,
|
||||||
ip=None,
|
country_code=None,
|
||||||
country_code=None,
|
country_name=None,
|
||||||
country_name=None,
|
region_code=None,
|
||||||
region_code=None,
|
region_name=None,
|
||||||
region_name=None,
|
city=None,
|
||||||
city=None,
|
zip_code=None,
|
||||||
zip_code=None,
|
latitude=None,
|
||||||
latitude=None,
|
longitude=None,
|
||||||
longitude=None,
|
use_metric=True,
|
||||||
use_metric=True,
|
time_zone="Europe/Amsterdam",
|
||||||
time_zone="Europe/Amsterdam",
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
await client.send_json({"id": 1, "type": "config/core/detect"})
|
await client.send_json({"id": 1, "type": "config/core/detect"})
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
"""Test the Coolmaster config flow."""
|
"""Test the Coolmaster config flow."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant import config_entries, setup
|
from homeassistant import config_entries, setup
|
||||||
from homeassistant.components.coolmaster.const import AVAILABLE_MODES, DOMAIN
|
from homeassistant.components.coolmaster.const import AVAILABLE_MODES, DOMAIN
|
||||||
|
|
||||||
from tests.common import mock_coro
|
|
||||||
|
|
||||||
|
|
||||||
def _flow_data():
|
def _flow_data():
|
||||||
options = {"host": "1.1.1.1"}
|
options = {"host": "1.1.1.1"}
|
||||||
@ -27,10 +25,9 @@ async def test_form(hass):
|
|||||||
"homeassistant.components.coolmaster.config_flow.CoolMasterNet.devices",
|
"homeassistant.components.coolmaster.config_flow.CoolMasterNet.devices",
|
||||||
return_value=[1],
|
return_value=[1],
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.coolmaster.async_setup", return_value=mock_coro(True)
|
"homeassistant.components.coolmaster.async_setup", return_value=True
|
||||||
) as mock_setup, patch(
|
) as mock_setup, patch(
|
||||||
"homeassistant.components.coolmaster.async_setup_entry",
|
"homeassistant.components.coolmaster.async_setup_entry", return_value=True,
|
||||||
return_value=mock_coro(True),
|
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], _flow_data()
|
result["flow_id"], _flow_data()
|
||||||
|
@ -3,9 +3,8 @@ from datetime import datetime, timedelta
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from unittest.mock import Mock, call
|
|
||||||
|
|
||||||
from asynctest import patch
|
from asynctest import Mock, call, patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import zone
|
from homeassistant.components import zone
|
||||||
|
@ -23,7 +23,13 @@ def mock_controller_connect():
|
|||||||
"""Mock a successful connection."""
|
"""Mock a successful connection."""
|
||||||
with patch("homeassistant.components.freebox.router.Freepybox") as service_mock:
|
with patch("homeassistant.components.freebox.router.Freepybox") as service_mock:
|
||||||
service_mock.return_value.open = CoroutineMock()
|
service_mock.return_value.open = CoroutineMock()
|
||||||
service_mock.return_value.system.get_config = CoroutineMock()
|
service_mock.return_value.system.get_config = CoroutineMock(
|
||||||
|
return_value={
|
||||||
|
"mac": "abcd",
|
||||||
|
"model_info": {"pretty_name": "Pretty Model"},
|
||||||
|
"firmware_version": "123",
|
||||||
|
}
|
||||||
|
)
|
||||||
service_mock.return_value.lan.get_hosts_list = CoroutineMock()
|
service_mock.return_value.lan.get_hosts_list = CoroutineMock()
|
||||||
service_mock.return_value.connection.get_status = CoroutineMock()
|
service_mock.return_value.connection.get_status = CoroutineMock()
|
||||||
service_mock.return_value.close = CoroutineMock()
|
service_mock.return_value.close = CoroutineMock()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""The tests for the hassio component."""
|
"""The tests for the hassio component."""
|
||||||
import os
|
import os
|
||||||
from unittest.mock import Mock, patch
|
|
||||||
|
|
||||||
|
from asynctest import patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.auth.const import GROUP_ID_ADMIN
|
from homeassistant.auth.const import GROUP_ID_ADMIN
|
||||||
@ -9,8 +9,6 @@ from homeassistant.components import frontend
|
|||||||
from homeassistant.components.hassio import STORAGE_KEY
|
from homeassistant.components.hassio import STORAGE_KEY
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import mock_coro
|
|
||||||
|
|
||||||
MOCK_ENVIRON = {"HASSIO": "127.0.0.1", "HASSIO_TOKEN": "abcdefgh"}
|
MOCK_ENVIRON = {"HASSIO": "127.0.0.1", "HASSIO_TOKEN": "abcdefgh"}
|
||||||
|
|
||||||
|
|
||||||
@ -193,8 +191,7 @@ async def test_fail_setup_without_environ_var(hass):
|
|||||||
async def test_warn_when_cannot_connect(hass, caplog):
|
async def test_warn_when_cannot_connect(hass, caplog):
|
||||||
"""Fail warn when we cannot connect."""
|
"""Fail warn when we cannot connect."""
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
||||||
"homeassistant.components.hassio.HassIO.is_connected",
|
"homeassistant.components.hassio.HassIO.is_connected", return_value=None,
|
||||||
Mock(return_value=mock_coro(None)),
|
|
||||||
):
|
):
|
||||||
result = await async_setup_component(hass, "hassio", {})
|
result = await async_setup_component(hass, "hassio", {})
|
||||||
assert result
|
assert result
|
||||||
@ -311,7 +308,7 @@ async def test_service_calls_core(hassio_env, hass, aioclient_mock):
|
|||||||
assert aioclient_mock.call_count == 4
|
assert aioclient_mock.call_count == 4
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.config.async_check_ha_config_file", return_value=mock_coro()
|
"homeassistant.config.async_check_ha_config_file", return_value=None
|
||||||
) as mock_check_config:
|
) as mock_check_config:
|
||||||
await hass.services.async_call("homeassistant", "restart")
|
await hass.services.async_call("homeassistant", "restart")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -1,24 +1,21 @@
|
|||||||
"""Tests for the Hisense AEH-W4A1 init file."""
|
"""Tests for the Hisense AEH-W4A1 init file."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
from pyaehw4a1 import exceptions
|
from pyaehw4a1 import exceptions
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components import hisense_aehw4a1
|
from homeassistant.components import hisense_aehw4a1
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import mock_coro
|
|
||||||
|
|
||||||
|
|
||||||
async def test_creating_entry_sets_up_climate_discovery(hass):
|
async def test_creating_entry_sets_up_climate_discovery(hass):
|
||||||
"""Test setting up Hisense AEH-W4A1 loads the climate component."""
|
"""Test setting up Hisense AEH-W4A1 loads the climate component."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.discovery",
|
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.discovery",
|
||||||
return_value=mock_coro(["1.2.3.4"]),
|
return_value=["1.2.3.4"],
|
||||||
):
|
):
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.climate.async_setup_entry",
|
"homeassistant.components.hisense_aehw4a1.climate.async_setup_entry",
|
||||||
return_value=mock_coro(True),
|
return_value=True,
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
hisense_aehw4a1.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
hisense_aehw4a1.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
@ -41,11 +38,11 @@ async def test_configuring_hisense_w4a1_create_entry(hass):
|
|||||||
"""Test that specifying config will create an entry."""
|
"""Test that specifying config will create an entry."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.check",
|
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.check",
|
||||||
return_value=mock_coro(True),
|
return_value=True,
|
||||||
):
|
):
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.async_setup_entry",
|
"homeassistant.components.hisense_aehw4a1.async_setup_entry",
|
||||||
return_value=mock_coro(True),
|
return_value=True,
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -65,7 +62,7 @@ async def test_configuring_hisense_w4a1_not_creates_entry_for_device_not_found(h
|
|||||||
):
|
):
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.async_setup_entry",
|
"homeassistant.components.hisense_aehw4a1.async_setup_entry",
|
||||||
return_value=mock_coro(True),
|
return_value=True,
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -80,8 +77,7 @@ async def test_configuring_hisense_w4a1_not_creates_entry_for_device_not_found(h
|
|||||||
async def test_configuring_hisense_w4a1_not_creates_entry_for_empty_import(hass):
|
async def test_configuring_hisense_w4a1_not_creates_entry_for_empty_import(hass):
|
||||||
"""Test that specifying config will not create an entry."""
|
"""Test that specifying config will not create an entry."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.async_setup_entry",
|
"homeassistant.components.hisense_aehw4a1.async_setup_entry", return_value=True,
|
||||||
return_value=mock_coro(True),
|
|
||||||
) as mock_setup:
|
) as mock_setup:
|
||||||
await async_setup_component(hass, hisense_aehw4a1.DOMAIN, {})
|
await async_setup_component(hass, hisense_aehw4a1.DOMAIN, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
import asyncio
|
import asyncio
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import Mock, patch
|
|
||||||
|
|
||||||
|
from asynctest import Mock, patch
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
import yaml
|
import yaml
|
||||||
@ -37,7 +37,6 @@ from tests.common import (
|
|||||||
async_capture_events,
|
async_capture_events,
|
||||||
async_mock_service,
|
async_mock_service,
|
||||||
get_test_home_assistant,
|
get_test_home_assistant,
|
||||||
mock_coro,
|
|
||||||
mock_service,
|
mock_service,
|
||||||
patch_yaml_files,
|
patch_yaml_files,
|
||||||
)
|
)
|
||||||
@ -215,15 +214,15 @@ class TestComponentsCore(unittest.TestCase):
|
|||||||
assert mock_error.called
|
assert mock_error.called
|
||||||
assert mock_process.called is False
|
assert mock_process.called is False
|
||||||
|
|
||||||
@patch("homeassistant.core.HomeAssistant.async_stop", return_value=mock_coro())
|
@patch("homeassistant.core.HomeAssistant.async_stop", return_value=None)
|
||||||
def test_stop_homeassistant(self, mock_stop):
|
def test_stop_homeassistant(self, mock_stop):
|
||||||
"""Test stop service."""
|
"""Test stop service."""
|
||||||
stop(self.hass)
|
stop(self.hass)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
assert mock_stop.called
|
assert mock_stop.called
|
||||||
|
|
||||||
@patch("homeassistant.core.HomeAssistant.async_stop", return_value=mock_coro())
|
@patch("homeassistant.core.HomeAssistant.async_stop", return_value=None)
|
||||||
@patch("homeassistant.config.async_check_ha_config_file", return_value=mock_coro())
|
@patch("homeassistant.config.async_check_ha_config_file", return_value=None)
|
||||||
def test_restart_homeassistant(self, mock_check, mock_restart):
|
def test_restart_homeassistant(self, mock_check, mock_restart):
|
||||||
"""Test stop service."""
|
"""Test stop service."""
|
||||||
restart(self.hass)
|
restart(self.hass)
|
||||||
@ -231,7 +230,7 @@ class TestComponentsCore(unittest.TestCase):
|
|||||||
assert mock_restart.called
|
assert mock_restart.called
|
||||||
assert mock_check.called
|
assert mock_check.called
|
||||||
|
|
||||||
@patch("homeassistant.core.HomeAssistant.async_stop", return_value=mock_coro())
|
@patch("homeassistant.core.HomeAssistant.async_stop", return_value=None)
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.config.async_check_ha_config_file",
|
"homeassistant.config.async_check_ha_config_file",
|
||||||
side_effect=HomeAssistantError("Test error"),
|
side_effect=HomeAssistantError("Test error"),
|
||||||
@ -243,8 +242,8 @@ class TestComponentsCore(unittest.TestCase):
|
|||||||
assert mock_check.called
|
assert mock_check.called
|
||||||
assert not mock_restart.called
|
assert not mock_restart.called
|
||||||
|
|
||||||
@patch("homeassistant.core.HomeAssistant.async_stop", return_value=mock_coro())
|
@patch("homeassistant.core.HomeAssistant.async_stop", return_value=None)
|
||||||
@patch("homeassistant.config.async_check_ha_config_file", return_value=mock_coro())
|
@patch("homeassistant.config.async_check_ha_config_file", return_value=None)
|
||||||
def test_check_config(self, mock_check, mock_stop):
|
def test_check_config(self, mock_check, mock_stop):
|
||||||
"""Test stop service."""
|
"""Test stop service."""
|
||||||
check_config(self.hass)
|
check_config(self.hass)
|
||||||
@ -271,8 +270,7 @@ async def test_turn_on_to_not_block_for_domains_without_service(hass):
|
|||||||
service = hass.services._services["homeassistant"]["turn_on"]
|
service = hass.services._services["homeassistant"]["turn_on"]
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.core.ServiceRegistry.async_call",
|
"homeassistant.core.ServiceRegistry.async_call", return_value=None,
|
||||||
side_effect=lambda *args: mock_coro(),
|
|
||||||
) as mock_call:
|
) as mock_call:
|
||||||
await service.func(service_call)
|
await service.func(service_call)
|
||||||
|
|
||||||
@ -296,8 +294,7 @@ async def test_entity_update(hass):
|
|||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.helpers.entity_component.async_update_entity",
|
"homeassistant.helpers.entity_component.async_update_entity", return_value=None,
|
||||||
return_value=mock_coro(),
|
|
||||||
) as mock_update:
|
) as mock_update:
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"homeassistant",
|
"homeassistant",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""The tests for the IPMA weather component."""
|
"""The tests for the IPMA weather component."""
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from unittest.mock import patch
|
|
||||||
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant.components import weather
|
from homeassistant.components import weather
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
@ -22,7 +23,7 @@ from homeassistant.components.weather import (
|
|||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util.dt import now
|
from homeassistant.util.dt import now
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_coro
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
TEST_CONFIG = {"name": "HomeTown", "latitude": "40.00", "longitude": "-8.00"}
|
TEST_CONFIG = {"name": "HomeTown", "latitude": "40.00", "longitude": "-8.00"}
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ async def test_setup_configuration(hass):
|
|||||||
"""Test for successfully setting up the IPMA platform."""
|
"""Test for successfully setting up the IPMA platform."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ipma.weather.async_get_location",
|
"homeassistant.components.ipma.weather.async_get_location",
|
||||||
return_value=mock_coro(MockLocation()),
|
return_value=MockLocation(),
|
||||||
):
|
):
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -153,7 +154,7 @@ async def test_setup_config_flow(hass):
|
|||||||
"""Test for successfully setting up the IPMA platform."""
|
"""Test for successfully setting up the IPMA platform."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ipma.weather.async_get_location",
|
"homeassistant.components.ipma.weather.async_get_location",
|
||||||
return_value=mock_coro(MockLocation()),
|
return_value=MockLocation(),
|
||||||
):
|
):
|
||||||
entry = MockConfigEntry(domain="ipma", data=TEST_CONFIG)
|
entry = MockConfigEntry(domain="ipma", data=TEST_CONFIG)
|
||||||
await hass.config_entries.async_forward_entry_setup(entry, WEATHER_DOMAIN)
|
await hass.config_entries.async_forward_entry_setup(entry, WEATHER_DOMAIN)
|
||||||
@ -175,7 +176,7 @@ async def test_daily_forecast(hass):
|
|||||||
"""Test for successfully getting daily forecast."""
|
"""Test for successfully getting daily forecast."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ipma.weather.async_get_location",
|
"homeassistant.components.ipma.weather.async_get_location",
|
||||||
return_value=mock_coro(MockLocation()),
|
return_value=MockLocation(),
|
||||||
):
|
):
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -201,7 +202,7 @@ async def test_hourly_forecast(hass):
|
|||||||
"""Test for successfully getting daily forecast."""
|
"""Test for successfully getting daily forecast."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ipma.weather.async_get_location",
|
"homeassistant.components.ipma.weather.async_get_location",
|
||||||
return_value=mock_coro(MockLocation()),
|
return_value=MockLocation(),
|
||||||
):
|
):
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
"""Tests for iZone."""
|
"""Tests for iZone."""
|
||||||
|
|
||||||
from unittest.mock import Mock, patch
|
from asynctest import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components.izone.const import DISPATCH_CONTROLLER_DISCOVERED, IZONE
|
from homeassistant.components.izone.const import DISPATCH_CONTROLLER_DISCOVERED, IZONE
|
||||||
|
|
||||||
from tests.common import mock_coro
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_disco():
|
def mock_disco():
|
||||||
@ -24,7 +21,7 @@ def _mock_start_discovery(hass, mock_disco):
|
|||||||
|
|
||||||
def do_disovered(*args):
|
def do_disovered(*args):
|
||||||
async_dispatcher_send(hass, DISPATCH_CONTROLLER_DISCOVERED, True)
|
async_dispatcher_send(hass, DISPATCH_CONTROLLER_DISCOVERED, True)
|
||||||
return mock_coro(mock_disco)
|
return mock_disco
|
||||||
|
|
||||||
return do_disovered
|
return do_disovered
|
||||||
|
|
||||||
@ -36,7 +33,7 @@ async def test_not_found(hass, mock_disco):
|
|||||||
"homeassistant.components.izone.config_flow.async_start_discovery_service"
|
"homeassistant.components.izone.config_flow.async_start_discovery_service"
|
||||||
) as start_disco, patch(
|
) as start_disco, patch(
|
||||||
"homeassistant.components.izone.config_flow.async_stop_discovery_service",
|
"homeassistant.components.izone.config_flow.async_stop_discovery_service",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
) as stop_disco:
|
) as stop_disco:
|
||||||
start_disco.side_effect = _mock_start_discovery(hass, mock_disco)
|
start_disco.side_effect = _mock_start_discovery(hass, mock_disco)
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -59,13 +56,12 @@ async def test_found(hass, mock_disco):
|
|||||||
mock_disco.pi_disco.controllers["blah"] = object()
|
mock_disco.pi_disco.controllers["blah"] = object()
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.izone.climate.async_setup_entry",
|
"homeassistant.components.izone.climate.async_setup_entry", return_value=True,
|
||||||
return_value=mock_coro(True),
|
|
||||||
) as mock_setup, patch(
|
) as mock_setup, patch(
|
||||||
"homeassistant.components.izone.config_flow.async_start_discovery_service"
|
"homeassistant.components.izone.config_flow.async_start_discovery_service"
|
||||||
) as start_disco, patch(
|
) as start_disco, patch(
|
||||||
"homeassistant.components.izone.async_start_discovery_service",
|
"homeassistant.components.izone.async_start_discovery_service",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
):
|
):
|
||||||
start_disco.side_effect = _mock_start_discovery(hass, mock_disco)
|
start_disco.side_effect = _mock_start_discovery(hass, mock_disco)
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
"""Define tests for the Luftdaten config flow."""
|
"""Define tests for the Luftdaten config flow."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
|
||||||
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.luftdaten import DOMAIN, config_flow
|
from homeassistant.components.luftdaten import DOMAIN, config_flow
|
||||||
from homeassistant.components.luftdaten.const import CONF_SENSOR_ID
|
from homeassistant.components.luftdaten.const import CONF_SENSOR_ID
|
||||||
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_SHOW_ON_MAP
|
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_SHOW_ON_MAP
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_coro
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_duplicate_error(hass):
|
async def test_duplicate_error(hass):
|
||||||
@ -29,7 +30,7 @@ async def test_communication_error(hass):
|
|||||||
flow = config_flow.LuftDatenFlowHandler()
|
flow = config_flow.LuftDatenFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
||||||
with patch("luftdaten.Luftdaten.get_data", return_value=mock_coro(None)):
|
with patch("luftdaten.Luftdaten.get_data", return_value=None):
|
||||||
result = await flow.async_step_user(user_input=conf)
|
result = await flow.async_step_user(user_input=conf)
|
||||||
assert result["errors"] == {CONF_SENSOR_ID: "invalid_sensor"}
|
assert result["errors"] == {CONF_SENSOR_ID: "invalid_sensor"}
|
||||||
|
|
||||||
@ -41,8 +42,8 @@ async def test_invalid_sensor(hass):
|
|||||||
flow = config_flow.LuftDatenFlowHandler()
|
flow = config_flow.LuftDatenFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
||||||
with patch("luftdaten.Luftdaten.get_data", return_value=mock_coro(False)), patch(
|
with patch("luftdaten.Luftdaten.get_data", return_value=False), patch(
|
||||||
"luftdaten.Luftdaten.validate_sensor", return_value=mock_coro(False)
|
"luftdaten.Luftdaten.validate_sensor", return_value=False
|
||||||
):
|
):
|
||||||
result = await flow.async_step_user(user_input=conf)
|
result = await flow.async_step_user(user_input=conf)
|
||||||
assert result["errors"] == {CONF_SENSOR_ID: "invalid_sensor"}
|
assert result["errors"] == {CONF_SENSOR_ID: "invalid_sensor"}
|
||||||
@ -66,8 +67,8 @@ async def test_step_import(hass):
|
|||||||
flow = config_flow.LuftDatenFlowHandler()
|
flow = config_flow.LuftDatenFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
||||||
with patch("luftdaten.Luftdaten.get_data", return_value=mock_coro(True)), patch(
|
with patch("luftdaten.Luftdaten.get_data", return_value=True), patch(
|
||||||
"luftdaten.Luftdaten.validate_sensor", return_value=mock_coro(True)
|
"luftdaten.Luftdaten.validate_sensor", return_value=True
|
||||||
):
|
):
|
||||||
result = await flow.async_step_import(import_config=conf)
|
result = await flow.async_step_import(import_config=conf)
|
||||||
|
|
||||||
@ -91,8 +92,8 @@ async def test_step_user(hass):
|
|||||||
flow = config_flow.LuftDatenFlowHandler()
|
flow = config_flow.LuftDatenFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
||||||
with patch("luftdaten.Luftdaten.get_data", return_value=mock_coro(True)), patch(
|
with patch("luftdaten.Luftdaten.get_data", return_value=True), patch(
|
||||||
"luftdaten.Luftdaten.validate_sensor", return_value=mock_coro(True)
|
"luftdaten.Luftdaten.validate_sensor", return_value=True
|
||||||
):
|
):
|
||||||
result = await flow.async_step_user(user_input=conf)
|
result = await flow.async_step_user(user_input=conf)
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""The tests for the microsoft face platform."""
|
"""The tests for the microsoft face platform."""
|
||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import patch
|
|
||||||
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant.components import camera, microsoft_face as mf
|
from homeassistant.components import camera, microsoft_face as mf
|
||||||
from homeassistant.components.microsoft_face import (
|
from homeassistant.components.microsoft_face import (
|
||||||
@ -18,12 +19,7 @@ from homeassistant.components.microsoft_face import (
|
|||||||
from homeassistant.const import ATTR_NAME
|
from homeassistant.const import ATTR_NAME
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import assert_setup_component, get_test_home_assistant, load_fixture
|
||||||
assert_setup_component,
|
|
||||||
get_test_home_assistant,
|
|
||||||
load_fixture,
|
|
||||||
mock_coro,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def create_group(hass, name):
|
def create_group(hass, name):
|
||||||
@ -97,7 +93,7 @@ class TestMicrosoftFaceSetup:
|
|||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
)
|
)
|
||||||
def test_setup_component(self, mock_update):
|
def test_setup_component(self, mock_update):
|
||||||
"""Set up component."""
|
"""Set up component."""
|
||||||
@ -106,7 +102,7 @@ class TestMicrosoftFaceSetup:
|
|||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
)
|
)
|
||||||
def test_setup_component_wrong_api_key(self, mock_update):
|
def test_setup_component_wrong_api_key(self, mock_update):
|
||||||
"""Set up component without api key."""
|
"""Set up component without api key."""
|
||||||
@ -115,7 +111,7 @@ class TestMicrosoftFaceSetup:
|
|||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
)
|
)
|
||||||
def test_setup_component_test_service(self, mock_update):
|
def test_setup_component_test_service(self, mock_update):
|
||||||
"""Set up component."""
|
"""Set up component."""
|
||||||
@ -171,7 +167,7 @@ class TestMicrosoftFaceSetup:
|
|||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
)
|
)
|
||||||
def test_service_groups(self, mock_update, aioclient_mock):
|
def test_service_groups(self, mock_update, aioclient_mock):
|
||||||
"""Set up component, test groups services."""
|
"""Set up component, test groups services."""
|
||||||
@ -258,7 +254,7 @@ class TestMicrosoftFaceSetup:
|
|||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
)
|
)
|
||||||
def test_service_train(self, mock_update, aioclient_mock):
|
def test_service_train(self, mock_update, aioclient_mock):
|
||||||
"""Set up component, test train groups services."""
|
"""Set up component, test train groups services."""
|
||||||
@ -278,7 +274,7 @@ class TestMicrosoftFaceSetup:
|
|||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.camera.async_get_image",
|
"homeassistant.components.camera.async_get_image",
|
||||||
return_value=mock_coro(camera.Image("image/jpeg", b"Test")),
|
return_value=camera.Image("image/jpeg", b"Test"),
|
||||||
)
|
)
|
||||||
def test_service_face(self, camera_mock, aioclient_mock):
|
def test_service_face(self, camera_mock, aioclient_mock):
|
||||||
"""Set up component, test person face services."""
|
"""Set up component, test person face services."""
|
||||||
@ -318,7 +314,7 @@ class TestMicrosoftFaceSetup:
|
|||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
)
|
)
|
||||||
def test_service_status_400(self, mock_update, aioclient_mock):
|
def test_service_status_400(self, mock_update, aioclient_mock):
|
||||||
"""Set up component, test groups services with error."""
|
"""Set up component, test groups services with error."""
|
||||||
@ -340,7 +336,7 @@ class TestMicrosoftFaceSetup:
|
|||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
"homeassistant.components.microsoft_face.MicrosoftFace.update_store",
|
||||||
return_value=mock_coro(),
|
return_value=None,
|
||||||
)
|
)
|
||||||
def test_service_status_timeout(self, mock_update, aioclient_mock):
|
def test_service_status_timeout(self, mock_update, aioclient_mock):
|
||||||
"""Set up component, test groups services with timeout."""
|
"""Set up component, test groups services with timeout."""
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
"""Test Mikrotik setup process."""
|
"""Test Mikrotik setup process."""
|
||||||
from unittest.mock import Mock, patch
|
from asynctest import CoroutineMock, Mock, patch
|
||||||
|
|
||||||
from homeassistant.components import mikrotik
|
from homeassistant.components import mikrotik
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import MOCK_DATA
|
from . import MOCK_DATA
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_coro
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_with_no_config(hass):
|
async def test_setup_with_no_config(hass):
|
||||||
@ -23,9 +23,9 @@ async def test_successful_config_entry(hass):
|
|||||||
|
|
||||||
with patch.object(mikrotik, "MikrotikHub") as mock_hub, patch(
|
with patch.object(mikrotik, "MikrotikHub") as mock_hub, patch(
|
||||||
"homeassistant.helpers.device_registry.async_get_registry",
|
"homeassistant.helpers.device_registry.async_get_registry",
|
||||||
return_value=mock_coro(mock_registry),
|
return_value=mock_registry,
|
||||||
):
|
):
|
||||||
mock_hub.return_value.async_setup.return_value = mock_coro(True)
|
mock_hub.return_value.async_setup = CoroutineMock(return_value=True)
|
||||||
mock_hub.return_value.serial_num = "12345678"
|
mock_hub.return_value.serial_num = "12345678"
|
||||||
mock_hub.return_value.model = "RB750"
|
mock_hub.return_value.model = "RB750"
|
||||||
mock_hub.return_value.hostname = "mikrotik"
|
mock_hub.return_value.hostname = "mikrotik"
|
||||||
@ -55,7 +55,7 @@ async def test_hub_fail_setup(hass):
|
|||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
with patch.object(mikrotik, "MikrotikHub") as mock_hub:
|
with patch.object(mikrotik, "MikrotikHub") as mock_hub:
|
||||||
mock_hub.return_value.async_setup.return_value = mock_coro(False)
|
mock_hub.return_value.async_setup = CoroutineMock(return_value=False)
|
||||||
assert await mikrotik.async_setup_entry(hass, entry) is False
|
assert await mikrotik.async_setup_entry(hass, entry) is False
|
||||||
|
|
||||||
assert mikrotik.DOMAIN not in hass.data
|
assert mikrotik.DOMAIN not in hass.data
|
||||||
@ -67,10 +67,9 @@ async def test_unload_entry(hass):
|
|||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
with patch.object(mikrotik, "MikrotikHub") as mock_hub, patch(
|
with patch.object(mikrotik, "MikrotikHub") as mock_hub, patch(
|
||||||
"homeassistant.helpers.device_registry.async_get_registry",
|
"homeassistant.helpers.device_registry.async_get_registry", return_value=Mock(),
|
||||||
return_value=mock_coro(Mock()),
|
|
||||||
):
|
):
|
||||||
mock_hub.return_value.async_setup.return_value = mock_coro(True)
|
mock_hub.return_value.async_setup = CoroutineMock(return_value=True)
|
||||||
mock_hub.return_value.serial_num = "12345678"
|
mock_hub.return_value.serial_num = "12345678"
|
||||||
mock_hub.return_value.model = "RB750"
|
mock_hub.return_value.model = "RB750"
|
||||||
mock_hub.return_value.hostname = "mikrotik"
|
mock_hub.return_value.hostname = "mikrotik"
|
||||||
|
@ -3,8 +3,8 @@ from datetime import datetime, timedelta
|
|||||||
import json
|
import json
|
||||||
import ssl
|
import ssl
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
from asynctest import CoroutineMock, MagicMock, call, mock_open, patch
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -31,7 +31,6 @@ from tests.common import (
|
|||||||
async_mock_mqtt_component,
|
async_mock_mqtt_component,
|
||||||
fire_mqtt_message,
|
fire_mqtt_message,
|
||||||
get_test_home_assistant,
|
get_test_home_assistant,
|
||||||
mock_coro,
|
|
||||||
mock_device_registry,
|
mock_device_registry,
|
||||||
mock_mqtt_component,
|
mock_mqtt_component,
|
||||||
mock_registry,
|
mock_registry,
|
||||||
@ -56,9 +55,9 @@ def entity_reg(hass):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_mqtt():
|
def mock_mqtt():
|
||||||
"""Make sure connection is established."""
|
"""Make sure connection is established."""
|
||||||
with mock.patch("homeassistant.components.mqtt.MQTT") as mock_mqtt:
|
with patch("homeassistant.components.mqtt.MQTT") as mock_mqtt:
|
||||||
mock_mqtt.return_value.async_connect.return_value = mock_coro(True)
|
mock_mqtt.return_value.async_connect = CoroutineMock(return_value=True)
|
||||||
mock_mqtt.return_value.async_disconnect.return_value = mock_coro(True)
|
mock_mqtt.return_value.async_disconnect = CoroutineMock(return_value=True)
|
||||||
yield mock_mqtt
|
yield mock_mqtt
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +66,7 @@ async def async_mock_mqtt_client(hass, config=None):
|
|||||||
if config is None:
|
if config is None:
|
||||||
config = {mqtt.CONF_BROKER: "mock-broker"}
|
config = {mqtt.CONF_BROKER: "mock-broker"}
|
||||||
|
|
||||||
with mock.patch("paho.mqtt.client.Client") as mock_client:
|
with patch("paho.mqtt.client.Client") as mock_client:
|
||||||
mock_client().connect.return_value = 0
|
mock_client().connect.return_value = 0
|
||||||
mock_client().subscribe.return_value = (0, 0)
|
mock_client().subscribe.return_value = (0, 0)
|
||||||
mock_client().unsubscribe.return_value = (0, 0)
|
mock_client().unsubscribe.return_value = (0, 0)
|
||||||
@ -583,12 +582,12 @@ class TestMQTTCallbacks(unittest.TestCase):
|
|||||||
# Fake that the client is connected
|
# Fake that the client is connected
|
||||||
self.hass.data["mqtt"].connected = True
|
self.hass.data["mqtt"].connected = True
|
||||||
|
|
||||||
calls_a = mock.MagicMock()
|
calls_a = MagicMock()
|
||||||
mqtt.subscribe(self.hass, "test/state", calls_a)
|
mqtt.subscribe(self.hass, "test/state", calls_a)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
assert calls_a.called
|
assert calls_a.called
|
||||||
|
|
||||||
calls_b = mock.MagicMock()
|
calls_b = MagicMock()
|
||||||
mqtt.subscribe(self.hass, "test/state", calls_b)
|
mqtt.subscribe(self.hass, "test/state", calls_b)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
assert calls_b.called
|
assert calls_b.called
|
||||||
@ -639,9 +638,9 @@ class TestMQTTCallbacks(unittest.TestCase):
|
|||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
expected = [
|
expected = [
|
||||||
mock.call("test/state", 2),
|
call("test/state", 2),
|
||||||
mock.call("test/state", 0),
|
call("test/state", 0),
|
||||||
mock.call("test/state", 1),
|
call("test/state", 1),
|
||||||
]
|
]
|
||||||
assert self.hass.data["mqtt"]._mqttc.subscribe.mock_calls == expected
|
assert self.hass.data["mqtt"]._mqttc.subscribe.mock_calls == expected
|
||||||
|
|
||||||
@ -653,7 +652,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
|||||||
self.hass.data["mqtt"]._mqtt_on_connect(None, None, None, 0)
|
self.hass.data["mqtt"]._mqtt_on_connect(None, None, None, 0)
|
||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
|
|
||||||
expected.append(mock.call("test/state", 1))
|
expected.append(call("test/state", 1))
|
||||||
assert self.hass.data["mqtt"]._mqttc.subscribe.mock_calls == expected
|
assert self.hass.data["mqtt"]._mqttc.subscribe.mock_calls == expected
|
||||||
|
|
||||||
|
|
||||||
@ -661,9 +660,9 @@ async def test_setup_embedded_starts_with_no_config(hass):
|
|||||||
"""Test setting up embedded server with no config."""
|
"""Test setting up embedded server with no config."""
|
||||||
client_config = ("localhost", 1883, "user", "pass", None, "3.1.1")
|
client_config = ("localhost", 1883, "user", "pass", None, "3.1.1")
|
||||||
|
|
||||||
with mock.patch(
|
with patch(
|
||||||
"homeassistant.components.mqtt.server.async_start",
|
"homeassistant.components.mqtt.server.async_start",
|
||||||
return_value=mock_coro(return_value=(True, client_config)),
|
return_value=(True, client_config),
|
||||||
) as _start:
|
) as _start:
|
||||||
await async_mock_mqtt_client(hass, {})
|
await async_mock_mqtt_client(hass, {})
|
||||||
assert _start.call_count == 1
|
assert _start.call_count == 1
|
||||||
@ -673,11 +672,10 @@ async def test_setup_embedded_with_embedded(hass):
|
|||||||
"""Test setting up embedded server with no config."""
|
"""Test setting up embedded server with no config."""
|
||||||
client_config = ("localhost", 1883, "user", "pass", None, "3.1.1")
|
client_config = ("localhost", 1883, "user", "pass", None, "3.1.1")
|
||||||
|
|
||||||
with mock.patch(
|
with patch(
|
||||||
"homeassistant.components.mqtt.server.async_start",
|
"homeassistant.components.mqtt.server.async_start",
|
||||||
return_value=mock_coro(return_value=(True, client_config)),
|
return_value=(True, client_config),
|
||||||
) as _start:
|
) as _start:
|
||||||
_start.return_value = mock_coro(return_value=(True, client_config))
|
|
||||||
await async_mock_mqtt_client(hass, {"embedded": None})
|
await async_mock_mqtt_client(hass, {"embedded": None})
|
||||||
assert _start.call_count == 1
|
assert _start.call_count == 1
|
||||||
|
|
||||||
@ -686,7 +684,7 @@ async def test_setup_fails_if_no_connect_broker(hass):
|
|||||||
"""Test for setup failure if connection to broker is missing."""
|
"""Test for setup failure if connection to broker is missing."""
|
||||||
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
|
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
|
||||||
|
|
||||||
with mock.patch("paho.mqtt.client.Client") as mock_client:
|
with patch("paho.mqtt.client.Client") as mock_client:
|
||||||
mock_client().connect = lambda *args: 1
|
mock_client().connect = lambda *args: 1
|
||||||
assert not await mqtt.async_setup_entry(hass, entry)
|
assert not await mqtt.async_setup_entry(hass, entry)
|
||||||
|
|
||||||
@ -695,8 +693,8 @@ async def test_setup_raises_ConfigEntryNotReady_if_no_connect_broker(hass):
|
|||||||
"""Test for setup failure if connection to broker is missing."""
|
"""Test for setup failure if connection to broker is missing."""
|
||||||
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
|
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"})
|
||||||
|
|
||||||
with mock.patch("paho.mqtt.client.Client") as mock_client:
|
with patch("paho.mqtt.client.Client") as mock_client:
|
||||||
mock_client().connect = mock.Mock(side_effect=OSError("Connection error"))
|
mock_client().connect = MagicMock(side_effect=OSError("Connection error"))
|
||||||
with pytest.raises(ConfigEntryNotReady):
|
with pytest.raises(ConfigEntryNotReady):
|
||||||
await mqtt.async_setup_entry(hass, entry)
|
await mqtt.async_setup_entry(hass, entry)
|
||||||
|
|
||||||
@ -808,7 +806,7 @@ async def test_mqtt_subscribes_topics_on_connect(hass):
|
|||||||
mqtt.Subscription("still/pending", None, 1),
|
mqtt.Subscription("still/pending", None, 1),
|
||||||
]
|
]
|
||||||
|
|
||||||
hass.add_job = mock.MagicMock()
|
hass.add_job = MagicMock()
|
||||||
hass.data["mqtt"]._mqtt_on_connect(None, None, 0, 0)
|
hass.data["mqtt"]._mqtt_on_connect(None, None, 0, 0)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -874,7 +872,7 @@ async def test_dump_service(hass):
|
|||||||
"""Test that we can dump a topic."""
|
"""Test that we can dump a topic."""
|
||||||
await async_mock_mqtt_component(hass)
|
await async_mock_mqtt_component(hass)
|
||||||
|
|
||||||
mock_open = mock.mock_open()
|
mopen = mock_open()
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"mqtt", "dump", {"topic": "bla/#", "duration": 3}, blocking=True
|
"mqtt", "dump", {"topic": "bla/#", "duration": 3}, blocking=True
|
||||||
@ -882,11 +880,11 @@ async def test_dump_service(hass):
|
|||||||
async_fire_mqtt_message(hass, "bla/1", "test1")
|
async_fire_mqtt_message(hass, "bla/1", "test1")
|
||||||
async_fire_mqtt_message(hass, "bla/2", "test2")
|
async_fire_mqtt_message(hass, "bla/2", "test2")
|
||||||
|
|
||||||
with mock.patch("homeassistant.components.mqtt.open", mock_open):
|
with patch("homeassistant.components.mqtt.open", mopen):
|
||||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=3))
|
async_fire_time_changed(hass, utcnow() + timedelta(seconds=3))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
writes = mock_open.return_value.write.mock_calls
|
writes = mopen.return_value.write.mock_calls
|
||||||
assert len(writes) == 2
|
assert len(writes) == 2
|
||||||
assert writes[0][1][0] == "bla/1,test1\n"
|
assert writes[0][1][0] == "bla/1,test1\n"
|
||||||
assert writes[1][1][0] == "bla/2,test2\n"
|
assert writes[1][1][0] == "bla/2,test2\n"
|
||||||
@ -1251,7 +1249,7 @@ async def test_debug_info_wildcard(hass, mqtt_mock):
|
|||||||
]
|
]
|
||||||
|
|
||||||
start_dt = datetime(2019, 1, 1, 0, 0, 0)
|
start_dt = datetime(2019, 1, 1, 0, 0, 0)
|
||||||
with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
with patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
||||||
dt_utcnow.return_value = start_dt
|
dt_utcnow.return_value = start_dt
|
||||||
async_fire_mqtt_message(hass, "sensor/abc", "123")
|
async_fire_mqtt_message(hass, "sensor/abc", "123")
|
||||||
|
|
||||||
@ -1293,7 +1291,7 @@ async def test_debug_info_filter_same(hass, mqtt_mock):
|
|||||||
|
|
||||||
dt1 = datetime(2019, 1, 1, 0, 0, 0)
|
dt1 = datetime(2019, 1, 1, 0, 0, 0)
|
||||||
dt2 = datetime(2019, 1, 1, 0, 0, 1)
|
dt2 = datetime(2019, 1, 1, 0, 0, 1)
|
||||||
with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
with patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
||||||
dt_utcnow.return_value = dt1
|
dt_utcnow.return_value = dt1
|
||||||
async_fire_mqtt_message(hass, "sensor/abc", "123")
|
async_fire_mqtt_message(hass, "sensor/abc", "123")
|
||||||
async_fire_mqtt_message(hass, "sensor/abc", "123")
|
async_fire_mqtt_message(hass, "sensor/abc", "123")
|
||||||
|
@ -153,8 +153,7 @@ light:
|
|||||||
payload_off: "off"
|
payload_off: "off"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from unittest import mock
|
from asynctest import call, patch
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
from homeassistant.components import light, mqtt
|
from homeassistant.components import light, mqtt
|
||||||
from homeassistant.components.mqtt.discovery import async_start
|
from homeassistant.components.mqtt.discovery import async_start
|
||||||
@ -188,7 +187,6 @@ from tests.common import (
|
|||||||
MockConfigEntry,
|
MockConfigEntry,
|
||||||
assert_setup_component,
|
assert_setup_component,
|
||||||
async_fire_mqtt_message,
|
async_fire_mqtt_message,
|
||||||
mock_coro,
|
|
||||||
)
|
)
|
||||||
from tests.components.light import common
|
from tests.components.light import common
|
||||||
|
|
||||||
@ -673,7 +671,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
|||||||
)
|
)
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
||||||
return_value=mock_coro(fake_state),
|
return_value=fake_state,
|
||||||
):
|
):
|
||||||
with assert_setup_component(1, light.DOMAIN):
|
with assert_setup_component(1, light.DOMAIN):
|
||||||
assert await async_setup_component(hass, light.DOMAIN, config)
|
assert await async_setup_component(hass, light.DOMAIN, config)
|
||||||
@ -716,12 +714,12 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
|||||||
|
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call("test_light_rgb/set", "on", 2, False),
|
call("test_light_rgb/set", "on", 2, False),
|
||||||
mock.call("test_light_rgb/rgb/set", "255,128,0", 2, False),
|
call("test_light_rgb/rgb/set", "255,128,0", 2, False),
|
||||||
mock.call("test_light_rgb/brightness/set", 50, 2, False),
|
call("test_light_rgb/brightness/set", 50, 2, False),
|
||||||
mock.call("test_light_rgb/hs/set", "359.0,78.0", 2, False),
|
call("test_light_rgb/hs/set", "359.0,78.0", 2, False),
|
||||||
mock.call("test_light_rgb/white_value/set", 80, 2, False),
|
call("test_light_rgb/white_value/set", 80, 2, False),
|
||||||
mock.call("test_light_rgb/xy/set", "0.14,0.131", 2, False),
|
call("test_light_rgb/xy/set", "0.14,0.131", 2, False),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
@ -760,8 +758,8 @@ async def test_sending_mqtt_rgb_command_with_template(hass, mqtt_mock):
|
|||||||
|
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call("test_light_rgb/set", "on", 0, False),
|
call("test_light_rgb/set", "on", 0, False),
|
||||||
mock.call("test_light_rgb/rgb/set", "#ff803f", 0, False),
|
call("test_light_rgb/rgb/set", "#ff803f", 0, False),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
@ -795,8 +793,8 @@ async def test_sending_mqtt_color_temp_command_with_template(hass, mqtt_mock):
|
|||||||
|
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call("test_light_color_temp/set", "on", 0, False),
|
call("test_light_color_temp/set", "on", 0, False),
|
||||||
mock.call("test_light_color_temp/color_temp/set", "10", 0, False),
|
call("test_light_color_temp/color_temp/set", "10", 0, False),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
@ -980,8 +978,8 @@ async def test_on_command_first(hass, mqtt_mock):
|
|||||||
# test_light/bright: 50
|
# test_light/bright: 50
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call("test_light/set", "ON", 0, False),
|
call("test_light/set", "ON", 0, False),
|
||||||
mock.call("test_light/bright", 50, 0, False),
|
call("test_light/bright", 50, 0, False),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
@ -1015,8 +1013,8 @@ async def test_on_command_last(hass, mqtt_mock):
|
|||||||
# test_light/set: 'ON'
|
# test_light/set: 'ON'
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call("test_light/bright", 50, 0, False),
|
call("test_light/bright", 50, 0, False),
|
||||||
mock.call("test_light/set", "ON", 0, False),
|
call("test_light/set", "ON", 0, False),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
@ -1072,8 +1070,8 @@ async def test_on_command_brightness(hass, mqtt_mock):
|
|||||||
|
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call("test_light/rgb", "255,128,0", 0, False),
|
call("test_light/rgb", "255,128,0", 0, False),
|
||||||
mock.call("test_light/bright", 50, 0, False),
|
call("test_light/bright", 50, 0, False),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
@ -1102,8 +1100,8 @@ async def test_on_command_rgb(hass, mqtt_mock):
|
|||||||
# test_light/set: 'ON'
|
# test_light/set: 'ON'
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call("test_light/rgb", "127,127,127", 0, False),
|
call("test_light/rgb", "127,127,127", 0, False),
|
||||||
mock.call("test_light/set", "ON", 0, False),
|
call("test_light/set", "ON", 0, False),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
@ -1138,8 +1136,8 @@ async def test_on_command_rgb_template(hass, mqtt_mock):
|
|||||||
# test_light/set: 'ON'
|
# test_light/set: 'ON'
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call("test_light/rgb", "127/127/127", 0, False),
|
call("test_light/rgb", "127/127/127", 0, False),
|
||||||
mock.call("test_light/set", "ON", 0, False),
|
call("test_light/set", "ON", 0, False),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
@ -1174,8 +1172,8 @@ async def test_effect(hass, mqtt_mock):
|
|||||||
# test_light/set: 'ON'
|
# test_light/set: 'ON'
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call("test_light/effect/set", "rainbow", 0, False),
|
call("test_light/effect/set", "rainbow", 0, False),
|
||||||
mock.call("test_light/set", "ON", 0, False),
|
call("test_light/set", "ON", 0, False),
|
||||||
],
|
],
|
||||||
any_order=True,
|
any_order=True,
|
||||||
)
|
)
|
||||||
|
@ -88,8 +88,8 @@ light:
|
|||||||
brightness_scale: 99
|
brightness_scale: 99
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
from unittest import mock
|
|
||||||
from unittest.mock import patch
|
from asynctest import call, patch
|
||||||
|
|
||||||
from homeassistant.components import light
|
from homeassistant.components import light
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -123,7 +123,7 @@ from .test_common import (
|
|||||||
help_test_update_with_json_attrs_not_dict,
|
help_test_update_with_json_attrs_not_dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.common import async_fire_mqtt_message, mock_coro
|
from tests.common import async_fire_mqtt_message
|
||||||
from tests.components.light import common
|
from tests.components.light import common
|
||||||
|
|
||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
@ -323,7 +323,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
||||||
return_value=mock_coro(fake_state),
|
return_value=fake_state,
|
||||||
):
|
):
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -397,7 +397,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
|||||||
|
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"r": 0, "g": 123, "b": 255,'
|
'{"state": "ON", "color": {"r": 0, "g": 123, "b": 255,'
|
||||||
@ -407,7 +407,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
|||||||
2,
|
2,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"r": 255, "g": 56, "b": 59,'
|
'{"state": "ON", "color": {"r": 255, "g": 56, "b": 59,'
|
||||||
@ -417,7 +417,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
|||||||
2,
|
2,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"r": 255, "g": 128, "b": 0,'
|
'{"state": "ON", "color": {"r": 255, "g": 128, "b": 0,'
|
||||||
@ -471,7 +471,7 @@ async def test_sending_hs_color(hass, mqtt_mock):
|
|||||||
|
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"h": 210.824, "s": 100.0},'
|
'{"state": "ON", "color": {"h": 210.824, "s": 100.0},'
|
||||||
@ -480,7 +480,7 @@ async def test_sending_hs_color(hass, mqtt_mock):
|
|||||||
0,
|
0,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"h": 359.0, "s": 78.0},'
|
'{"state": "ON", "color": {"h": 359.0, "s": 78.0},'
|
||||||
@ -489,7 +489,7 @@ async def test_sending_hs_color(hass, mqtt_mock):
|
|||||||
0,
|
0,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"h": 30.118, "s": 100.0},'
|
'{"state": "ON", "color": {"h": 30.118, "s": 100.0},'
|
||||||
@ -532,19 +532,19 @@ async def test_sending_rgb_color_no_brightness(hass, mqtt_mock):
|
|||||||
|
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator('{"state": "ON", "color": {"r": 0, "g": 24, "b": 50}}'),
|
JsonValidator('{"state": "ON", "color": {"r": 0, "g": 24, "b": 50}}'),
|
||||||
0,
|
0,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator('{"state": "ON", "color": {"r": 50, "g": 11, "b": 11}}'),
|
JsonValidator('{"state": "ON", "color": {"r": 50, "g": 11, "b": 11}}'),
|
||||||
0,
|
0,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator('{"state": "ON", "color": {"r": 255, "g": 128, "b": 0}}'),
|
JsonValidator('{"state": "ON", "color": {"r": 255, "g": 128, "b": 0}}'),
|
||||||
0,
|
0,
|
||||||
@ -585,7 +585,7 @@ async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
|
|||||||
|
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"r": 0, "g": 123, "b": 255},'
|
'{"state": "ON", "color": {"r": 0, "g": 123, "b": 255},'
|
||||||
@ -594,7 +594,7 @@ async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
|
|||||||
0,
|
0,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"r": 255, "g": 56, "b": 59},'
|
'{"state": "ON", "color": {"r": 255, "g": 56, "b": 59},'
|
||||||
@ -603,7 +603,7 @@ async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
|
|||||||
0,
|
0,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"r": 255, "g": 128, "b": 0},'
|
'{"state": "ON", "color": {"r": 255, "g": 128, "b": 0},'
|
||||||
@ -647,7 +647,7 @@ async def test_sending_xy_color(hass, mqtt_mock):
|
|||||||
|
|
||||||
mqtt_mock.async_publish.assert_has_calls(
|
mqtt_mock.async_publish.assert_has_calls(
|
||||||
[
|
[
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"x": 0.14, "y": 0.131},'
|
'{"state": "ON", "color": {"x": 0.14, "y": 0.131},'
|
||||||
@ -656,7 +656,7 @@ async def test_sending_xy_color(hass, mqtt_mock):
|
|||||||
0,
|
0,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"x": 0.654, "y": 0.301},'
|
'{"state": "ON", "color": {"x": 0.654, "y": 0.301},'
|
||||||
@ -665,7 +665,7 @@ async def test_sending_xy_color(hass, mqtt_mock):
|
|||||||
0,
|
0,
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
mock.call(
|
call(
|
||||||
"test_light_rgb/set",
|
"test_light_rgb/set",
|
||||||
JsonValidator(
|
JsonValidator(
|
||||||
'{"state": "ON", "color": {"x": 0.611, "y": 0.375},'
|
'{"state": "ON", "color": {"x": 0.611, "y": 0.375},'
|
||||||
|
@ -26,7 +26,7 @@ If your light doesn't support white value feature, omit `white_value_template`.
|
|||||||
|
|
||||||
If your light doesn't support RGB feature, omit `(red|green|blue)_template`.
|
If your light doesn't support RGB feature, omit `(red|green|blue)_template`.
|
||||||
"""
|
"""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant.components import light
|
from homeassistant.components import light
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -60,7 +60,7 @@ from .test_common import (
|
|||||||
help_test_update_with_json_attrs_not_dict,
|
help_test_update_with_json_attrs_not_dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.common import assert_setup_component, async_fire_mqtt_message, mock_coro
|
from tests.common import assert_setup_component, async_fire_mqtt_message
|
||||||
from tests.components.light import common
|
from tests.components.light import common
|
||||||
|
|
||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
@ -287,7 +287,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
||||||
return_value=mock_coro(fake_state),
|
return_value=fake_state,
|
||||||
):
|
):
|
||||||
with assert_setup_component(1, light.DOMAIN):
|
with assert_setup_component(1, light.DOMAIN):
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Define tests for the Notion config flow."""
|
"""Define tests for the Notion config flow."""
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
import aionotion
|
import aionotion
|
||||||
|
from asynctest import patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""The tests for the openalpr cloud platform."""
|
"""The tests for the openalpr cloud platform."""
|
||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import PropertyMock, patch
|
|
||||||
|
from asynctest import PropertyMock, patch
|
||||||
|
|
||||||
from homeassistant.components import camera, image_processing as ip
|
from homeassistant.components import camera, image_processing as ip
|
||||||
from homeassistant.components.openalpr_cloud.image_processing import OPENALPR_API_URL
|
from homeassistant.components.openalpr_cloud.image_processing import OPENALPR_API_URL
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""The tests for the openalpr local platform."""
|
"""The tests for the openalpr local platform."""
|
||||||
from unittest.mock import MagicMock, PropertyMock, patch
|
from asynctest import MagicMock, PropertyMock, patch
|
||||||
|
|
||||||
import homeassistant.components.image_processing as ip
|
import homeassistant.components.image_processing as ip
|
||||||
from homeassistant.const import ATTR_ENTITY_PICTURE
|
from homeassistant.const import ATTR_ENTITY_PICTURE
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Test the Opentherm Gateway config flow."""
|
"""Test the Opentherm Gateway config flow."""
|
||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
|
from asynctest import patch
|
||||||
from pyotgw.vars import OTGW_ABOUT
|
from pyotgw.vars import OTGW_ABOUT
|
||||||
from serial import SerialException
|
from serial import SerialException
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""Tests for OwnTracks config flow."""
|
"""Tests for OwnTracks config flow."""
|
||||||
from unittest.mock import Mock, patch
|
from asynctest import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""Define tests for the OpenUV config flow."""
|
"""Define tests for the OpenUV config flow."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
from regenmaschine.errors import RainMachineError
|
from regenmaschine.errors import RainMachineError
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""Test the Ring config flow."""
|
"""Test the Ring config flow."""
|
||||||
from unittest.mock import Mock, patch
|
from asynctest import Mock, patch
|
||||||
|
|
||||||
from homeassistant import config_entries, setup
|
from homeassistant import config_entries, setup
|
||||||
from homeassistant.components.ring import DOMAIN
|
from homeassistant.components.ring import DOMAIN
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
"""The tests for the rmvtransport platform."""
|
"""The tests for the rmvtransport platform."""
|
||||||
import datetime
|
import datetime
|
||||||
from unittest.mock import patch
|
|
||||||
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import mock_coro
|
|
||||||
|
|
||||||
VALID_CONFIG_MINIMAL = {
|
VALID_CONFIG_MINIMAL = {
|
||||||
"sensor": {"platform": "rmvtransport", "next_departure": [{"station": "3000010"}]}
|
"sensor": {"platform": "rmvtransport", "next_departure": [{"station": "3000010"}]}
|
||||||
}
|
}
|
||||||
@ -163,8 +162,7 @@ def get_no_departures_mock():
|
|||||||
async def test_rmvtransport_min_config(hass):
|
async def test_rmvtransport_min_config(hass):
|
||||||
"""Test minimal rmvtransport configuration."""
|
"""Test minimal rmvtransport configuration."""
|
||||||
with patch(
|
with patch(
|
||||||
"RMVtransport.RMVtransport.get_departures",
|
"RMVtransport.RMVtransport.get_departures", return_value=get_departures_mock(),
|
||||||
return_value=mock_coro(get_departures_mock()),
|
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, "sensor", VALID_CONFIG_MINIMAL) is True
|
assert await async_setup_component(hass, "sensor", VALID_CONFIG_MINIMAL) is True
|
||||||
|
|
||||||
@ -183,8 +181,7 @@ async def test_rmvtransport_min_config(hass):
|
|||||||
async def test_rmvtransport_name_config(hass):
|
async def test_rmvtransport_name_config(hass):
|
||||||
"""Test custom name configuration."""
|
"""Test custom name configuration."""
|
||||||
with patch(
|
with patch(
|
||||||
"RMVtransport.RMVtransport.get_departures",
|
"RMVtransport.RMVtransport.get_departures", return_value=get_departures_mock(),
|
||||||
return_value=mock_coro(get_departures_mock()),
|
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, "sensor", VALID_CONFIG_NAME)
|
assert await async_setup_component(hass, "sensor", VALID_CONFIG_NAME)
|
||||||
|
|
||||||
@ -195,8 +192,7 @@ async def test_rmvtransport_name_config(hass):
|
|||||||
async def test_rmvtransport_misc_config(hass):
|
async def test_rmvtransport_misc_config(hass):
|
||||||
"""Test misc configuration."""
|
"""Test misc configuration."""
|
||||||
with patch(
|
with patch(
|
||||||
"RMVtransport.RMVtransport.get_departures",
|
"RMVtransport.RMVtransport.get_departures", return_value=get_departures_mock(),
|
||||||
return_value=mock_coro(get_departures_mock()),
|
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, "sensor", VALID_CONFIG_MISC)
|
assert await async_setup_component(hass, "sensor", VALID_CONFIG_MISC)
|
||||||
|
|
||||||
@ -208,8 +204,7 @@ async def test_rmvtransport_misc_config(hass):
|
|||||||
async def test_rmvtransport_dest_config(hass):
|
async def test_rmvtransport_dest_config(hass):
|
||||||
"""Test destination configuration."""
|
"""Test destination configuration."""
|
||||||
with patch(
|
with patch(
|
||||||
"RMVtransport.RMVtransport.get_departures",
|
"RMVtransport.RMVtransport.get_departures", return_value=get_departures_mock(),
|
||||||
return_value=mock_coro(get_departures_mock()),
|
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, "sensor", VALID_CONFIG_DEST)
|
assert await async_setup_component(hass, "sensor", VALID_CONFIG_DEST)
|
||||||
|
|
||||||
@ -227,7 +222,7 @@ async def test_rmvtransport_no_departures(hass):
|
|||||||
"""Test for no departures."""
|
"""Test for no departures."""
|
||||||
with patch(
|
with patch(
|
||||||
"RMVtransport.RMVtransport.get_departures",
|
"RMVtransport.RMVtransport.get_departures",
|
||||||
return_value=mock_coro(get_no_departures_mock()),
|
return_value=get_no_departures_mock(),
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, "sensor", VALID_CONFIG_MINIMAL)
|
assert await async_setup_component(hass, "sensor", VALID_CONFIG_MINIMAL)
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""Test the sentry config flow."""
|
"""Test the sentry config flow."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
from sentry_sdk.utils import BadDsn
|
from sentry_sdk.utils import BadDsn
|
||||||
|
|
||||||
from homeassistant import config_entries, setup
|
from homeassistant import config_entries, setup
|
||||||
|
@ -4,7 +4,8 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import Mock, patch
|
|
||||||
|
from asynctest import Mock, patch
|
||||||
|
|
||||||
from homeassistant.components import shell_command
|
from homeassistant.components import shell_command
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""Tests for SMHI config flow."""
|
"""Tests for SMHI config flow."""
|
||||||
from unittest.mock import Mock, patch
|
from asynctest import Mock, patch
|
||||||
|
|
||||||
from smhi.smhi_lib import Smhi as SmhiApi, SmhiForecastException
|
from smhi.smhi_lib import Smhi as SmhiApi, SmhiForecastException
|
||||||
|
|
||||||
from homeassistant.components.smhi import config_flow
|
from homeassistant.components.smhi import config_flow
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
from unittest.mock import Mock, patch
|
|
||||||
|
from asynctest import Mock, patch
|
||||||
|
|
||||||
from homeassistant.components.smhi import weather as weather_smhi
|
from homeassistant.components.smhi import weather as weather_smhi
|
||||||
from homeassistant.components.smhi.const import ATTR_SMHI_CLOUDINESS
|
from homeassistant.components.smhi.const import ATTR_SMHI_CLOUDINESS
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""Test the solarlog config flow."""
|
"""Test the solarlog config flow."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow, setup
|
from homeassistant import config_entries, data_entry_flow, setup
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""Test the Tesla config flow."""
|
"""Test the Tesla config flow."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
from teslajsonpy import TeslaException
|
from teslajsonpy import TeslaException
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow, setup
|
from homeassistant import config_entries, data_entry_flow, setup
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
"""Common tradfri test fixtures."""
|
"""Common tradfri test fixtures."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from tests.common import mock_coro
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_gateway_info():
|
def mock_gateway_info():
|
||||||
@ -19,5 +16,5 @@ def mock_gateway_info():
|
|||||||
def mock_entry_setup():
|
def mock_entry_setup():
|
||||||
"""Mock entry setup."""
|
"""Mock entry setup."""
|
||||||
with patch("homeassistant.components.tradfri.async_setup_entry") as mock_setup:
|
with patch("homeassistant.components.tradfri.async_setup_entry") as mock_setup:
|
||||||
mock_setup.return_value = mock_coro(True)
|
mock_setup.return_value = True
|
||||||
yield mock_setup
|
yield mock_setup
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
"""Test the Tradfri config flow."""
|
"""Test the Tradfri config flow."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.tradfri import config_flow
|
from homeassistant.components.tradfri import config_flow
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_coro
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -20,9 +19,7 @@ def mock_auth():
|
|||||||
|
|
||||||
async def test_user_connection_successful(hass, mock_auth, mock_entry_setup):
|
async def test_user_connection_successful(hass, mock_auth, mock_entry_setup):
|
||||||
"""Test a successful connection."""
|
"""Test a successful connection."""
|
||||||
mock_auth.side_effect = lambda hass, host, code: mock_coro(
|
mock_auth.side_effect = lambda hass, host, code: {"host": host, "gateway_id": "bla"}
|
||||||
{"host": host, "gateway_id": "bla"}
|
|
||||||
)
|
|
||||||
|
|
||||||
flow = await hass.config_entries.flow.async_init(
|
flow = await hass.config_entries.flow.async_init(
|
||||||
"tradfri", context={"source": "user"}
|
"tradfri", context={"source": "user"}
|
||||||
@ -80,9 +77,7 @@ async def test_user_connection_bad_key(hass, mock_auth, mock_entry_setup):
|
|||||||
|
|
||||||
async def test_discovery_connection(hass, mock_auth, mock_entry_setup):
|
async def test_discovery_connection(hass, mock_auth, mock_entry_setup):
|
||||||
"""Test a connection via discovery."""
|
"""Test a connection via discovery."""
|
||||||
mock_auth.side_effect = lambda hass, host, code: mock_coro(
|
mock_auth.side_effect = lambda hass, host, code: {"host": host, "gateway_id": "bla"}
|
||||||
{"host": host, "gateway_id": "bla"}
|
|
||||||
)
|
|
||||||
|
|
||||||
flow = await hass.config_entries.flow.async_init(
|
flow = await hass.config_entries.flow.async_init(
|
||||||
"tradfri", context={"source": "zeroconf"}, data={"host": "123.123.123.123"}
|
"tradfri", context={"source": "zeroconf"}, data={"host": "123.123.123.123"}
|
||||||
@ -104,9 +99,12 @@ async def test_discovery_connection(hass, mock_auth, mock_entry_setup):
|
|||||||
|
|
||||||
async def test_import_connection(hass, mock_auth, mock_entry_setup):
|
async def test_import_connection(hass, mock_auth, mock_entry_setup):
|
||||||
"""Test a connection via import."""
|
"""Test a connection via import."""
|
||||||
mock_auth.side_effect = lambda hass, host, code: mock_coro(
|
mock_auth.side_effect = lambda hass, host, code: {
|
||||||
{"host": host, "gateway_id": "bla", "identity": "mock-iden", "key": "mock-key"}
|
"host": host,
|
||||||
)
|
"gateway_id": "bla",
|
||||||
|
"identity": "mock-iden",
|
||||||
|
"key": "mock-key",
|
||||||
|
}
|
||||||
|
|
||||||
flow = await hass.config_entries.flow.async_init(
|
flow = await hass.config_entries.flow.async_init(
|
||||||
"tradfri",
|
"tradfri",
|
||||||
@ -132,9 +130,12 @@ async def test_import_connection(hass, mock_auth, mock_entry_setup):
|
|||||||
|
|
||||||
async def test_import_connection_no_groups(hass, mock_auth, mock_entry_setup):
|
async def test_import_connection_no_groups(hass, mock_auth, mock_entry_setup):
|
||||||
"""Test a connection via import and no groups allowed."""
|
"""Test a connection via import and no groups allowed."""
|
||||||
mock_auth.side_effect = lambda hass, host, code: mock_coro(
|
mock_auth.side_effect = lambda hass, host, code: {
|
||||||
{"host": host, "gateway_id": "bla", "identity": "mock-iden", "key": "mock-key"}
|
"host": host,
|
||||||
)
|
"gateway_id": "bla",
|
||||||
|
"identity": "mock-iden",
|
||||||
|
"key": "mock-key",
|
||||||
|
}
|
||||||
|
|
||||||
flow = await hass.config_entries.flow.async_init(
|
flow = await hass.config_entries.flow.async_init(
|
||||||
"tradfri",
|
"tradfri",
|
||||||
@ -160,9 +161,12 @@ async def test_import_connection_no_groups(hass, mock_auth, mock_entry_setup):
|
|||||||
|
|
||||||
async def test_import_connection_legacy(hass, mock_gateway_info, mock_entry_setup):
|
async def test_import_connection_legacy(hass, mock_gateway_info, mock_entry_setup):
|
||||||
"""Test a connection via import."""
|
"""Test a connection via import."""
|
||||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: mock_coro(
|
mock_gateway_info.side_effect = lambda hass, host, identity, key: {
|
||||||
{"host": host, "identity": identity, "key": key, "gateway_id": "mock-gateway"}
|
"host": host,
|
||||||
)
|
"identity": identity,
|
||||||
|
"key": key,
|
||||||
|
"gateway_id": "mock-gateway",
|
||||||
|
}
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
"tradfri",
|
"tradfri",
|
||||||
@ -187,9 +191,12 @@ async def test_import_connection_legacy_no_groups(
|
|||||||
hass, mock_gateway_info, mock_entry_setup
|
hass, mock_gateway_info, mock_entry_setup
|
||||||
):
|
):
|
||||||
"""Test a connection via legacy import and no groups allowed."""
|
"""Test a connection via legacy import and no groups allowed."""
|
||||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: mock_coro(
|
mock_gateway_info.side_effect = lambda hass, host, identity, key: {
|
||||||
{"host": host, "identity": identity, "key": key, "gateway_id": "mock-gateway"}
|
"host": host,
|
||||||
)
|
"identity": identity,
|
||||||
|
"key": key,
|
||||||
|
"gateway_id": "mock-gateway",
|
||||||
|
}
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
"tradfri",
|
"tradfri",
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
"""Tests for Tradfri setup."""
|
"""Tests for Tradfri setup."""
|
||||||
from unittest.mock import patch
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_coro
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_config_yaml_host_not_imported(hass):
|
async def test_config_yaml_host_not_imported(hass):
|
||||||
@ -51,9 +51,12 @@ async def test_config_json_host_not_imported(hass):
|
|||||||
|
|
||||||
async def test_config_json_host_imported(hass, mock_gateway_info, mock_entry_setup):
|
async def test_config_json_host_imported(hass, mock_gateway_info, mock_entry_setup):
|
||||||
"""Test that we import a configured host."""
|
"""Test that we import a configured host."""
|
||||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: mock_coro(
|
mock_gateway_info.side_effect = lambda hass, host, identity, key: {
|
||||||
{"host": host, "identity": identity, "key": key, "gateway_id": "mock-gateway"}
|
"host": host,
|
||||||
)
|
"identity": identity,
|
||||||
|
"key": key,
|
||||||
|
"gateway_id": "mock-gateway",
|
||||||
|
}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.tradfri.load_json",
|
"homeassistant.components.tradfri.load_json",
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
"""Test UPnP/IGD setup process."""
|
"""Test UPnP/IGD setup process."""
|
||||||
|
|
||||||
from ipaddress import IPv4Address
|
from ipaddress import IPv4Address
|
||||||
from unittest.mock import patch
|
|
||||||
|
from asynctest import patch
|
||||||
|
|
||||||
from homeassistant.components import upnp
|
from homeassistant.components import upnp
|
||||||
from homeassistant.components.upnp.device import Device
|
from homeassistant.components.upnp.device import Device
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"""Set up some common test helper things."""
|
"""Set up some common test helper things."""
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
|
from asynctest import patch
|
||||||
import pytest
|
import pytest
|
||||||
import requests_mock as _requests_mock
|
import requests_mock as _requests_mock
|
||||||
|
|
||||||
@ -26,7 +26,6 @@ from tests.common import ( # noqa: E402, isort:skip
|
|||||||
INSTANCES,
|
INSTANCES,
|
||||||
MockUser,
|
MockUser,
|
||||||
async_test_home_assistant,
|
async_test_home_assistant,
|
||||||
mock_coro,
|
|
||||||
mock_storage as mock_storage,
|
mock_storage as mock_storage,
|
||||||
)
|
)
|
||||||
from tests.test_util.aiohttp import mock_aiohttp_client # noqa: E402, isort:skip
|
from tests.test_util.aiohttp import mock_aiohttp_client # noqa: E402, isort:skip
|
||||||
@ -128,7 +127,7 @@ def mock_device_tracker_conf():
|
|||||||
side_effect=mock_update_config,
|
side_effect=mock_update_config,
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.device_tracker.legacy.async_load_config",
|
"homeassistant.components.device_tracker.legacy.async_load_config",
|
||||||
side_effect=lambda *args: mock_coro(devices),
|
side_effect=lambda *args: devices,
|
||||||
):
|
):
|
||||||
yield devices
|
yield devices
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user