From e303064f75f05291033d6996ad6d6769d48a0825 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 6 Oct 2020 10:15:50 +0200 Subject: [PATCH] Don't use asynctest directly (#41306) --- tests/components/eafm/conftest.py | 3 +- tests/components/eafm/test_config_flow.py | 3 +- tests/components/hyperion/test_light.py | 36 +++++++++---------- .../openweathermap/test_config_flow.py | 2 +- tests/components/wilight/test_config_flow.py | 2 +- tests/components/wilight/test_init.py | 2 +- tests/components/wilight/test_light.py | 2 +- 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/tests/components/eafm/conftest.py b/tests/components/eafm/conftest.py index b25c0f4cdba..7233257f2eb 100644 --- a/tests/components/eafm/conftest.py +++ b/tests/components/eafm/conftest.py @@ -1,8 +1,9 @@ """eafm fixtures.""" -from asynctest import patch import pytest +from tests.async_mock import patch + @pytest.fixture() def mock_get_stations(): diff --git a/tests/components/eafm/test_config_flow.py b/tests/components/eafm/test_config_flow.py index 4656e34a34c..cd71767104f 100644 --- a/tests/components/eafm/test_config_flow.py +++ b/tests/components/eafm/test_config_flow.py @@ -1,10 +1,11 @@ """Tests for eafm config flow.""" -from asynctest import patch import pytest from voluptuous.error import MultipleInvalid from homeassistant.components.eafm import const +from tests.async_mock import patch + async def test_flow_no_discovered_stations(hass, mock_get_stations): """Test config flow discovers no station.""" diff --git a/tests/components/hyperion/test_light.py b/tests/components/hyperion/test_light.py index c400e34db51..8250cc6c9c2 100644 --- a/tests/components/hyperion/test_light.py +++ b/tests/components/hyperion/test_light.py @@ -1,6 +1,4 @@ """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 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.setup import async_setup_component +from tests.async_mock import AsyncMock, Mock, call, patch + TEST_HOST = "test-hyperion-host" TEST_PORT = const.DEFAULT_PORT TEST_NAME = "test_hyperion_name" @@ -23,7 +23,7 @@ TEST_ENTITY_ID = f"{DOMAIN}.{TEST_NAME}" def create_mock_client(): """Create a mock Hyperion client.""" 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.effects = None 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): """Test the platform not being ready.""" 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) 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) # 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( 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] (=) # === brightness = 128 - client.async_send_set_color = CoroutineMock(return_value=True) - client.async_send_set_adjustment = CoroutineMock(return_value=True) + client.async_send_set_color = AsyncMock(return_value=True) + client.async_send_set_adjustment = AsyncMock(return_value=True) await hass.services.async_call( DOMAIN, SERVICE_TURN_ON, @@ -142,7 +142,7 @@ async def test_light_async_turn_on(hass): # On (=), 50% (=), solid (=), [0,255,255] (!) 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( DOMAIN, SERVICE_TURN_ON, @@ -171,8 +171,8 @@ async def test_light_async_turn_on(hass): # On (=), 100% (!), solid, [0,255,255] (=) brightness = 255 - client.async_send_set_color = CoroutineMock(return_value=True) - client.async_send_set_adjustment = CoroutineMock(return_value=True) + client.async_send_set_color = AsyncMock(return_value=True) + client.async_send_set_adjustment = AsyncMock(return_value=True) await hass.services.async_call( DOMAIN, @@ -198,8 +198,8 @@ async def test_light_async_turn_on(hass): # On (=), 100% (=), V4L (!), [0,255,255] (=) effect = const.KEY_COMPONENTID_EXTERNAL_SOURCES[2] # V4L - client.async_send_clear = CoroutineMock(return_value=True) - client.async_send_set_component = CoroutineMock(return_value=True) + client.async_send_clear = AsyncMock(return_value=True) + client.async_send_set_component = AsyncMock(return_value=True) await hass.services.async_call( DOMAIN, SERVICE_TURN_ON, @@ -244,8 +244,8 @@ async def test_light_async_turn_on(hass): # On (=), 100% (=), "Warm Blobs" (!), [0,255,255] (=) effect = "Warm Blobs" - client.async_send_clear = CoroutineMock(return_value=True) - client.async_send_set_effect = CoroutineMock(return_value=True) + client.async_send_clear = AsyncMock(return_value=True) + client.async_send_set_effect = AsyncMock(return_value=True) await hass.services.async_call( DOMAIN, @@ -276,8 +276,8 @@ async def test_light_async_turn_on(hass): # No calls if disconnected. client.has_loaded_state = False call_registered_callback(client, "client-update", {"loaded-state": False}) - client.async_send_clear = CoroutineMock(return_value=True) - client.async_send_set_effect = CoroutineMock(return_value=True) + client.async_send_clear = AsyncMock(return_value=True) + client.async_send_set_effect = AsyncMock(return_value=True) await hass.services.async_call( 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() 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( 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. 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}) await hass.services.async_call( diff --git a/tests/components/openweathermap/test_config_flow.py b/tests/components/openweathermap/test_config_flow.py index f5844df6bfe..4b3297563ed 100644 --- a/tests/components/openweathermap/test_config_flow.py +++ b/tests/components/openweathermap/test_config_flow.py @@ -1,5 +1,4 @@ """Define tests for the OpenWeatherMap config flow.""" -from asynctest import MagicMock, patch from pyowm.exceptions.api_call_error import APICallError from pyowm.exceptions.api_response_error import UnauthorizedError @@ -19,6 +18,7 @@ from homeassistant.const import ( CONF_NAME, ) +from tests.async_mock import MagicMock, patch from tests.common import MockConfigEntry CONFIG = { diff --git a/tests/components/wilight/test_config_flow.py b/tests/components/wilight/test_config_flow.py index 7ca6b3241ff..c8476cbe349 100644 --- a/tests/components/wilight/test_config_flow.py +++ b/tests/components/wilight/test_config_flow.py @@ -1,5 +1,4 @@ """Test the WiLight config flow.""" -from asynctest import patch import pytest from homeassistant.components.wilight.config_flow import ( @@ -16,6 +15,7 @@ from homeassistant.data_entry_flow import ( ) from homeassistant.helpers.typing import HomeAssistantType +from tests.async_mock import patch from tests.common import MockConfigEntry from tests.components.wilight import ( CONF_COMPONENTS, diff --git a/tests/components/wilight/test_init.py b/tests/components/wilight/test_init.py index 01ed57fdcd1..efd779a29df 100644 --- a/tests/components/wilight/test_init.py +++ b/tests/components/wilight/test_init.py @@ -1,5 +1,4 @@ """Tests for the WiLight integration.""" -from asynctest import patch import pytest import pywilight @@ -11,6 +10,7 @@ from homeassistant.config_entries import ( ) from homeassistant.helpers.typing import HomeAssistantType +from tests.async_mock import patch from tests.components.wilight import ( HOST, UPNP_MAC_ADDRESS, diff --git a/tests/components/wilight/test_light.py b/tests/components/wilight/test_light.py index 4d4a32604ad..d02c7233e60 100644 --- a/tests/components/wilight/test_light.py +++ b/tests/components/wilight/test_light.py @@ -1,5 +1,4 @@ """Tests for the WiLight integration.""" -from asynctest import patch import pytest import pywilight @@ -17,6 +16,7 @@ from homeassistant.const import ( ) from homeassistant.helpers.typing import HomeAssistantType +from tests.async_mock import patch from tests.components.wilight import ( HOST, UPNP_MAC_ADDRESS,