mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Don't use asynctest directly (#41306)
This commit is contained in:
parent
949ab621c0
commit
e303064f75
@ -1,8 +1,9 @@
|
|||||||
"""eafm fixtures."""
|
"""eafm fixtures."""
|
||||||
|
|
||||||
from asynctest import patch
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def mock_get_stations():
|
def mock_get_stations():
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
"""Tests for eafm config flow."""
|
"""Tests for eafm config flow."""
|
||||||
from asynctest import patch
|
|
||||||
import pytest
|
import pytest
|
||||||
from voluptuous.error import MultipleInvalid
|
from voluptuous.error import MultipleInvalid
|
||||||
|
|
||||||
from homeassistant.components.eafm import const
|
from homeassistant.components.eafm import const
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_no_discovered_stations(hass, mock_get_stations):
|
async def test_flow_no_discovered_stations(hass, mock_get_stations):
|
||||||
"""Test config flow discovers no station."""
|
"""Test config flow discovers no station."""
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""Tests for the Hyperion integration."""
|
"""Tests for the Hyperion integration."""
|
||||||
# from tests.async_mock import AsyncMock, MagicMock, patch
|
|
||||||
from asynctest import CoroutineMock, Mock, call, patch
|
|
||||||
from hyperion import const
|
from hyperion import const
|
||||||
|
|
||||||
from homeassistant.components.hyperion import light as hyperion_light
|
from homeassistant.components.hyperion import light as hyperion_light
|
||||||
@ -13,6 +11,8 @@ from homeassistant.components.light import (
|
|||||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.async_mock import AsyncMock, Mock, call, patch
|
||||||
|
|
||||||
TEST_HOST = "test-hyperion-host"
|
TEST_HOST = "test-hyperion-host"
|
||||||
TEST_PORT = const.DEFAULT_PORT
|
TEST_PORT = const.DEFAULT_PORT
|
||||||
TEST_NAME = "test_hyperion_name"
|
TEST_NAME = "test_hyperion_name"
|
||||||
@ -23,7 +23,7 @@ TEST_ENTITY_ID = f"{DOMAIN}.{TEST_NAME}"
|
|||||||
def create_mock_client():
|
def create_mock_client():
|
||||||
"""Create a mock Hyperion client."""
|
"""Create a mock Hyperion client."""
|
||||||
mock_client = Mock()
|
mock_client = Mock()
|
||||||
mock_client.async_client_connect = CoroutineMock(return_value=True)
|
mock_client.async_client_connect = AsyncMock(return_value=True)
|
||||||
mock_client.adjustment = None
|
mock_client.adjustment = None
|
||||||
mock_client.effects = None
|
mock_client.effects = None
|
||||||
mock_client.id = "%s:%i" % (TEST_HOST, TEST_PORT)
|
mock_client.id = "%s:%i" % (TEST_HOST, TEST_PORT)
|
||||||
@ -65,7 +65,7 @@ async def test_setup_platform(hass):
|
|||||||
async def test_setup_platform_not_ready(hass):
|
async def test_setup_platform_not_ready(hass):
|
||||||
"""Test the platform not being ready."""
|
"""Test the platform not being ready."""
|
||||||
client = create_mock_client()
|
client = create_mock_client()
|
||||||
client.async_client_connect = CoroutineMock(return_value=False)
|
client.async_client_connect = AsyncMock(return_value=False)
|
||||||
|
|
||||||
await setup_entity(hass, client=client)
|
await setup_entity(hass, client=client)
|
||||||
assert hass.states.get(TEST_ENTITY_ID) is None
|
assert hass.states.get(TEST_ENTITY_ID) is None
|
||||||
@ -97,7 +97,7 @@ async def test_light_async_turn_on(hass):
|
|||||||
await setup_entity(hass, client=client)
|
await setup_entity(hass, client=client)
|
||||||
|
|
||||||
# On (=), 100% (=), solid (=), [255,255,255] (=)
|
# On (=), 100% (=), solid (=), [255,255,255] (=)
|
||||||
client.async_send_set_color = CoroutineMock(return_value=True)
|
client.async_send_set_color = AsyncMock(return_value=True)
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: TEST_ENTITY_ID}, blocking=True
|
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: TEST_ENTITY_ID}, blocking=True
|
||||||
)
|
)
|
||||||
@ -113,8 +113,8 @@ async def test_light_async_turn_on(hass):
|
|||||||
# On (=), 50% (!), solid (=), [255,255,255] (=)
|
# On (=), 50% (!), solid (=), [255,255,255] (=)
|
||||||
# ===
|
# ===
|
||||||
brightness = 128
|
brightness = 128
|
||||||
client.async_send_set_color = CoroutineMock(return_value=True)
|
client.async_send_set_color = AsyncMock(return_value=True)
|
||||||
client.async_send_set_adjustment = CoroutineMock(return_value=True)
|
client.async_send_set_adjustment = AsyncMock(return_value=True)
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
@ -142,7 +142,7 @@ async def test_light_async_turn_on(hass):
|
|||||||
|
|
||||||
# On (=), 50% (=), solid (=), [0,255,255] (!)
|
# On (=), 50% (=), solid (=), [0,255,255] (!)
|
||||||
hs_color = (180.0, 100.0)
|
hs_color = (180.0, 100.0)
|
||||||
client.async_send_set_color = CoroutineMock(return_value=True)
|
client.async_send_set_color = AsyncMock(return_value=True)
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
@ -171,8 +171,8 @@ async def test_light_async_turn_on(hass):
|
|||||||
|
|
||||||
# On (=), 100% (!), solid, [0,255,255] (=)
|
# On (=), 100% (!), solid, [0,255,255] (=)
|
||||||
brightness = 255
|
brightness = 255
|
||||||
client.async_send_set_color = CoroutineMock(return_value=True)
|
client.async_send_set_color = AsyncMock(return_value=True)
|
||||||
client.async_send_set_adjustment = CoroutineMock(return_value=True)
|
client.async_send_set_adjustment = AsyncMock(return_value=True)
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -198,8 +198,8 @@ async def test_light_async_turn_on(hass):
|
|||||||
|
|
||||||
# On (=), 100% (=), V4L (!), [0,255,255] (=)
|
# On (=), 100% (=), V4L (!), [0,255,255] (=)
|
||||||
effect = const.KEY_COMPONENTID_EXTERNAL_SOURCES[2] # V4L
|
effect = const.KEY_COMPONENTID_EXTERNAL_SOURCES[2] # V4L
|
||||||
client.async_send_clear = CoroutineMock(return_value=True)
|
client.async_send_clear = AsyncMock(return_value=True)
|
||||||
client.async_send_set_component = CoroutineMock(return_value=True)
|
client.async_send_set_component = AsyncMock(return_value=True)
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
@ -244,8 +244,8 @@ async def test_light_async_turn_on(hass):
|
|||||||
|
|
||||||
# On (=), 100% (=), "Warm Blobs" (!), [0,255,255] (=)
|
# On (=), 100% (=), "Warm Blobs" (!), [0,255,255] (=)
|
||||||
effect = "Warm Blobs"
|
effect = "Warm Blobs"
|
||||||
client.async_send_clear = CoroutineMock(return_value=True)
|
client.async_send_clear = AsyncMock(return_value=True)
|
||||||
client.async_send_set_effect = CoroutineMock(return_value=True)
|
client.async_send_set_effect = AsyncMock(return_value=True)
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -276,8 +276,8 @@ async def test_light_async_turn_on(hass):
|
|||||||
# No calls if disconnected.
|
# No calls if disconnected.
|
||||||
client.has_loaded_state = False
|
client.has_loaded_state = False
|
||||||
call_registered_callback(client, "client-update", {"loaded-state": False})
|
call_registered_callback(client, "client-update", {"loaded-state": False})
|
||||||
client.async_send_clear = CoroutineMock(return_value=True)
|
client.async_send_clear = AsyncMock(return_value=True)
|
||||||
client.async_send_set_effect = CoroutineMock(return_value=True)
|
client.async_send_set_effect = AsyncMock(return_value=True)
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: TEST_ENTITY_ID}, blocking=True
|
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: TEST_ENTITY_ID}, blocking=True
|
||||||
@ -292,7 +292,7 @@ async def test_light_async_turn_off(hass):
|
|||||||
client = create_mock_client()
|
client = create_mock_client()
|
||||||
await setup_entity(hass, client=client)
|
await setup_entity(hass, client=client)
|
||||||
|
|
||||||
client.async_send_set_component = CoroutineMock(return_value=True)
|
client.async_send_set_component = AsyncMock(return_value=True)
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: TEST_ENTITY_ID}, blocking=True
|
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: TEST_ENTITY_ID}, blocking=True
|
||||||
)
|
)
|
||||||
@ -308,7 +308,7 @@ async def test_light_async_turn_off(hass):
|
|||||||
|
|
||||||
# No calls if no state loaded.
|
# No calls if no state loaded.
|
||||||
client.has_loaded_state = False
|
client.has_loaded_state = False
|
||||||
client.async_send_set_component = CoroutineMock(return_value=True)
|
client.async_send_set_component = AsyncMock(return_value=True)
|
||||||
call_registered_callback(client, "client-update", {"loaded-state": False})
|
call_registered_callback(client, "client-update", {"loaded-state": False})
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Define tests for the OpenWeatherMap config flow."""
|
"""Define tests for the OpenWeatherMap config flow."""
|
||||||
from asynctest import MagicMock, patch
|
|
||||||
from pyowm.exceptions.api_call_error import APICallError
|
from pyowm.exceptions.api_call_error import APICallError
|
||||||
from pyowm.exceptions.api_response_error import UnauthorizedError
|
from pyowm.exceptions.api_response_error import UnauthorizedError
|
||||||
|
|
||||||
@ -19,6 +18,7 @@ from homeassistant.const import (
|
|||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from tests.async_mock import MagicMock, patch
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Test the WiLight config flow."""
|
"""Test the WiLight config flow."""
|
||||||
from asynctest import patch
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.wilight.config_flow import (
|
from homeassistant.components.wilight.config_flow import (
|
||||||
@ -16,6 +15,7 @@ from homeassistant.data_entry_flow import (
|
|||||||
)
|
)
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
from tests.components.wilight import (
|
from tests.components.wilight import (
|
||||||
CONF_COMPONENTS,
|
CONF_COMPONENTS,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Tests for the WiLight integration."""
|
"""Tests for the WiLight integration."""
|
||||||
from asynctest import patch
|
|
||||||
import pytest
|
import pytest
|
||||||
import pywilight
|
import pywilight
|
||||||
|
|
||||||
@ -11,6 +10,7 @@ from homeassistant.config_entries import (
|
|||||||
)
|
)
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
from tests.components.wilight import (
|
from tests.components.wilight import (
|
||||||
HOST,
|
HOST,
|
||||||
UPNP_MAC_ADDRESS,
|
UPNP_MAC_ADDRESS,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Tests for the WiLight integration."""
|
"""Tests for the WiLight integration."""
|
||||||
from asynctest import patch
|
|
||||||
import pytest
|
import pytest
|
||||||
import pywilight
|
import pywilight
|
||||||
|
|
||||||
@ -17,6 +16,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
from tests.components.wilight import (
|
from tests.components.wilight import (
|
||||||
HOST,
|
HOST,
|
||||||
UPNP_MAC_ADDRESS,
|
UPNP_MAC_ADDRESS,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user