Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions tests/components/ambiclimate/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tests for the Ambiclimate config flow."""
from unittest.mock import Mock, patch

import ambiclimate
from asynctest import Mock, patch

from homeassistant import data_entry_flow
from homeassistant.components.ambiclimate import config_flow
Expand Down
24 changes: 10 additions & 14 deletions tests/components/awair/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from datetime import timedelta
import json
import logging
from unittest.mock import patch

from asynctest import patch

from homeassistant.components.awair.sensor import (
ATTR_LAST_API_UPDATE,
Expand All @@ -28,7 +29,7 @@
from homeassistant.setup import async_setup_component
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"}}

Expand Down Expand Up @@ -68,9 +69,9 @@ def alter_time(retval):
async def setup_awair(hass, config=None, data_fixture=AIR_DATA_FIXTURE):
"""Load the Awair platform."""
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)
air_data_mock = mock_coro(data_fixture)
air_data_mock = data_fixture
air_data_patch = patch(
"python_awair.AwairClient.air_data_latest", return_value=air_data_mock
)
Expand Down Expand Up @@ -233,8 +234,7 @@ async def test_availability(hass):

future = NOW + timedelta(minutes=30)
data_patch = patch(
"python_awair.AwairClient.air_data_latest",
return_value=mock_coro(AIR_DATA_FIXTURE),
"python_awair.AwairClient.air_data_latest", return_value=AIR_DATA_FIXTURE,
)

with data_patch, alter_time(future):
Expand All @@ -246,9 +246,7 @@ async def test_availability(hass):
future = NOW + timedelta(hours=1)
fixture = AIR_DATA_FIXTURE_UPDATED
fixture[0][ATTR_TIMESTAMP] = str(future)
data_patch = patch(
"python_awair.AwairClient.air_data_latest", return_value=mock_coro(fixture)
)
data_patch = patch("python_awair.AwairClient.air_data_latest", return_value=fixture)

with data_patch, alter_time(future):
async_fire_time_changed(hass, future)
Expand All @@ -258,9 +256,7 @@ async def test_availability(hass):

future = NOW + timedelta(minutes=90)
fixture = AIR_DATA_FIXTURE_EMPTY
data_patch = patch(
"python_awair.AwairClient.air_data_latest", return_value=mock_coro(fixture)
)
data_patch = patch("python_awair.AwairClient.air_data_latest", return_value=fixture)

with data_patch, alter_time(future):
async_fire_time_changed(hass, future)
Expand All @@ -276,7 +272,7 @@ async def test_async_update(hass):
future = NOW + timedelta(minutes=10)
data_patch = patch(
"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):
Expand All @@ -300,7 +296,7 @@ async def test_throttle_async_update(hass):
future = NOW + timedelta(minutes=1)
data_patch = patch(
"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):
Expand Down
10 changes: 5 additions & 5 deletions tests/components/axis/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Test Axis config flow."""
from unittest.mock import Mock, patch
from asynctest import Mock, patch

from homeassistant.components import axis
from homeassistant.components.axis import config_flow

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):
Expand Down Expand Up @@ -80,7 +80,7 @@ async def test_manual_configuration_update_configuration(hass):

with patch(
"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["flow_id"],
Expand Down Expand Up @@ -113,7 +113,7 @@ async def test_flow_fails_already_configured(hass):

with patch(
"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["flow_id"],
Expand Down Expand Up @@ -232,7 +232,7 @@ async def test_flow_create_entry_multiple_existing_entries_of_same_model(hass):

async def test_zeroconf_flow(hass):
"""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(
config_flow.DOMAIN,
data={
Expand Down
9 changes: 3 additions & 6 deletions tests/components/cast/test_media_player.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""The tests for the Cast Media player platform."""
# pylint: disable=protected-access
from typing import Optional
from unittest.mock import MagicMock, Mock, patch
from uuid import UUID

from asynctest import MagicMock, Mock, patch
import attr
import pytest

Expand All @@ -14,7 +14,7 @@
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.setup import async_setup_component

from tests.common import MockConfigEntry, mock_coro
from tests.common import MockConfigEntry


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -468,7 +468,6 @@ async def test_entry_setup_no_config(hass: HomeAssistantType):

with patch(
"homeassistant.components.cast.media_player._async_setup_platform",
return_value=mock_coro(),
) as mock_setup:
await cast.async_setup_entry(hass, MockConfigEntry(), None)

Expand All @@ -484,7 +483,6 @@ async def test_entry_setup_single_config(hass: HomeAssistantType):

with patch(
"homeassistant.components.cast.media_player._async_setup_platform",
return_value=mock_coro(),
) as mock_setup:
await cast.async_setup_entry(hass, MockConfigEntry(), None)

Expand All @@ -500,7 +498,6 @@ async def test_entry_setup_list_config(hass: HomeAssistantType):

with patch(
"homeassistant.components.cast.media_player._async_setup_platform",
return_value=mock_coro(),
) as mock_setup:
await cast.async_setup_entry(hass, MockConfigEntry(), None)

Expand All @@ -517,7 +514,7 @@ async def test_entry_setup_platform_not_ready(hass: HomeAssistantType):

with patch(
"homeassistant.components.cast.media_player._async_setup_platform",
return_value=mock_coro(exception=Exception),
side_effect=Exception,
) as mock_setup:
with pytest.raises(PlatformNotReady):
await cast.async_setup_entry(hass, MockConfigEntry(), None)
Expand Down
18 changes: 8 additions & 10 deletions tests/components/cloud/test_account_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import asyncio
import logging
from time import time
from unittest.mock import Mock, patch

from asynctest import CoroutineMock, Mock, patch
import pytest

from homeassistant import config_entries, data_entry_flow
from homeassistant.components.cloud import account_link
from homeassistant.helpers import config_entry_oauth2_flow
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"

Expand Down Expand Up @@ -42,12 +42,10 @@ async def test_setup_provide_implementation(hass):

with patch(
"homeassistant.components.cloud.account_link._get_services",
side_effect=lambda _: mock_coro(
[
{"service": "test", "min_version": "0.1.0"},
{"service": "too_new", "min_version": "100.0.0"},
]
),
return_value=[
{"service": "test", "min_version": "0.1.0"},
{"service": "too_new", "min_version": "100.0.0"},
],
):
assert (
await config_entry_oauth2_flow.async_get_implementations(
Expand Down Expand Up @@ -77,7 +75,7 @@ async def test_get_services_cached(hass):

with patch.object(account_link, "CACHE_TIMEOUT", 0), patch(
"hass_nabucasa.account_link.async_fetch_available_services",
side_effect=lambda _: mock_coro(services),
side_effect=lambda _: services,
) as mock_fetch:
assert await account_link._get_services(hass) == 1

Expand Down Expand Up @@ -111,7 +109,7 @@ async def test_implementation(hass, flow_handler):
flow_finished = asyncio.Future()

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),
)

Expand Down
38 changes: 16 additions & 22 deletions tests/components/config/test_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test hassbian config."""
from unittest.mock import patch

from asynctest import patch
import pytest

from homeassistant.bootstrap import async_setup_component
Expand All @@ -9,8 +8,6 @@
from homeassistant.const import CONF_UNIT_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL
from homeassistant.util import dt as dt_util, location

from tests.common import mock_coro

ORIG_TIME_ZONE = dt_util.DEFAULT_TIME_ZONE


Expand All @@ -31,7 +28,7 @@ async def test_validate_config_ok(hass, hass_client):

with patch(
"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")

Expand All @@ -42,7 +39,7 @@ async def test_validate_config_ok(hass, hass_client):

with patch(
"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")

Expand Down Expand Up @@ -121,8 +118,7 @@ async def test_websocket_bad_core_update(hass, client):
async def test_detect_config(hass, client):
"""Test detect config."""
with patch(
"homeassistant.util.location.async_detect_location_info",
return_value=mock_coro(None),
"homeassistant.util.location.async_detect_location_info", return_value=None,
):
await client.send_json({"id": 1, "type": "config/core/detect"})

Expand All @@ -136,20 +132,18 @@ async def test_detect_config_fail(hass, client):
"""Test detect config."""
with patch(
"homeassistant.util.location.async_detect_location_info",
return_value=mock_coro(
location.LocationInfo(
ip=None,
country_code=None,
country_name=None,
region_code=None,
region_name=None,
city=None,
zip_code=None,
latitude=None,
longitude=None,
use_metric=True,
time_zone="Europe/Amsterdam",
)
return_value=location.LocationInfo(
ip=None,
country_code=None,
country_name=None,
region_code=None,
region_name=None,
city=None,
zip_code=None,
latitude=None,
longitude=None,
use_metric=True,
time_zone="Europe/Amsterdam",
),
):
await client.send_json({"id": 1, "type": "config/core/detect"})
Expand Down
9 changes: 3 additions & 6 deletions tests/components/coolmaster/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""Test the Coolmaster config flow."""
from unittest.mock import patch
from asynctest import patch

from homeassistant import config_entries, setup
from homeassistant.components.coolmaster.const import AVAILABLE_MODES, DOMAIN

from tests.common import mock_coro


def _flow_data():
options = {"host": "1.1.1.1"}
Expand All @@ -27,10 +25,9 @@ async def test_form(hass):
"homeassistant.components.coolmaster.config_flow.CoolMasterNet.devices",
return_value=[1],
), patch(
"homeassistant.components.coolmaster.async_setup", return_value=mock_coro(True)
"homeassistant.components.coolmaster.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.coolmaster.async_setup_entry",
return_value=mock_coro(True),
"homeassistant.components.coolmaster.async_setup_entry", return_value=True,
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], _flow_data()
Expand Down
3 changes: 1 addition & 2 deletions tests/components/device_tracker/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import json
import logging
import os
from unittest.mock import Mock, call

from asynctest import patch
from asynctest import Mock, call, patch
import pytest

from homeassistant.components import zone
Expand Down
8 changes: 7 additions & 1 deletion tests/components/freebox/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ def mock_controller_connect():
"""Mock a successful connection."""
with patch("homeassistant.components.freebox.router.Freepybox") as service_mock:
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.connection.get_status = CoroutineMock()
service_mock.return_value.close = CoroutineMock()
Expand Down
Loading